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.

154 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sFor base classes, you can restrict which other code is allowed to derive from yourclass by using code access security inheritance dem<strong>and</strong>s. For more information, see“Authorizing Code” in Chapter 8, “Code Access <strong>Security</strong> in Practice.”Restrict Which Users Can Call Your CodeAnnotate classes <strong>and</strong> methods with declarative principal permission dem<strong>and</strong>s tocontrol which users can call your classes <strong>and</strong> class members. In the followingexample, only members of the specified Windows group can access the Orders class.A class level attribute like this applies to all class members. Declarative principalpermission dem<strong>and</strong>s can also be used on individual methods. Method level attributesoverride class level attributes.[PrincipalPermission(<strong>Security</strong>Action.Dem<strong>and</strong>,Role=@"DomainName\WindowsGroup")]public sealed class Orders(){}Expose Fields Using PropertiesMake all fields private. To make a field value accessible to external types, use a readonly or a read/write property. Properties allow you to add additional constraints,such as input validation or permission dem<strong>and</strong>s, as shown in the following codesample.public sealed class MyClass{private string field; // field is private// Only members of the specified group are able to// access this public property[PrincipalPermission(<strong>Security</strong>Action.Dem<strong>and</strong>,Role=@"DomainName\WindowsGroup")]public string Field{get {return field;}}}

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

Saved successfully!

Ooh no, something went wrong!