You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I create a route with a CORS plugin specifying at least two allowed origins, and then attempt to access the route using curl with header.Origin=''(empty string), receives empty reply from server.
Create a request curl -ivv http://localhost:8000/ -H "Host: echo-test.com" -H "Origin;" (The header.Origin field is set to an empty string)
curl client info:
* Host localhost:8000 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:8000...
* Connected to localhost (::1) port 8000
> GET / HTTP/1.1
> Host: echo-test.com
> User-Agent: curl/8.7.1
> Accept: */*
> Origin:
>
* Request completely sent off
* Empty reply from server
* Closing connection
curl: (52) Empty reply from server
Kong server error log:
failed to run header_filter_by_lua*: /usr/local/share/lua/5.1/kong/plugins/cors/handler.lua:34: invalid url
stack traceback:
[C]: in function 'assert'
/usr/local/share/lua/5.1/kong/plugins/cors/handler.lua:34: in function 'normalize_origin'
/usr/local/share/lua/5.1/kong/plugins/cors/handler.lua:132: in function 'configure_origin'
/usr/local/share/lua/5.1/kong/plugins/cors/handler.lua:245: in function </usr/local/share/lua/5.1/kong/plugins/cors/handler.lua:240>
/usr/local/share/lua/5.1/kong/init.lua:465: in function 'execute_collected_plugins_iterator'
/usr/local/share/lua/5.1/kong/init.lua:1633: in function 'header_filter'
header_filter_by_lua(nginx-kong.conf:116):2: in main chunk while reading response header from upstream
occurs when the domain parameter is an empty string. This appears to happen when the request origin (req_origin) is passed as an empty string through the CORS plugin logic.
Proposed Fix
We should add a check for empty origin values at:
By adding a condition req_origin ~= "" before processing the origin value, we can prevent empty strings from reaching the assertion check while maintaining valid CORS behavior.
If acceptable, I'd be happy to submit a PR to implement this fix.
The text was updated successfully, but these errors were encountered:
dingjiayi
changed the title
Plugin(cors):
Plugin(cors):Assertion failure on empty origin header
Mar 11, 2025
Is there an existing issue for this?
Kong version (
$ kong version
)Kong 3.9
Current Behavior
When I create a route with a CORS plugin specifying at least two allowed origins, and then attempt to access the route using curl with
header.Origin
=''
(empty string), receives empty reply from server.Expected Behavior
Not empty reply.
Steps To Reproduce
Route Config:
CORS Plugin:
curl -ivv http://localhost:8000/ -H "Host: echo-test.com" -H "Origin;"
(Theheader.Origin
field is set to an empty string)curl client info:
Kong server error log:
Anything else?
The assertion failure at
kong/kong/plugins/cors/handler.lua
Line 34 in 6b9d32b
Proposed Fix
We should add a check for empty origin values at:
kong/kong/plugins/cors/handler.lua
Line 194 in 6b9d32b
kong/kong/plugins/cors/handler.lua
Line 250 in 6b9d32b
By adding a condition
req_origin ~= ""
before processing the origin value, we can prevent empty strings from reaching the assertion check while maintaining valid CORS behavior.If acceptable, I'd be happy to submit a PR to implement this fix.
The text was updated successfully, but these errors were encountered: