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.

628 Part V: Assessing Your <strong>Security</strong>Unmanaged CodeGive special attention to code that calls unmanaged code, including Win32 DLLs <strong>and</strong>COM objects, due to the increased security risk. Unmanaged code is not verifiablytype safe <strong>and</strong> introduces the potential for buffer overflows. Resource access fromunmanaged code is not subject to code access security checks. This is theresponsibility of the managed wrapper class.Generally, you should not directly expose unmanaged code to partially trustedcallers. For more information about the issues raised in this section, see the“Unmanaged Code” sections in Chapter 7, “Building Secure Assemblies,” <strong>and</strong>Chapter 8, “Code Access <strong>Security</strong> in Practice.”Use the following review questions to validate your use of unmanaged code:●Do you assert the unmanaged code permission?If so, check that your code dem<strong>and</strong>s an appropriate permission prior to callingthe Assert method to ensure that all callers are authorized to access the resourceor operation exposed by the unmanaged code. For example, the following codefragment shows how to dem<strong>and</strong> a custom Encryption permission <strong>and</strong> then assertthe unmanaged code permission:// Dem<strong>and</strong> custom EncryptionPermission.(new EncryptionPermission(EncryptionPermissionFlag.Encrypt, storeFlag)).Dem<strong>and</strong>();// Assert the unmanaged code permission.(new <strong>Security</strong>Permission(<strong>Security</strong>PermissionFlag.UnmanagedCode)).Assert();// Now use P/Invoke to call the unmanaged DPAPI functions.●For more information see “Assert <strong>and</strong> RevertAssert” in Chapter 8, “Code Access<strong>Security</strong> in Practice.”Do you use SuppressUnmanagedCodeAttribute?This attribute suppresses the dem<strong>and</strong> for the unmanaged code permission issuedautomatically when managed code calls unmanaged code. If P/Invoke methods orCOM interop interfaces are annotated with this attribute, ensure that all codepaths leading to the unmanaged code calls are protected with security permissiondem<strong>and</strong>s to authorize callers. Also check that this attribute is used at the methodlevel <strong>and</strong> not at the class level.Note Adding a SupressUnmanagedCode<strong>Security</strong>Attribute turns the implicit dem<strong>and</strong> for theUnmanagedCode permission issued by the interop layer into a LinkDem<strong>and</strong>. Your code isvulnerable to luring attacks.

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

Saved successfully!

Ooh no, something went wrong!