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.

210 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>s[SqlClientPermissionAttribute(<strong>Security</strong>Action.PermitOnly,AllowBlankPassword=false)]public static int CheckProductStockLevel(string productCode){// Retrieve the connection string from the registrystring connectionString = GetConnectionString();. . .}For more information about how to s<strong>and</strong>box data access code to allow the OLE DB<strong>and</strong> other data providers to be used from partial trust <strong>Web</strong> applications, seeChapter 9, “Using Code Access <strong>Security</strong> with ASP.NET.”Directory ServicesCurrently, code that uses classes from the System.DirectoryServices namespace toaccess directory services such as Active Directory must be granted full trust.However, you can use the DirectoryServicesPermission to constrain the type ofaccess <strong>and</strong> the particular directory services to which code can connect.Constraining Directory Service AccessTo constrain code, you can use the DirectoryServicesPermissionAttribute togetherwith <strong>Security</strong>Action.PermitOnly. The following attribute ensures that the code canonly connect to a specific LDAP path <strong>and</strong> can only browse the directory.[DirectoryServicesPermissionAttribute(<strong>Security</strong>Action.PermitOnly,Path="LDAP://rootDSE",PermissionAccess=DirectoryServicesPermissionAccess.Browse)]public static string GetNamingContext(string ldapPath){DirectorySearcher dsSearcher = new DirectorySearcher(ldapPath);dsSearcher.PropertiesToLoad.Add("defaultNamingContext");dsSearcher.Filter = "";SearchResult result = dsSearcher.FindOne();return (string)result.Properties["adsPath"][0];}

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

Saved successfully!

Ooh no, something went wrong!