11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8: Code Access <strong>Security</strong> in Practice 211Requesting DirectoryServicesPermissionTo document the permission requirements of your code, <strong>and</strong> to ensure your assemblycannot load if it is granted insufficient directory services access from code accesssecurity policy, add an assembly level DirectoryServicesPermissionAttribute with<strong>Security</strong>Action.RequestMinimum as shown in the following example.[assembly: DirectoryServicesPermissionAttribute(<strong>Security</strong>Action.RequestMinimum,Path="LDAP://rootDSE",PermissionAccess=DirectoryServicesPermissionAccess.Browse)]Environment VariablesCode that needs to read or write environment variables using theSystem.Environment class must be granted the EnvironmentPermission by codeaccess security policy. This permission type can be used to constrain access to specificnamed environment variables.Constraining Environment Variable AccessTo constrain code so that it can only read specific environment variables, you can usethe EnvironmentPermissionAttribute together with <strong>Security</strong>Action.PermitOnly.The following attributes ensure that the code can only read from the username,userdomain, <strong>and</strong> temp variables.[EnvironmentPermissionAttribute(<strong>Security</strong>Action.PermitOnly, Read="username")][EnvironmentPermissionAttribute(<strong>Security</strong>Action.PermitOnly, Read="userdomain")][EnvironmentPermissionAttribute(<strong>Security</strong>Action.PermitOnly, Read="temp")]public static string GetVariable(string name){return Environment.GetEnvironmentVariable(name);}Requesting EnvironmentPermissionTo document the permission requirements of your code, <strong>and</strong> to ensure your assemblycannot load if it is granted insufficient environment variable access from code accesssecurity policy, add an assembly level EnvironmentPermissionAttribute with<strong>Security</strong>Action.RequestMinimum as shown in the following code.[assembly: EnvironmentPermissionAttribute(<strong>Security</strong>Action.RequestMinimum,Read="username"),EnvironmentPermissionAttribute(<strong>Security</strong>Action.RequestMinimum,Read="userdomain"),EnvironmentPermissionAttribute(<strong>Security</strong>Action.RequestMinimum,Read="temp")]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!