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 9: Using Code Access <strong>Security</strong> with ASP.NET 243Note Any strong named assembly that is called by an ASP.NET <strong>Web</strong> application or <strong>Web</strong> servicemust be installed in the GAC. In this instance, you should install the assembly in the GAC toensure that it is granted full trust.5. Configure your <strong>Web</strong> application for medium trust. Add the following code to<strong>Web</strong>.config or place it in Machine.config inside a element that points toyour application:6. Reference the data access assembly from your ASP.NET <strong>Web</strong> application.Since a strong named assembly must be in the GAC <strong>and</strong> not the \bin directory of a<strong>Web</strong> application, you must add the assembly to the list of assemblies used in theapplication if you are not using code behind files. You can obtain thePublicKeyToken of your assembly by using the following comm<strong>and</strong>:sn -Tp oledbwrapper.dllNote Use a capital –T switch.Then add the following to Machine.config or <strong>Web</strong>.config:Note In between successive rebuilds of your wrapper assembly, you might need to recycle theASP.NET worker process because your wrapper assembly, which is installed in the GAC is cachedby the ASP.NET process. To recycle the ASP.NET worker process (Aspnet_wp.exe) you can run theIISreset.exe utility.7. Protect the code that calls Assert.The Assert call means that any code that calls the data access wrapper can interactwith the OLE DB data source. To prevent malicious code from calling the dataaccess component <strong>and</strong> potentially using it to attack the database, you can issue afull dem<strong>and</strong> for a custom permission prior to calling Assert <strong>and</strong> update themedium-trust policy file to grant your <strong>Web</strong> application the custom permission.This solution entails a reasonable amount of developer effort.For more information about developing a custom permission, see “How To: Createa Custom Encryption Permission” in the “How To” section of this guide.

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

Saved successfully!

Ooh no, something went wrong!