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 205Using Policy Permission GrantsYou can configure code access security policy to grant a restricted permission set to aspecific assembly. This constrains its ability to access resources or perform otherprivileged operations. For more information, see “How To: Configure Code Access<strong>Security</strong> Policy to Constrain an Assembly” in the “How To” section of this guide.Using Stack Walk ModifiersYou can use stack walk modifiers to ensure that only specific permissions areavailable to the code that you call. For example, you can use<strong>Security</strong>Action.PermitOnly to ensure that your method <strong>and</strong> any methods that arecalled only have a restricted permission set. The following example applies a veryrestrictive permission set. The code only has the permission to execute. It cannotaccess resources or perform other privileged operations.[<strong>Security</strong>PermissionAttribute(<strong>Security</strong>Action.PermitOnly,Flags=<strong>Security</strong>PermissionFlag.Execution)]public void SomeMethod(){// The current method <strong>and</strong> downstream can only execute. They cannot access// resources or perform other privileged operations.SomeOtherMethod();}File I/OThe following sections show you how to use code access security to constrain varioustypes of resource access including file I/O, event log, registry, data access, directoryservices, environment variables, <strong>Web</strong> services, <strong>and</strong> sockets.To be able to perform file I/O, your assembly must be granted the FileIOPermissionby code access security policy. If your code is granted the unrestrictedFileIOPermission, it can access files anywhere on the file system, subject to Windowssecurity. A restricted FileIOPermission can be used to constrain an assembly’s abilityto perform file I/O, for example, by specifying allowed access rights (read,read/write, <strong>and</strong> so on.)Constraining File I/O within your <strong>Application</strong>’s ContextA common requirement is to be able to restrict file I/O to specific directory locationssuch as your application’s directory hierarchy.Note If your <strong>Web</strong> application is configured for Medium trust, file access is automatically restrictedto the application’s virtual directory hierarchy. For more information, see Chapter 9, “Using CodeAccess <strong>Security</strong> with ASP.NET.”

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

Saved successfully!

Ooh no, something went wrong!