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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8: Code Access <strong>Security</strong> in Practice 195RequestMinimumYou can use <strong>Security</strong>Action.RequestMinimum method along with declarativepermission attributes to specify the minimum set of permissions your assemblyneeds to run. For example, if your assembly needs to access the registry, but onlyneeds to retrieve configuration data from a specific key, use an attribute similar to thefollowing:[assembly: RegistryPermissionAttribute(<strong>Security</strong>Action.RequestMinimum,Read=@"HKEY_LOCAL_MACHINE\SOFTWARE\YourApp")]If you know up front that your code will run in a full trust environment <strong>and</strong> will begranted the full set of unrestricted permissions, using RequestMinimum is lessimportant. However, it is good practice to specify your assembly’s permissionrequirements.Note Permission attributes accept a comma-delimited list of properties <strong>and</strong> property values afterthe m<strong>and</strong>atory constructor arguments. These are used to initialize the underlying permission object.A quick way to find out what property names are supported is to use Ildasm.exe on the assemblythat contains the permission attribute type.RequestOptionalIf you use <strong>Security</strong>Action.RequestOptional method, no other permissions exceptthose specified with <strong>Security</strong>Action.RequestMinimum <strong>and</strong><strong>Security</strong>Action.RequestOptional will be granted to your assembly, even if yourassembly would otherwise have been granted additional permissions by code accesssecurity policy.RequestRefused<strong>Security</strong>Action.RequestRefuse allows you to make sure that your assembly cannotbe granted permissions by code access security policy that it does not require. Forexample, if your assembly does not call unmanaged code, you could use thefollowing attribute to ensure code access security policy does not grant yourassembly the unmanaged code permission.[assembly: <strong>Security</strong>PermissionAttribute(<strong>Security</strong>Action.RequestRefuse,UnmanagedCode=true)]

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

Saved successfully!

Ooh no, something went wrong!