Skip to content

Fix CORS header duplication in chained proxies#2990

Open
BiosSystem wants to merge 1 commit into
labstack:masterfrom
BiosSystem:fix-cors-header-duplication
Open

Fix CORS header duplication in chained proxies#2990
BiosSystem wants to merge 1 commit into
labstack:masterfrom
BiosSystem:fix-cors-header-duplication

Conversation

@BiosSystem
Copy link
Copy Markdown

Fixes #2853.

When Echo CORS middleware is run in a chained proxy setup (or in front of any handler copying upstream headers using Add), headers like Access-Control-Allow-Origin and Vary get duplicated in the response.

Changes:

  • Run simple request CORS header writing inside a Before hook on the response. This allows the proxy's CORS config to cleanly Set the headers, overriding duplicated upstream headers from the proxy or downstream response copy.
  • Implement addVaryHeader helper to merge and deduplicate Vary values case-insensitively.
  • Add unit test simulating ReverseProxy behavior to verify headers are not duplicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CORS middleware duplicates headers when used in chained proxy servers

1 participant