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.

How To: Use Code Access <strong>Security</strong> Policy to Constrain an Assembly 825Summary of StepsThis How To includes the following steps:1. Create an assembly that performs file I/O.2. Create a <strong>Web</strong> application.3. Test file I/O with no code access security constraints.4. Configure code access security policy to constrain file I/O.5. Test file I/O with code access security constraints.Step 1. Create an Assembly That Performs File I/OIn this step, you create an assembly that performs file I/O using a supplied filename. To create a new assembly that performs file I/O1. Create a new Microsoft Visual C# development tool class library project calledFileIO <strong>and</strong> rename class1.cs to FileIO.cs.2. Add a strong name to the assembly.By adding a strong name, you make the assembly tamper proof by digitallysigning it. The public key component of the strong name also providescryptographically strong evidence for code access security policy. Anadministrator can apply policy by using the strong name to uniquely identifythe assembly.3. Use a fixed assembly version. Open Assemblyinfo.cs <strong>and</strong> set theAssemblyVersion attribute as shown below:[assembly: AssemblyVersion("1.0.0.1")]4. Add the following using statements to the top of FileIO.cs:using System.IO;using System.Text;5. Rename Class1 to FileWrapper <strong>and</strong> seal the class to prevent inheritance.public sealed class FileWrapper6. Rename the default constructor to match the class name <strong>and</strong> change it to private,which prevents instances of the FileWrapper class from being created. This classprovides static methods only.

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

Saved successfully!

Ooh no, something went wrong!