Description
An exception message or stack trace in an HTTP response can show users internal paths, class names, SQL errors, or configuration values.
Potential impact
The error may disclose sensitive values or reveal internal structures and input checks that can help someone target the application.
Remediation
- Return an appropriate status and a generic message. Keep strings from
getMessage()orgetLocalizedMessage()out of the response. - Record diagnostic exceptions in access-controlled server logs. Disable framework debug pages and detailed error responses in production.
Examples
Before
java
catch (Exception e) {
response.getWriter().write(e.getMessage());
}
After
java
catch (Exception e) {
logger.warn("request failed", e);
response.sendError(500, "Internal server error");
}
In the revised handler, logger.warn records the exception on the server and sendError sends the client a generic error with status 500.