Do the access levels and modifiers (private, sealed, etc) serve a security purpose in C#?

后端 未结 5 904
一生所求
一生所求 2021-01-11 17:08

I\'ve seen that you can manipulate private and internal members using reflection. I\'ve also seen it said that a \'sealed\' class is more secure that one that isn\'t.

5条回答
  •  不思量自难忘°
    2021-01-11 17:28

    Regarding the comments about reflection and security - consider that there are many internal types + members in mscorlib.dll that call into native Windows functions and can potentially lead to badness if a malicious application uses reflection to call into them. This isn't necessarily a problem since untrusted applications normally aren't granted these permissions by the runtime. This (and a few declarative security checks) is how the mscorlib.dll binary can expose its types to all manner of trusted and untrusted code, yet the untrusted code can't get around the public API.

    This is really just scratching the surface of the reflection + security issue, but hopefully it's enough information to lead you down the right path.

提交回复
热议问题