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.

336 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>s<strong>Web</strong> Service Endpoint AuthorizationIf your <strong>Web</strong> service is configured for Integrated Windows authentication you canconfigure NTFS permissions on your <strong>Web</strong> service (.asmx) files to control access, basedon the security context of the original caller. This authorization is performed by theASP.NET FileAuthorizationModule <strong>and</strong> impersonation is not required.Regardless of the authentication type, you can use the ASP.NETUrlAuthorizationModule to control access to <strong>Web</strong> service (.asmx) files. You configurethis by adding <strong>and</strong> elements to the element inMachine.config or <strong>Web</strong>.config.For more information about both forms of authorization, see the “Authorization”section in Chapter 19, “Securing Your ASP.NET <strong>Application</strong> <strong>and</strong> <strong>Web</strong> Services.”<strong>Web</strong> Method AuthorizationYou can use declarative principal permission dem<strong>and</strong>s to control access to individual<strong>Web</strong> methods based on the identity or role membership of the caller. The caller’sidentity <strong>and</strong> role membership is maintained by the principal object associated withthe current <strong>Web</strong> request (accessed through HttpContext.User.)[PrincipalPermission(<strong>Security</strong>Action.Dem<strong>and</strong>, Role=@"Manager")][<strong>Web</strong>Method]public string QueryEmployeeDetails(string empID){}For more information about principal permission dem<strong>and</strong>s, see the “Authorization”section in Chapter 10, “Building Secure ASP.NET Pages <strong>and</strong> Controls.”Programmatic AuthorizationYou can use imperative permission checks or explicit role checks by callingIPrincipal.IsInRole inside your <strong>Web</strong> methods for fine-grained authorization logic asfollows.// This assumes non-Windows authentication. With Windows authentication// cast the User object to a WindowsPrincipal <strong>and</strong> use Windows groups as// role namesGenericPrincipal user = User as GenericPrincipal;if (null != user){if ( user.IsInRole(@"Manager") ){// User is authorized to perform manager functionality}}

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

Saved successfully!

Ooh no, something went wrong!