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.

202 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sInterfaces <strong>and</strong> Link Dem<strong>and</strong>sIf your class implements an interface <strong>and</strong> one of the method implementations has alink dem<strong>and</strong>, make sure that the method declaration on the interface definition hasthe same link dem<strong>and</strong>. Otherwise, the caller simply has to call your method throughthe interface to bypass the link dem<strong>and</strong>. An example is shown below.public interface IMyInterface{// The link dem<strong>and</strong> shown on the method implementation below// should be repeated herevoid Method1();}public class MyImplementation : IMyInterface{// The method implementation has a link dem<strong>and</strong> but the interface does not[<strong>Security</strong>Permission(<strong>Security</strong>Action.LinkDem<strong>and</strong>,Flags=<strong>Security</strong>PermissionFlag.ControlPrincipal)]public void Method1(){}}With the following code, the caller is subject to the link dem<strong>and</strong>:MyImplementation t = new MyImplementation();t.Method1();With the following code, the caller is not subject to the link dem<strong>and</strong>:IMyInterface i = new MyImplementation();i.Method1();Structures <strong>and</strong> Link Dem<strong>and</strong>sLink dem<strong>and</strong>s do not prevent the construction of structures by untrusted callers.This is because default constructors are not automatically generated for structures.Therefore, the structure level link dem<strong>and</strong> only applies if you use an explicitconstructor.

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

Saved successfully!

Ooh no, something went wrong!