字节码操作有哪些危险(如果有)?

发布于 2024-10-02 12:34:11 字数 110 浏览 3 评论 0原文

字节码增强似乎是一项非常有趣的 Java 技术,但它给人一种有点“黑魔法”的感觉。使用它是否有任何缺点(除了将功能添加到从源代码中不明显的类中这一事实之外)?

它会导致安全、序列化等问题吗?

Bytecode enhancement seems like a very interesting Java technique, but it has the feel of a bit of "black magic" about it. Are there any disadvantages to using it (other than the fact that functionality is added to classes that is not apparent from the source code)?

Does it cause problems with security, serialization, etc.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

給妳壹絲溫柔 2024-10-09 12:34:11

使用它有什么缺点吗(除了将功能添加到从源代码中不明显的类中这一事实之外)?

一件事是由字节码操作产生的错误可能更难以诊断。源代码的检查和源代码级调试将更加困难。

这是否会导致安全问题,

验证者(理论上)应该防止修改后的字节码破坏核心类型系统并破坏 JVM。 (不言而喻,不应该允许不受信任的代码进行字节码修改,因此我们可以忽略这种情况。)但是,在过去,一些 Java 字节码验证器并不彻底。

此外,字节码修改:

  • 使得基于源代码的安全分析变得更加困难,并且
  • 可能会抵消使用 FindBugs 等静态分析工具的(有限的)安全优势。

序列化等?

字节码修改可能会导致现有的序列化对象无法被修改后的类读取;例如,通过添加和删除字段,或者通过更改类的超类和接口。但是,您可以通过更改源代码来完成相同的操作。

Are there any disadvantages to using it (other than the fact that functionality is added to classes that is not apparent from the source code)?

One thing is that bugs created by bytecode manipulation are likely to be more difficult to diagnose. Examination of the source code, and source level debugging will be harder.

Does it cause problems with security,

The verifier should (in theory) prevent the modified bytecode from breaking the core type system and corrupting the JVM. (And it goes without saying that untrusted code shouldn't be allowed to do bytecode modification, so we can discount that scenario.) However, in the past, some Java byte code verifiers have been less than thorough.

Furthermore, bytecode modification :

  • makes it harder to do a proper source code based security analysis, and
  • could nullify the (limited) security benefits of using a static analysis tool such as FindBugs.

serialization, etc.?

Bytecode modification can do things that will make existing serialized objects unreadable by the modified class; e.g. by adding and removing fields, or by changing a classes superclass and interfaces. However, you can do the same thing by changing the sourcecode.

↘紸啶 2024-10-09 12:34:11

JVM 验证字节码,但是异常字节码 可能代表安全威胁。

The JVM verifies bytecodes, but deviant bytecode may represent a security threat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文