Skip to content

Commit

Permalink
fix: Non wildcard origin in CORS should sent Vary header (apache#9010)
Browse files Browse the repository at this point in the history
  • Loading branch information
boekkooi-lengoo authored and AlinsRan committed Jun 26, 2023
1 parent 3e4511e commit f266ee8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions apisix/plugins/cors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ local function set_cors_headers(conf, ctx)
end

core.response.set_header("Access-Control-Allow-Origin", ctx.cors_allow_origins)
if ctx.cors_allow_origins ~= "*" then
core.response.add_header("Vary", "Origin")
end

core.response.set_header("Access-Control-Allow-Methods", allow_methods)
core.response.set_header("Access-Control-Max-Age", conf.max_age)
core.response.set_header("Access-Control-Expose-Headers", conf.expose_headers)
Expand Down Expand Up @@ -305,6 +301,9 @@ function _M.header_filter(conf, ctx)
conf.allow_origins_by_metadata, ctx, req_origin
)
end
if conf.allow_origins ~= "*" then
core.response.add_header("Vary", "Origin")
end
if allow_origins then
ctx.cors_allow_origins = allow_origins
set_cors_headers(conf, ctx)
Expand Down
4 changes: 2 additions & 2 deletions t/plugin/cors3.t
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Origin: http://foo.example.org
hello world
--- response_headers
Access-Control-Allow-Origin:
Vary:
Vary: Origin
Access-Control-Allow-Methods:
Access-Control-Allow-Headers:
Access-Control-Expose-Headers:
Expand Down Expand Up @@ -254,7 +254,7 @@ Origin: http://foo.example.org
hello world
--- response_headers
Access-Control-Allow-Origin:
Vary:
Vary: Origin
Access-Control-Allow-Methods:
Access-Control-Allow-Headers:
Access-Control-Expose-Headers:
Expand Down

0 comments on commit f266ee8

Please sign in to comment.