spring-cloud / spring-cloud/spring-cloud-gateway

Different header behavior CORS vs CSP

Open
#4,065 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
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:

  1. Both should support automatic merging, or
  2. 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

  1. Is this difference intentional? If so, what's the reasoning behind treating CORS and CSP differently?
  2. Where can I find the merge logic for CORS?
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.