Detailed Spring error attributes exposed

Detailed Spring error attributes exposed

Description

Spring Boot error responses can expose internal paths and failed validation details when they include exception messages, stack traces, or binding errors.

Potential impact

  • Exposure of class names, paths, queries and internal state
  • Information that helps attackers refine inputs or automate attacks
  • Disclosure of sensitive exception messages

Remediation

  1. Exclude detailed error messages, stack traces, binding errors, and exception types from the default production response. Use server.error.* in Spring Boot 3.x and the corresponding spring.web.error.* properties in 4.x.
  2. Check responses built by controllers or custom error handlers as well. Return a generic message and a tracking ID to the client. Keep necessary diagnostic details in restricted server logs after removing passwords and tokens.

Examples

These properties configure the default error response in Spring Boot 3.x.

Before

properties
server.error.include-message=always
server.error.include-stacktrace=always

After

properties
server.error.include-message=never
server.error.include-stacktrace=never
server.error.include-binding-errors=never
server.error.include-exception=false

The revised settings exclude all four detailed attributes from the default response. Check actual responses, since controllers that write their own error bodies are independent of these settings.

References