Use the Exception Shielding pattern to sanitize unsafe exceptions by replacing them with exceptions that are safe by design. Return only those exceptions to the client that have been sanitized or exceptions that are safe by design. Exceptions that are safe by design do not contain sensitive information in the exception message and they do not contain a detailed stack trace, either of which might reveal sensitive information about the Web service's inner workings.
Participants
Exception shielding involves the following participants:
- Client. The client application that calls a Web service.
- Service. The Web service that processes requests that are received from clients.
Process
Figure 1 illustrates how an unhandled exception that is thrown by a Web service is processed by a service that implements exception shielding.
Figure 1
A Web service that implements exception shielding
As illustrated in Figure 1, the exception shielding process involves the following steps:
- The client submits a request to the service.
- The service attempts to process the request and throws an exception. The exception can be safe or unsafe by design.
- Exception shielding logic processes the exception. If the exception type is safe by design, it is already considered sanitized and is returned to the client unmodified. If the exception is unsafe, the exception is replaced with an exception that is safe by design, which is returned to the client.
- The service returns the processed exception to the client. The exception is wrapped in a SOAPException before it is returned to the client.
Example
Global Bank has designed a Web service that checks the balance of customer accounts. Global Bank needs to ensure that when exceptions occur, information potentially useful to attackers is not revealed.
For some anticipated exceptions that are safe by design, such as data validation errors, the Web service returns appropriate information to the client. For other exceptions, such as database failures that throw a SQLException on the server side, the exception logic sanitizes the exception, replacing it with an exception that is safe by design.