Skip to content

Commit

Permalink
Re-add support for multiple Access-Control-Request-Headers field (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jub0bs committed Aug 29, 2024
1 parent 1562b17 commit a814d79
Show file tree
Hide file tree
Showing 5 changed files with 562 additions and 303 deletions.
8 changes: 5 additions & 3 deletions cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,11 @@ func (c *Cors) handlePreflight(w http.ResponseWriter, r *http.Request) {
// Note: the Fetch standard guarantees that at most one
// Access-Control-Request-Headers header is present in the preflight request;
// see step 5.2 in https://fetch.spec.whatwg.org/#cors-preflight-fetch-0.
reqHeaders, found := first(r.Header, "Access-Control-Request-Headers")
if found && !c.allowedHeadersAll && !c.allowedHeaders.Subsumes(reqHeaders[0]) {
c.logf(" Preflight aborted: headers '%v' not allowed", reqHeaders[0])
// However, some gateways split that header into multiple headers of the same name;
// see https://github.com/rs/cors/issues/184.
reqHeaders, found := r.Header["Access-Control-Request-Headers"]
if found && !c.allowedHeadersAll && !c.allowedHeaders.Accepts(reqHeaders) {
c.logf(" Preflight aborted: headers '%v' not allowed", reqHeaders)
return
}
if c.allowedOriginsAll {
Expand Down
Loading

0 comments on commit a814d79

Please sign in to comment.