spring-cloud / spring-cloud/spring-cloud-gateway
Different header behavior CORS vs CSP
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
I've noticed an difference in how Spring handles header merging for CORS vs Content Security Policy (CSP) when using Spring Cloud Gateway with upstream services that also set these headers.
Current Behavior
CORS Headers
- CORS headers from the gateway and upstream services are automatically merged when both services set CORS
- This works seamlessly without additional configuration
CSP Headers
- No merge functionality exists for CSP headers
- When an upstream service sets CSP headers, the gateway's CSP configuration is completely ignored
Expected Behavior
I would expected both CORS and CSP should behave consistently. Either:
- Both should support automatic merging, or
- Both should explicitly overwrite without merging
I also found no documentation on this behavior. I this spring default behavior or something special in spring cloud gateway?
Questions
- Is this difference intentional? If so, what's the reasoning behind treating CORS and CSP differently?
- Where can I find the merge logic for CORS?
- Is there a way to achieve consistent behavior? Should CSP get similar merge support, or should developers handle this at the application level?
Thanks
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.
Research direction
No files or tests are named. Locate the gateway's CORS header merge entry point and the CSP header handling, then compare their behavior and existing tests. Done means documenting the intentional behavior or defining and testing a consistent merge or overwrite policy for both headers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api, security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100