.NET Code Access Security: Useful or just overcomplicated?

扶醉桌前 提交于 2019-11-30 17:42:52

The .NET team them self have comed to the same conclusion the assembly access security is being reworked for .NET#4. Take a look at this blog for more info: .NET Security blog

Here, here! I've shared many of the same frustrations. And of course, the over-complication and horrid documentation basically encourage developers to bypass it or use overly broad rules. Security will always be a tough nut for anyone but CAS is really difficult to do right.

I've had to deal with CAS but it wasn't too difficult since I only had to deploy it on a dozen workstations or so. You can also push out the required settings via Group Policy.

But to answer your question, no, I don't think it ever helped.

Look on the bright side though, starting with .NET 3.5 you can run apps across a network share without CAS.

After much searching I stumbled upon this blog entry from the CLR team which not only confirms that CAS is going away in .NET 4, but also gives a great guide on what will break and how to migrate toward the new sandbox model: New Security Model: Moving to a Better Sandbox. From the article:

In versions of .Net Framework before v4, we had many ways to restrict the permissions of an assembly or even certain code path within the assembly:

  1. Stack-walk modifiers: Deny, PermitOnly

  2. Assembly-level requests: RequestOptional, RequestRefuse, RequestMinimum

  3. Policy changes: caspol, and AppDomain.SetPolicyLevel

  4. Loading an assembly with a Zone other than MyComputer

In the past, these APIs have been a source of confusion for host and application writers. In .Net Framework 4, these methods of restricting permissions are marked obsolete and we hope to remove them at a point in the future.

Most distressing is the fact that all these deprecated methods of creating a sandbox will start throwing a NotSupportedException. This is exceptionally precarious for any poor souls (like myself) that for whatever reason are required to implement CAS in their organization at this time. You have been warned.

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