diff --git a/kong/clustering/compat/removed_fields.lua b/kong/clustering/compat/removed_fields.lua index 9a63e490929..c5a2af2c7f3 100644 --- a/kong/clustering/compat/removed_fields.lua +++ b/kong/clustering/compat/removed_fields.lua @@ -231,7 +231,7 @@ return { -- Any dataplane older than 3.10.0 [3010000000] = { cors = { - "skip_cors_when_origin_is_empty", + "allow_origin_absent", }, session = { "hash_subject", diff --git a/kong/plugins/cors/handler.lua b/kong/plugins/cors/handler.lua index 456c0c248a0..f1b111dcb0a 100644 --- a/kong/plugins/cors/handler.lua +++ b/kong/plugins/cors/handler.lua @@ -248,7 +248,7 @@ function CorsHandler:header_filter(conf) end local req_origin = kong.request.get_header("origin") - if not req_origin and conf.skip_cors_when_origin_is_empty then + if not req_origin and not conf.allow_origin_absent then return end diff --git a/kong/plugins/cors/schema.lua b/kong/plugins/cors/schema.lua index 3f5fbbf5b99..1334f789feb 100644 --- a/kong/plugins/cors/schema.lua +++ b/kong/plugins/cors/schema.lua @@ -48,7 +48,7 @@ return { { credentials = { description = "Flag to determine whether the `Access-Control-Allow-Credentials` header should be sent with `true` as the value.", type = "boolean", required = true, default = false }, }, { private_network = { description = "Flag to determine whether the `Access-Control-Allow-Private-Network` header should be sent with `true` as the value.", type = "boolean", required = true, default = false }, }, { preflight_continue = { description = "A boolean value that instructs the plugin to proxy the `OPTIONS` preflight request to the Upstream service.", type = "boolean", required = true, default = false }, }, - { skip_cors_when_origin_is_empty = { description = "A boolean value that skip cors response headers when origin header of request is empty", type = "boolean", required = true, default = false }, }, + { allow_origin_absent = { description = "A boolean value that skip cors response headers when origin header of request is empty", type = "boolean", required = true, default = true }, }, }, }, }, }, } diff --git a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua index 79e05ee2436..805f0e1e66d 100644 --- a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua +++ b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua @@ -207,7 +207,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() enabled = true, config = { -- [[ new fields 3.10.0 - skip_cors_when_origin_is_empty = false, + allow_origin_absent = true, -- ]] -- [[ new fields 3.5.0 private_network = false @@ -215,10 +215,10 @@ describe("CP/DP config compat transformations #" .. strategy, function() } } - assert.not_nil(cors.config.skip_cors_when_origin_is_empty) + assert.not_nil(cors.config.allow_origin_absent) local expected_cors = cycle_aware_deep_copy(cors) do_assert(uuid(), "3.10.0", expected_cors) - expected_cors.config.skip_cors_when_origin_is_empty = nil + expected_cors.config.allow_origin_absent = nil assert.not_nil(cors.config.private_network) expected_cors = cycle_aware_deep_copy(expected_cors) @@ -235,7 +235,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() enabled = true, config = { -- [[ new fields 3.10.0 - skip_cors_when_origin_is_empty = false, + allow_origin_absent = true, -- ]] -- [[ new fields 3.5.0 private_network = false @@ -243,7 +243,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() } } do_assert(uuid(), "3.10.0", cors) - cors.config.skip_cors_when_origin_is_empty = nil + cors.config.allow_origin_absent = nil do_assert(uuid(), "3.5.0", cors) diff --git a/spec/03-plugins/13-cors/01-access_spec.lua b/spec/03-plugins/13-cors/01-access_spec.lua index 4d46c2cc3ec..141d6c4d543 100644 --- a/spec/03-plugins/13-cors/01-access_spec.lua +++ b/spec/03-plugins/13-cors/01-access_spec.lua @@ -476,7 +476,7 @@ for _, strategy in helpers.each_strategy() do name = "cors", route = { id = route15.id }, config = { - skip_cors_when_origin_is_empty = true, + allow_origin_absent = false, origins = { "foo.bar" }, exposed_headers = { "x-auth-token" }, credentials = true @@ -487,7 +487,7 @@ for _, strategy in helpers.each_strategy() do name = "cors", route = { id = route16.id }, config = { - skip_cors_when_origin_is_empty = false, + allow_origin_absent = true, origins = { "foo.bar" }, exposed_headers = { "x-auth-token" }, credentials = true @@ -1161,7 +1161,7 @@ for _, strategy in helpers.each_strategy() do assert.equal("disallowed-domain.test", json.headers["origin"]) end) - it("when enable skip_cors_when_origin_is_empty, no ACAO", function() + it("when disable allow_origin_absent, no ACAO", function() local res = assert(proxy_client:send { method = "GET", headers = { @@ -1174,7 +1174,7 @@ for _, strategy in helpers.each_strategy() do assert.is_nil(res.headers["Access-Control-Expose-Headers"]) end) - it("when disable skip_cors_when_origin_is_empty, ACAO is returned", function() + it("when enable allow_origin_absent, ACAO is returned", function() local res = assert(proxy_client:send { method = "GET", headers = {