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.

208 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sConstraining Event Logging CodeIf you want to constrain the actions of event log wrapper code — perhaps codewritten by another developer or development organization — you can use declarativeattributes together with <strong>Security</strong>Action.PermitOnly as shown in the followingexample.The following attribute ensures that the WriteToLog method <strong>and</strong> any methods it callscan only access the local computer’s event log <strong>and</strong> cannot delete event logs or eventsources. These operations are not permitted byEventLogPermissionAccess.Instrument.[EventLogPermission(<strong>Security</strong>Action.PermitOnly,MachineName=".",PermissionAccess=EventLogPermissionAccess.Instrument)]public static void WriteToLog( string message )To enforce read-only access to existing logs, use EventLogPermissionAccess.Browse.Requesting EventLogPermissionTo document the permission requirements of your code, <strong>and</strong> to ensure that yourassembly cannot load if it is granted insufficient event log access by code accesssecurity policy, add an assembly level EventLogPermissionAttribute with<strong>Security</strong>Action.RequestMinimum as shown in the following example.// This attribute indicates that your code requires the ability to access the// event logs on the local machine only (".") <strong>and</strong> needs instrumentation access// which means it can read or write to existing logs <strong>and</strong> create new event sources// <strong>and</strong> event logs[assembly: EventLogPermissionAttribute(<strong>Security</strong>Action.RequestMinimum,MachineName=".",PermissionAccess=EventLogPermissionAccess.Instrument)]RegistryCode that accesses the registry by using the Microsoft.Win32.Registry class must begranted the RegistryPermission by code access security policy. This permission typecan be used to constrain registry access to specific keys <strong>and</strong> sub keys, <strong>and</strong> can alsocontrol code’s ability to read, write, or create registry keys <strong>and</strong> named values.

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

Saved successfully!

Ooh no, something went wrong!