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 21: Code Review 625●Do you reduce the assert duration?Check that you only assert a permission for the minimum required length of time.For example, if you need to use an Assert call just while you call another method,check that you make a call to RevertAssert immediately after the method call.Do You Use Permission Dem<strong>and</strong>s When You Should?Your code is always subject to permission dem<strong>and</strong> checks from the .NET Frameworkclass library, but if your code uses explicit permission dem<strong>and</strong>s, check that this isdone appropriately. Search your code for the “.Dem<strong>and</strong>” string to identity declarative<strong>and</strong> imperative permission dem<strong>and</strong>s, <strong>and</strong> then review the following questions:●●●●Do you cache data?If so, check whether or not the code issues an appropriate permission dem<strong>and</strong>prior to accessing the cached data. For example, if the data is obtained from a file,<strong>and</strong> you want to ensure that the calling code is authorized to access the file fromwhere you populated the cache, dem<strong>and</strong> a FileIOPermission prior to accessingthe cached data.Do you expose custom resources or privileged operations?If your code exposes a custom resource or privileged operation throughunmanaged code, check that it issues an appropriate permission dem<strong>and</strong>, whichmight be a built-in permission type or a custom permission type depending onthe nature of the resource.Do you dem<strong>and</strong> soon enough?Check that you issue a permission dem<strong>and</strong> prior to accessing the resource orperforming the privileged operation. Do not access the resource <strong>and</strong> thenauthorize the caller.Do you issue redundant dem<strong>and</strong>s?Code that uses the .NET Framework class libraries is subject to permissiondem<strong>and</strong>s. Your code does not need to issue the same dem<strong>and</strong>. This results ina duplicated <strong>and</strong> wasteful stack walk.Do You Use Link Dem<strong>and</strong>s?Link dem<strong>and</strong>s, unlike regular dem<strong>and</strong>s, only check the immediate caller. They do notperform a full stack walk, <strong>and</strong> as a result, code that uses link dem<strong>and</strong>s is subject toluring attacks. For information on Luring Attacks, see “Link Dem<strong>and</strong>s” in Chapter 8,“Code Access <strong>Security</strong> in Practice.”

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

Saved successfully!

Ooh no, something went wrong!