-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Improve documentation for configuring Spring Security with '/error' #45663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It is documented https://docs.spring.io/spring-security/reference/servlet/getting-started.html#servlet-hello-auto-configuration in Spring Security, and Spring Boot documentation refers to Spring Security documentation in the first paragraph.
By default, everything in the application is protected, and it is up to the user to determine which URLs should be allowed. For the In general, users typically register their own |
I think this sentence can be rephrased a little bit with including information that Boot's |
What sentence is that exactly, @nosan? |
I think the first one that mentions that applications are secured by default. Maybe it could be rephrased to something like:
Or maybe add a |
/error
endpoint requires authentication and prevents error handling for public endpoints when using spring web security/error
/error
When using Spring Boot with Spring Security, if an unauthenticated user sends a request to a public endpoint e.g.
/auth/signup
that results in an exception (e.g., validation error), Spring framework intercepts the error and redirects it to the/error
endpoint.By default, Spring Boot configures
/error
for exception resolution. However, Spring Security also protects/error
, requiring authentication by default.As a result, expected application exceptions (like
MethodArgumentNotValidException
) are never properly returned to the client for unauthenticated users. Instead, the user receives a403 Forbidden
or401 Unauthorized
error, and the original exception details are lost.This breaks consistent error handling for APIs that are supposed to be public (e.g.,
/auth/signup
).Environment
Code to reproduce
if we send a http request with invalid body like:
expected response should be
400 Bad Request
with error details while actual response we get is401 Unauthorized
.Expected Behavior
The
/error
endpoint should either:Additional Context
This behavior is confusing and non-obvious to developers building public or semi-public REST APIs. Better defaults or clearer documentation would significantly improve the developer experience.
The text was updated successfully, but these errors were encountered: