-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
CORS Headers Added to Pre-Flight Request on Ambiguous Match Even Without @CrossOrigin #26490
Comments
A pre-flight request is mapped based on information in CORS headers about the would-be, actual request. However those headers describe only a subset of what I can refine the behavior so that for 0 matches with CORS config, we don't return Does that sound alright? |
Thanks for fast investigation. That sounds alright for me. I get the point where you can not choose the "right" one and the current behavior must apply. |
Not quite. In the absence of CORS configuration, it should result in a rejection. |
Thats exactly what I am looking for. I am totally fine with 403. Thanks |
By default CORS support is disabled but in case of multipe valid method mappings, Spring just adds CORS Headers to preflight requests with allowed origin *!
In AbstractHandlerMethodMapping.lookupHandlerMethod():410 there is a check, whether a mapping has more than one matches. If its a perfect match, everything is fine here.
But in the case, that there a multiple mappings EVERY preflight requests will be handled by PREFLIGHT_AMBIGUOUS_MATCH.
spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java
Line 410 in c82a445
Just a few lines later, the cors configurations will be gathered and for this special handler, the CORS-configuration will allow everything to everyone.
spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java
Line 477 in c82a445
You can simply check this behavior by making a brand new Spring Boot application with Spring Web without any changes. Just send an OPTIONS request to
/error
.BasicErrorController
has two mappings for this path and voila.All in all: I don't want my app to respond with CORS-headers at all, as I do not have any CORS configuration, but unfortunately Spring just adds those headers to my responses.
The text was updated successfully, but these errors were encountered: