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 197Usually, you do not explicitly dem<strong>and</strong> code access permissions. The .NETFramework classes do this for you, <strong>and</strong> a duplicate dem<strong>and</strong> is unnecessary. However,there are occasions when you need to issue explicit dem<strong>and</strong>s, for example, if yourcode exposes a custom resource by using unmanaged code or if your code accessescached data. You can authorize code in the following ways:● Restrict which code can call your code.●●●Restrict inheritance.Consider protecting cached data.Protect custom resources with custom permissions.Restrict Which Code Can Call Your CodeA method marked as public can be called by any code outside of the currentassembly. To further restrict which other code can call your methods, you can use acode access security identity permission dem<strong>and</strong> as shown in the following example.public sealed class Utility{// Although SomeOperation() is a public method, the following// permission dem<strong>and</strong> means that it can only be called by assemblies// with the specified public key.[StrongNameIdentityPermission(<strong>Security</strong>Action.LinkDem<strong>and</strong>,PublicKey="00240000048...97e85d098615")]public static void SomeOperation() {}}The above code shows a link dem<strong>and</strong>. This results in the authorization of theimmediate caller. Therefore, your code is potentially open to luring attacks, where amalicious assembly could potentially access the protected resources or operationsprovided by your assembly through a trusted intermediary assembly with thespecified strong name.Depending on the nature of the functionality provided by your class, you may needto dem<strong>and</strong> another permission to authorize the calling code in addition to using theidentity-based link dem<strong>and</strong>. Alternatively, you can consider using a full dem<strong>and</strong> inconjunction with the StrongNameIdentityPermission, although this assumes that allcode in the call stack is strong name signed using the same private key.Note Issuing a full stack walk dem<strong>and</strong> for the StrongNameIdentityPermission does not work if yourassembly is called by a <strong>Web</strong> application or <strong>Web</strong> service. This is because it is not possible to strongname the dynamically compiled classes associated with ASP.NET <strong>Web</strong> applications or <strong>Web</strong> services.

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

Saved successfully!

Ooh no, something went wrong!