Skip to content

CORS Options request forbidden with Webflux [SPR-15704] #20261

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

Closed
spring-projects-issues opened this issue Jun 26, 2017 · 4 comments
Closed

CORS Options request forbidden with Webflux [SPR-15704] #20261

spring-projects-issues opened this issue Jun 26, 2017 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 26, 2017

Guillaume DROUET opened SPR-15704 and commented

This issue has been reproduced with a spring boot application 2.0.0.M2
This is not reproduced with M1.
Please find an example in attachment. A RouterFunction handles an options request to allow CORS. In the unit test, you can see that when a request is sent, a 403 is returned. It seems that the response is inspected by cors processor before the handler has been invoked.


Affects: 5.0 RC2

Attachments:

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 26, 2017

Sébastien Deleuze commented

This behavior is expected since as of this commit the functional router leverages @EnableWebFlux infrastructure which provides built-in CORS support with no CORS mapping enabled by default. CORS support is complex to implement, so we clearly recommend leveraging Spring CORS support to handle this kind of requests.

Spring Framework 5 RC2 already provides a way to configure such CORS support via @EnableWebFlux + overriding WebFluxConfigurer#addCorsMappings.

As part of the upcoming Spring Framework 5 RC3, I initially added via #20126 a CorsWebFilter which allows to configure such support via a filter more flexible with security frameworks for example.

After a deeper look, I think that would also makes sense to add a cors(CorsConfigurationSource source) to HandlerStrategies.Builder in order to allow to configure AbstractHandlerMapping CORS support without application context + annotations. That's why I have reopened #20126 to add such support.

For super advanced use cases you could also disable CORS support by providing a no-op CorsProcessor by this is in practice almost never needed.

Does that make sense to you?

@spring-projects-issues
Copy link
Collaborator Author

Guillaume DROUET commented

+1, I was expecting such answer, there is no reason to ignore dedicated features that help to manage CORS and it's fine if those features disallow user to declare a route that matches a preflight CORS request. However do you confirm that it's still possible to achieve this with a custom, no-op, CorsProcessor?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 26, 2017

Sébastien Deleuze commented

Yes, as discussed in #18266 and #18621 providing a no-op CorsProcessor will allow you to set your custom headers even if I don't recommand that at all (CORS headers need also to be set on the actual request that come after the pre-flight request).

@spring-projects-issues
Copy link
Collaborator Author

Guillaume DROUET commented

Yes perfect, I agree this is not recommended but at least people can do it if they really want.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants