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 201Only use link dem<strong>and</strong>s in an assembly when you trust the assembly’s callers not toexpose its functionality further (for example, when the caller is an application, not alibrary) or when you know it is safe just to verify the immediate caller’s identity withan identity permission dem<strong>and</strong>.Performance <strong>and</strong> Link Dem<strong>and</strong>sCompared to other <strong>Web</strong> application performance issues such as network latency <strong>and</strong>database access, the cost of a stack walk is small. Do not use link dem<strong>and</strong>s purely forperformance reasons. Full dem<strong>and</strong>s provide a much greater degree of security.Calling Methods with Link Dem<strong>and</strong>sIf you call a link dem<strong>and</strong> protected method, only your code will be checked by thelink dem<strong>and</strong>. In this situation, you should make sure your code takes adequatemeasures to authorize its callers, for example, by dem<strong>and</strong>ing a permission.Mixing Class <strong>and</strong> Method Level Link Dem<strong>and</strong>sMethod level link dem<strong>and</strong>s override class level link dem<strong>and</strong>s. For example, in thefollowing code fragment, the link dem<strong>and</strong> for FileIOPermission must be repeated onthe method declaration or the EnvironmentPermission link dem<strong>and</strong> replaces theclass level FileIOPermission dem<strong>and</strong>.[FileIOPermission(<strong>Security</strong>Action.LinkDem<strong>and</strong>, Unrestricted=true)]public sealed class SomeClass{// The unrestricted FileIOPermission link dem<strong>and</strong> must be restated at the// method level, if the method is decorated with another link dem<strong>and</strong>.// Failure to do so means that (in this example) that the// EnvironmentPermission link dem<strong>and</strong> would override the class level// FileIOPermission link dem<strong>and</strong>[FileIOPermission(<strong>Security</strong>Action.LinkDem<strong>and</strong>, Unrestricted=true)][EnvironmentPermission(<strong>Security</strong>Action.LinkDem<strong>and</strong>, Read="PATH")]public void SomeMethod(){}}

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

Saved successfully!

Ooh no, something went wrong!