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.

212 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>s<strong>Web</strong> ServicesCode that calls <strong>Web</strong> services must be granted the <strong>Web</strong>Permission by code accesssecurity policy. The <strong>Web</strong>Permission actually constrains access to any HTTP Internetbasedresources.Constraining <strong>Web</strong> Service ConnectionsTo restrict the <strong>Web</strong> services to which your code can access, use the<strong>Web</strong>PermissionAttribute together with <strong>Security</strong>Action.PermitOnly. For example,the following code ensures that the PlaceOrder method <strong>and</strong> any methods it calls canonly invoke <strong>Web</strong> services on the http://somehost site.[<strong>Web</strong>PermissionAttribute(<strong>Security</strong>Action.PermitOnly,ConnectPattern=@"http://somehost/.*")][EnvironmentPermissionAttribute(<strong>Security</strong>Action.PermitOnly, Read="USERNAME")]public static void PlaceOrder(XmlDocument order){PurchaseService.Order svc = new PurchaseService.Order();// <strong>Web</strong> service uses Windows authenticationsvc.Credentials = System.Net.CredentialCache.DefaultCredentials;svc.PlaceOrder(order);}In the prior example, the ConnectPattern property of the <strong>Web</strong>PermissionAttributeclass is used. This allows you to supply a regular expression that matches the rangeof addresses to which a connection can be established. TheEnvironmentPermissionAttribute shown previously is required because the codeuses Windows authentication <strong>and</strong> default credentials.The following example shows how to use the Connect attribute to restrictconnections to a specific <strong>Web</strong> service.[<strong>Web</strong>PermissionAttribute(<strong>Security</strong>Action.PermitOnly,Connect=@"http://somehost/order.asmx")]

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

Saved successfully!

Ooh no, something went wrong!