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.

Chapter 8: Code Access <strong>Security</strong> in Practice 215●Native. This is potentially dangerous unmanaged code, but code that is protectedwith a full stack walking dem<strong>and</strong> for the unmanaged code permission. These areimplicitly made by the interop layer unless they have been suppressed with theSupressUnmanagedCode attribute.class NativeMethods {[DllImport("user32")]internal static extern void FormatDrive(string driveLetter);}●Unsafe. This is potentially dangerous unmanaged code that has the securitydem<strong>and</strong> for the unmanaged code permission declaratively suppressed. Thesemethods are potentially dangerous. Any caller of these methods must do a fullsecurity review to ensure that the usage is safe <strong>and</strong> protected because no stackwalk is performed.[SuppressUnmanagedCode<strong>Security</strong>]class UnsafeNativeMethods {[DllImport("user32")]internal static extern void CreateFile(string fileName);}Request the Unmanaged Code PermissionStrong-named[assembly: <strong>Security</strong>Permission(<strong>Security</strong>Action.RequestMinimum,UnmanagedCode=true)]S<strong>and</strong>box Unmanaged API CallsIsolate calls to unmanaged code in specific assemblies <strong>and</strong> keep the number ofassemblies that call unmanaged code to a minimum. Then, use the s<strong>and</strong>boxingpattern to ensure that the unmanaged code permission is only granted to selectedassemblies. To s<strong>and</strong>box your managed code that calls unmanaged code1. Place your code that calls unmanaged code in a separate (wrapper) assembly.2. Add a strong name to the assembly.This allows custom code access security policy to be easily applied to theassembly. For more information, see the “Strong Names” section in Chapter 7,“Building Secure Assemblies.”3. Request the unmanaged code permission (as described in the preceding section.)

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

Saved successfully!

Ooh no, something went wrong!