spring-projects / spring-projects/spring-security
Default Cache-Control/Expires/Pragma headers are being added in async response with custom Cache-Control header value
@sjohnr is already working on this.
Since Jun 14, 2024.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Describe the bug
Setting up a basic async HTTP GET endpoint where the returned response is allowed to be cached by downstream clients (via the Cache-Control header) produces duplicate Cache-Control header values. Expires and Pragma headers are also being added.
To Reproduce
- Spring Boot 2.7.x project
- Basic application with
EnableWebSecurityannotation - Async HTTP GET endpoint where the
DeferredResultis aResponseEntitywith aCache-Controlheader value
Headers being returned in case of the async HTTP response:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 2
Content-Type: text/html;charset=UTF-8
Date: Mon, 13 Mar 2023 18:04:41 GMT
Expires: 0
Keep-Alive: timeout=60
Pragma: no-cache
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Headers being returned in case of the sync HTTP response:
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 2
Content-Type: text/html;charset=UTF-8
Date: Mon, 13 Mar 2023 18:06:24 GMT
Keep-Alive: timeout=60
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Expected behavior
Setting Cache-Control/Expires/Pragma headers in async request processing context should be honored by the security header writer and it should not populate the HTTP response with the default headers in this case.
See the sample's sync endpoint for desired behavior.
Sample
https://github.com/cmark/spring-security-async-cache-control
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.