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.

204 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sUse the Dem<strong>and</strong> / Assert PatternDem<strong>and</strong>ing a specific permission before calling Assert is an effective way toauthorize upstream code. Sometimes you might be able to dem<strong>and</strong> a built-inpermission type to authorize calling code.Often, if your assembly is exposing functionality that is not provided by the .NETFramework class library, such as calling the Data Protection API (DPAPI), you need todevelop a custom permission <strong>and</strong> dem<strong>and</strong> the custom permission to authorizecallers. For example, you might develop a custom Encryption permission toauthorize callers to a managed DPAPI wrapper assembly. Dem<strong>and</strong>ing this permission<strong>and</strong> then asserting the unmanaged code permission is an effective way to authorizecalling code.For more information about this approach <strong>and</strong> about developing custom permissions,see “How To: Create a Custom Encryption Permission” in the “How To” section ofthis guide.Reduce the Assert DurationIf you only need to call Assert to satisfy the dem<strong>and</strong>s of a single downstream methodthat your code calls, then place the Assert immediately prior to the downstreammethod call. Then immediately call RevertAssert to keep the assertion window assmall as possible, <strong>and</strong> to ensure that any subsequent code your method calls does notinadvertently succeed because the Assert is still in effect.A common practice is to place the call to RevertAssert in a finally block to ensurethat it always gets called even in the event of an exception.Constraining CodeConstraining code <strong>and</strong> building least privileged code is analogous to using theprinciple of least privilege when you configure user or service accounts. Byrestricting the code access security permissions available to your code, you minimizescope for the malicious use of your code.There are two ways to constrain code to restrict which resources it can access <strong>and</strong>restrict which other privileged operations it can perform:● Using policy permission grants● Using stack walk modifiers

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

Saved successfully!

Ooh no, something went wrong!