locked
security transparency code question RRS feed

  • Question

  • Hello!

    I try to understand new concept in .NET Framework 4 - security transparency. I know that all code now falls in one of three categories(or layers, if you want):

    • Transparent code
    • Security Critical code
    • Safe Critical code

    Also I know that we now mark our code with one of the three attributes:

    This is way to put code in one of three categories I told before. Now - I can't find answer to one simple question: if we don't apply any attributes to code - which category such code will go? In other words - in .NET Framework 4 to which category all code belong by default?

    TNX!

    Friday, May 7, 2010 10:36 AM

Answers

  • Hi,

    Code access security primarily affects library code and partially trusted applications. Library developers must protect their code from unauthorized access from partially trusted applications. Partially trusted applications are applications that are loaded from external sources such as the Internet. Applications that are installed on your desktop or on the local intranet run in full trust. Full-trust applications are not affected by code access security unless they are marked as security-transparent, because they are fully trusted. The only limitation for full-trust applications is that applications that are marked with the SecurityTransparentAttribute attribute cannot call code that is marked with the SecurityCriticalAttribute attribute. Partially trusted applications must be run in a sandbox (for example, in Internet Explorer) so that code access security can be applied. If you download an application from the Internet and try to run it from your desktop, you will get a NotSupportedException with the message: "An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous." If you are sure that the application can be trusted, you can enable it to be run as full trust by using the <loadFromRemoteSources> element. For information about running an application in a sandbox, see How to: Run Partially Trusted Code in a Sandbox.

    This should answer your question.

    Reference link:

    http://msdn.microsoft.com/en-us/library/c5tk9z76(v=VS.100).aspx

    Thanks

    Binze


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Thursday, May 13, 2010 5:22 AM
    Wednesday, May 12, 2010 6:53 AM

All replies

  • Hmm... No one how know new Security System in .NET??
    Saturday, May 8, 2010 7:31 AM
  • Hi,

    Code access security primarily affects library code and partially trusted applications. Library developers must protect their code from unauthorized access from partially trusted applications. Partially trusted applications are applications that are loaded from external sources such as the Internet. Applications that are installed on your desktop or on the local intranet run in full trust. Full-trust applications are not affected by code access security unless they are marked as security-transparent, because they are fully trusted. The only limitation for full-trust applications is that applications that are marked with the SecurityTransparentAttribute attribute cannot call code that is marked with the SecurityCriticalAttribute attribute. Partially trusted applications must be run in a sandbox (for example, in Internet Explorer) so that code access security can be applied. If you download an application from the Internet and try to run it from your desktop, you will get a NotSupportedException with the message: "An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous." If you are sure that the application can be trusted, you can enable it to be run as full trust by using the <loadFromRemoteSources> element. For information about running an application in a sandbox, see How to: Run Partially Trusted Code in a Sandbox.

    This should answer your question.

    Reference link:

    http://msdn.microsoft.com/en-us/library/c5tk9z76(v=VS.100).aspx

    Thanks

    Binze


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Thursday, May 13, 2010 5:22 AM
    Wednesday, May 12, 2010 6:53 AM
  • First of all - thanks for so detailed answer!
    The only limitation for full-trust applications is that applications that are marked with the SecurityTransparentAttribute attribute cannot call code that is marked with the SecurityCriticalAttribute attribute.

    No, it's NOT ONLY limitation for full-trust code on condition that this code marked with SecurityTransparentAttribute. With this attribute code (even full-trusted) can't execute "dangerous" operations like, for example:

    FileIOPermission fp=new FileIOPermission(FileIOPermissionAccess.Read, "C:\\test_r"); fp.Assert();

    This should answer your question.

    To be frankly - no. Look - what we know to definitely? We know the following facts:

    1. ALL(with no exception!) code in FW4.0 get in one of three layers of code: Transparent/Security/Safe.

    2. Code marked with appropriate attribute will be sent to appropriate layer. All right?

    Now - if code NOT marked with any of three attributes it, obvious, also will be sent to one of three layers - right? The only question - to WHICH one exactly?

    Friday, May 14, 2010 4:13 PM