动态代码生成和安全性
我遇到了 JSON.Net
序列化库的问题,我希望得到在 CAS 和 AppDomain 管理方面比我更专家的人的意见。
要了解有关该问题的更多信息,您可以参阅问题 21575。我针对此问题提交了补丁。
这个想法是,当您第一次访问当前应用程序域时,DynamicCodeGeneration
标志会在当前应用程序域中一次性静态设置。但是,我认为应用程序域允许的权限可以更改。
例如,如果您跨另一个应用程序域调用一个应用程序域中的对象的方法,则似乎您继承了限制最严格的应用程序域的权限。因此,对我来说,应用程序域的权限不会更改并且您可以一劳永逸地静态设置 DynamicCodeGeneration
的假设是错误的。
我说得对吗?或者我是否错过了有关 CAS 和 AppDomain 管理的内容?
编辑:
我添加了一些关于我认为正在发生的事情的模式:http://www.sp4ce.net/data/temp/appdomain.png 您认为这是正确的吗?
I encounter a problem with the JSON.Net
serialization library and I wanted opinion of people more expert than me in CAS and AppDomain management.
To have more information on the problem, you can refer to the issue 21575. I submitted a patch for this issue.
The idea is that DynamicCodeGeneration
flag is statically set once and for all in the current application domain when you first access it. However, I think that permission allowed for an application domain can change.
For example, if you call a method of an object in an application domain, across another application domain, it seems that you inherit of the permissions of the most restrictive application domain. So for me this assumption that permissions won't change for an application domain and that you can statically set DynamicCodeGeneration
once and for all is wrong.
Am I correct ? Or do I miss something about CAS and AppDomain management ?
EDIT:
I added a little schema about what I think it is happening: http://www.sp4ce.net/data/temp/appdomain.png Do you think it is correct ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的单元测试为你的理论提供了证据。在跨应用程序域调用中,看起来会强制执行更严格的 CAS 限制。不过,我认为未来对限制性较小的应用程序域的本地调用(不远程处理限制性应用程序域)将不会继续强制执行限制性更强的权限集。
您尝试解决的 JSON.Net 问题是,权限集仅检查一次,并且在未来可能来自限制性更强的应用程序域的调用中不会重新验证。鉴于权限可以根据调用上下文而变化,因此在与权限的使用最本地的范围内请求权限是有意义的。您的解决方案是让调用代码负责通知 JSON.Net 是否使用 DynamicCodeGeneration。我认为 JSON.Net 库中更好的解决方案是在每次调用 JsonTypeReflector.DynamicCodeGeneration getter 时要求其所需的权限,而不是像现在一样缓存值。
I think your unit tests are providing evidence for your theory. In cross-appdomain calls, it looks like the more restrictive CAS restrictions are enforced. I don't think, though, that future calls local to the less restrictive appdomain (no remoting to restrictive appdomain) will continue to enforce the more restrictive permission set.
The issue with JSON.Net that you are attempting to address is that the permission set is checked once and not re-verified in future calls that may be coming from a more restrictive appdomain. Given that permissions can change depending on the calling context, it makes sense to demand permissions in the scope most local to the use of the permission. Your solution is to make the calling code responsible for informing JSON.Net of whether DynamicCodeGeneration is used. I think a better solution in the JSON.Net library would be to demand the requierd permissions in the JsonTypeReflector.DynamicCodeGeneration getter every time it is called, rather than caching the value as it does now.