Error handling without leaking details to attackers
Plan useful internal error reporting while preventing public responses from exposing stack traces, credentials or implementation details.
OWASP's Error Handling Cheat Sheet starts from the point that attacks typically begin with reconnaissance, where the attacker gathers technical details such as server, framework and library names and versions. Unhandled errors help with that and can also reveal injection points. We read the sheet on 15 November 2026. We skimmed its framework code samples (Java, Spring, ASP.NET Core, ASP.NET Web API) and did not run them, and we did not read the WSTG and RFC pages it links.
What a leak looks like
The sheet's examples: a full exception page showing the framework and server versions and a stack trace, and a database warning showing the install path and the failing call. Either tells an attacker what you run and where to poke.
The target behaviour
When something unexpected happens:
- return a generic response to the user, and
- log safe diagnostic details on the server for investigation, not in the response. Apply the logging guide's rules for secrets and personal data rather than copying raw request bodies or credentials.
The sheet suggests a global error handler in the runtime configuration or code, so no failure path is forgotten. It assumes a REST API backend, says to cover all failure modes as far as possible and use 5xx only for requests the server cannot fulfil, and points to Problem Details for HTTP APIs (RFC 7807, now RFC 9457 in its references) as a response format. In its samples, the generic body is a short message such as "An error occur, please retry", with an error flag header. It notes it may be wise to use 4xx codes when clients misbehave.
Its appendix says to use error messages without implementation details, and in general 4xx for client mistakes and 5xx for server failures.
Checklist for your team
- Is there one global handler for unexpected errors in each service?
- Does production return a safe error response without implementation details, using an appropriate status and request identifier where useful?
- Are the details (and a way to find the matching request) in server logs?
- Do debug pages, stack traces and database errors stay off in production?
- Have we looked at what a failed request returns, using a test request?
Related: REST API security checklist, authorization basics, logging basics.
Limits
One OWASP page. We did not test any of the framework samples and give none here. We give no statistics. Which status code fits a given failure is your API's decision; the sheet gives only the broad 4xx and 5xx split.
By Omnistu.