← Java / Spring · Contents

JAVA-026 / Beginner

Spring Boot default error page and information disclosure (/error details)

A05:2021 Security Misconfiguration · CWE-209 Error Message Information Exposure

Why is this a problem?

Exception class names and paths appear in responses and provide clues for attackers.

How to fix it

java
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorDto> handle(Exception e) {
    log.error("unhandled", e);   // Server logs only
    return ResponseEntity.status(500).body(new ErrorDto("INTERNAL_ERROR"));
}

Further reading