-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cors): treat empty Origin header same as missing header #14368
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. Not a blocker but please take a look
@@ -89,7 +89,7 @@ local function configure_origin(conf, header_filter, req_origin) | |||
end | |||
end | |||
|
|||
if req_origin then | |||
if req_origin and req_origin ~= "" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this way it's simpler?
if req_origin and req_origin ~= "" then | |
if req_origin == "" then | |
req_origin = nil | |
end | |
if req_origin then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @StarlightIbuki ,
Thanks a lot for reviewing this PR and for your suggestion!
I agree, your proposed change does make the conditional logic simpler and the code cleaner. That's a good direction.
One minor point I noticed is that this approach would convert an empty string req_origin
(""
) into nil
. While this doesn't have a functional impact on the current plugin's behavior, it does lead to a subtle loss of information by removing the distinction between an explicitly empty origin and a non-existent one (nil
).
Inspired by your comment aiming for simplification, what do you think about encapsulating this check into a small helper function instead? This way, we can keep the main logic clean while preserving the original values.
Something like this:
local function is_valid_origin(origin)
return origin and origin ~= ""
end
We could then use if is_valid_origin(req_origin) then ...
in the configure_origin function.
Let me know your thoughts! Thanks again for the feedback.
Summary
This change ensures that an empty Origin header (
Origin: ""
) is treatedthe same way as a missing Origin header, fixing inconsistent behavior
between these two cases.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix #14352