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.

626 Part V: Assessing Your <strong>Security</strong>Search your code for the “.LinkDem<strong>and</strong>” string to identify where link dem<strong>and</strong>s areused. They can only be used declaratively. An example is shown in the followingcode fragment:[StrongNameIdentityPermission(<strong>Security</strong>Action.LinkDem<strong>and</strong>,PublicKey="00240000048...97e85d098615")]public static void SomeOperation() {}For more information about the issues raised in this section, see “Link Dem<strong>and</strong>s” inChapter 8, “Code Access <strong>Security</strong> in Practice.” The following questions help you toreview the use of link dem<strong>and</strong>s in your code:● Why are you using a link dem<strong>and</strong>?A defensive approach is to avoid link dem<strong>and</strong>s as far as possible. Do not use themjust to improve performance <strong>and</strong> to eliminate full stack walks. Compared to thecosts of other <strong>Web</strong> application performance issues such as network latency <strong>and</strong>database access, the cost of the stack walk is small. Link dem<strong>and</strong>s are only safeif you know <strong>and</strong> can limit which code can call your code.● Do you trust your callers?When you use a link dem<strong>and</strong>, you rely on the caller to prevent a luring attack.Link dem<strong>and</strong>s are safe only if you know <strong>and</strong> can limit the exact set of direct callersinto your code, <strong>and</strong> you can trust those callers to authorize their callers.● Do you call code that is protected with link dem<strong>and</strong>s?If so, does your code provide authorization by dem<strong>and</strong>ing a security permissionfrom the callers of your code? Can the arguments passed to your methods passthrough to the code that you call? If so, can they maliciously influence the codeyou call?● Have you used link dem<strong>and</strong>s at the method <strong>and</strong> class level?When you add link dem<strong>and</strong>s to a method, it overrides the link dem<strong>and</strong> on theclass. Check that the method also includes class-level link dem<strong>and</strong>s.● Do you use link dem<strong>and</strong>s on classes that are not sealed?Link dem<strong>and</strong>s are not inherited by derived types <strong>and</strong> are not used when anoverridden method is called on the derived type. If you override a method thatneeds to be protected with a link dem<strong>and</strong>, apply the link dem<strong>and</strong> to theoverridden method.● Do you use a link dem<strong>and</strong> to protect a structure?Link dem<strong>and</strong>s do not prevent the construction of a structure by an untrustedcaller. This is because default constructors are not automatically generated forstructures, <strong>and</strong> therefore the structure level link dem<strong>and</strong> only applies if you usean explicit constructor.

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

Saved successfully!

Ooh no, something went wrong!