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 9: Using Code Access <strong>Security</strong> with ASP.NET 245 To build a s<strong>and</strong>boxed wrapper assembly to write to the event log1. Create an assembly for your event log code. Configure the assembly version,strong name the assembly, <strong>and</strong> mark it with theAllowPartiallyTrustedCallersAttribute, as shown in the following example.[[assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyKeyFile(@"..\..\eventlogwrapper.snk")][assembly:AllowPartiallyTrustedCallersAttribute()]You must annotate any strong named assembly withAllowPartiallyTrustedCallersAttribute if you want to support partial-trustcallers. This suppresses an implicit link dem<strong>and</strong> for full trust made by the .NETFramework whenever code from a strong named assembly is loaded <strong>and</strong> JITcompiled.Note AllowPartiallyTrustedCallersAttribute is defined in the System.<strong>Security</strong> namespace, soyou must reference this namespace with a using statement.2. Request appropriate permissions.Although not strictly necessary, requesting appropriate permissions is a goodpractice because it allows an administrator to view the assembly’s permissionrequirements by using tools like Permview.exe. Since the event log assembly canbe accessed from partial-trust callers, this assembly does not need to request a fulltrust permission set. The assembly in this example only writes to the event log ona specific machine <strong>and</strong>, therefore, only needs the following permission request:[assembly:EventLogPermissionAttribute(<strong>Security</strong>Action.RequestMinimum,MachineName="",PermissionAccess=EventLogPermissionAccess.Instrument)]However, if your assembly needs to request full trust, request the unrestrictedpermission set as follows:[assembly: PermissionSet(<strong>Security</strong>Action.RequestMinimum, Unrestricted=true)]

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

Saved successfully!

Ooh no, something went wrong!