Security impact of access modifiers (public, private, internal, protected)

廉价感情. 提交于 2019-12-05 05:26:37

No, access modifiers don't offer security protection. They are merely there for developer convenience, e.g. they help to enforce good coding practices and help with programming patterns.

It's easy to access otherwise inaccessible modifiers by using reflection in Java/C# and other languages.

The main purpose of the access modifiers is to enforce a specific design, not any kind of security.

As always with security it is necessary to understand what you are attempting to protect against. Have some idea of your threat model.

So, yes access modifiers are absolutely critical to the Java 2 Security Model, for dealing with mobile code. If, for instance, untrusted could clear the java.lang.System.security field, then that's the end of that (Update: I believe that specific example no longer works, but the principle remains). Access modifiers prevent illicit access through direct reference and also, with a runtime security check, even when accessed through reflection.

In other cases, it is just about code quality. Software security vulnerabilities are almost down to poor quality code, despite all the "we take security seriously" excuses. So access modifiers play a role everywhere.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!