Preventing Web Service Security Breaches with Unit Testing

[article]

Establishing a Final Defense with Design by Contract
If a security breach would have very serious consequences for your application, you might want to consider building a final layer of security into the code itself. If your Web service is built using Java, you can do this with Design by Contract (DbC).

DbC was designed to express and enforce a contract between a piece of code and its caller. This contract specifies what the callee expects and what the caller can expect (for example, expectations about what inputs will be passed to a method or conditions that a particular class or method should always satisfy). DbC tools generally have developers incorporate contract information into comment tags and then instrument the code with a special compiler to create assertion-like expressions out of the contract keywords. When the instrumented code is run, contract violations are typically sent to a monitor or logged to a file. The degree of program interference varies. You can often choose 1) nonintrusive monitoring (problems are reported, but program execution is not affected), 2) having the program throw an exception when a contract is violated, or 3) having the program perform a user-defined action when a contract is violated.

DbC can enforce security boundaries by ensuring that the application never accepts inputs known to lead to security problems or enters a state known to compromise security. The first step in creating an infrastructure that provides these safeguards is to use unit testing to determine what inputs and situations can make the service vulnerable to security breaches, then writing contracts that explicitly forbid these inputs and situations. Next, you configure the program so that whenever the conditions specified in the contract are not satisfied, the code fires an exception and the requested action (for example, a method invocation) is not allowed to occur. When this infrastructure is developed after thorough unit testing, it provides a very effective last layer
of defense.

Conclusion
Unless the industry develops an easy way to ensure Web service security, I fear that the security issues inherent in the very nature of Web services will make it difficult (though not impossible) to apply them in situations where security is of utmost importance. However, Web services can nevertheless be applied easily and profitably in many situations where security concerns are irrelevant. I predict that Web services will enjoy the most success and acceptance in the variety of possible implementations that do not involve security issues.

About the author

TechWell Contributor's picture TechWell Contributor

The opinions and positions expressed within these guest posts are those of the author alone and do not represent those of the TechWell Community Sites. Guest authors represent that they have the right to distribute this content and that such content is not violating the legal rights of others. If you would like to contribute content to a TechWell Community Site, email editors@techwell.com.

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!

Upcoming Events

May 04
May 04
May 04
Jun 01