From 5cbf01864d228f3ff4ae55ed9fcb624fed31836b Mon Sep 17 00:00:00 2001
From: "detail-app[bot]" <180357370+detail-app[bot]@users.noreply.github.com>
Date: Sun, 6 Sep 2026 14:00:47 +0000
Subject: [PATCH] fix(security): route non-CSRF access denials to a generic 403
handler
SecurityConfig wired CsrfAccessDeniedHandler as the catch-all
AccessDeniedHandler, so every authenticated non-CSRF AccessDeniedException
(including controller-thrown denials) was serialized as a false "CSRF token
missing or invalid" 403. Install a DelegatingAccessDeniedHandler that routes
MissingCsrfTokenException/InvalidCsrfTokenException to the CSRF handler and
all other denials to a new GenericAccessDeniedHandler emitting a generic
"Access denied." JSON 403, so non-CSRF failures no longer claim a CSRF
failure while CSRF messaging is preserved.
---
config/spotbugs/spotbugs-exclude.xml | 10 ++
.../security/GenericAccessDeniedHandler.java | 66 +++++++++++
.../javachat/config/SecurityConfig.java | 16 ++-
.../GenericAccessDeniedHandlerTest.java | 64 ++++++++++
.../web/RevokeApiKeyAuthIntegrationTest.java | 112 ++++++++++++++++++
5 files changed, 267 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/com/williamcallahan/javachat/adapters/in/web/security/GenericAccessDeniedHandler.java
create mode 100644 src/test/java/com/williamcallahan/javachat/adapters/in/web/security/GenericAccessDeniedHandlerTest.java
create mode 100644 src/test/java/com/williamcallahan/javachat/web/RevokeApiKeyAuthIntegrationTest.java
diff --git a/config/spotbugs/spotbugs-exclude.xml b/config/spotbugs/spotbugs-exclude.xml
index fd34e59a..76673913 100644
--- a/config/spotbugs/spotbugs-exclude.xml
+++ b/config/spotbugs/spotbugs-exclude.xml
@@ -380,6 +380,16 @@
+
+
+
+
+
+