Skip to content
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

Duplicate Vary headers after enabling CORS filter #24829

Closed
moomba42 opened this issue Mar 31, 2020 · 3 comments
Closed

Duplicate Vary headers after enabling CORS filter #24829

moomba42 opened this issue Mar 31, 2020 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@moomba42
Copy link

Affects: 2.2.6 and up, from what i tested.


Summary
I have noticed strange behavior when requesting a static resource with GET, while having the cors filter enabled by providing a CorsFilter bean.
The problem is that the Vary headers get duplicated. This only happens, when the url gets mapped by SimpleUrlHandlerMapping to a request handler that implements CorsConfigurationSource,
because then the AbstractHandlerMapping that the SimpleUrlHandlerMapping extends, injects a CorsInterceptor into the HandlerExecutionChain.
This CorsInterceptor then uses a DefaultCorsProcessor to process the requests, which in turn automatically appends the Vary headers.
The problem is that the CorsFilter also uses this DefaultCorsProcessor, so that's why the Vary headers get duplicated.

Current behavior
When enabling the cors filter, static file responses contain duplicate Vary headers.

Expected behavior
When enabling the cors filter, static file responses contain unique Vary headers.

Configuration

  • Spring Boot 2.2.6
  • Spring Web 5.2.5
  • Java 8

Sample
https://github.com/rwinch/spring-boot-double-vary-headers/tree/no-security

Related
Previously i thought this was related to spring security, so i created a ticket there (already resolved).
I'm linking it here for reference:
spring-projects/spring-security#8245

@moomba42
Copy link
Author

moomba42 commented Mar 31, 2020

A potential fix would be to only inject the CorsInterceptor in the AbstractHandlerMapping if the handler extends CorsConfigurationSource AND it provides a non-null CorsConfiguration too.
Right now this check is being done in AbstractHandlerMapping#hasCorsConfigurationSource
Or another way would be to add the Vary headers in the DefaultCorsProcessor#processRequest only if they aren't already present.

@rhuitl
Copy link

rhuitl commented Apr 15, 2020

Are there any updates on this issue?

@sdeleuze sdeleuze added this to the 5.2.6 milestone Apr 15, 2020
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 15, 2020
@sdeleuze
Copy link
Contributor

Fixed and validated with the sample project, thanks for raising this.

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) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants