← Java / Spring · 目次

JAVA-026 / 初級

Spring Boot デフォルトエラーページと情報露出(/error 詳細)

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

なぜ問題になるのか?

例外クラス名やパスがレスポンスに露出し、攻撃の手掛かりになります。

修正方法

java
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorDto> handle(Exception e) {
    log.error("unhandled", e);   // サーバーログのみ
    return ResponseEntity.status(500).body(new ErrorDto("INTERNAL_ERROR"));
}

参考資料