-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(core): Regex header values in traditional router are now validated #12365
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.
Could we reuse the code for path validation?
Also I'm wondering - what if someone want's a header to start with ~
but not to be treated as regex? Can it be escaped somehow? I assume for route's paths this is not supported but is it supported for headers?
@nowNick It's not a problem for URL paths given every valid path begins with "/". Regex header inherits that design and we did not consider the issue. There is not a way to escape the "~", so something like "~1" can only be expressed with a trivial regex: "~~1". |
f004449
to
04a01c9
Compare
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.
Good to go! Great job! 🚀
kong/db/schema/typedefs.lua
Outdated
path, err) | ||
|
||
local function validate_regex_or_plain_pattern(pattern) | ||
if pattern:sub(1, 1) ~= "~" 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.
I would personally extract this to yet another function and we could've ended up with code like this:
local function is_plain_patter(pattern)
return pattern:sub(1, 1) ~= "~"
end
local function validate_regex_or_plain_pattern(pattern)
return is_plain_patter(pattern) or is_valid_regex(pattern:sub(2))
end
We could also reuse then is_plain_patter
in the function above so that there'll one less check against "~"
character which imho is a bit magic_stringy
... but that's probably just nitpicking - I'm happy with the code we have right now 😃
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.
+1
changelog/unreleased/kong/traditional_router_header_validation.yml
Outdated
Show resolved
Hide resolved
Does the |
@StarlightIbuki please review the comments above. |
b128c5e
to
4bd3ada
Compare
Pathes have different requirements compared to headers. They need to start with slashes. I've updated the PR to reuse the code as much as possible. |
f991bdd
to
6114933
Compare
6114933
to
219af03
Compare
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.
Merge on CI green
….yml Co-authored-by: Guilherme Salazar <[email protected]>
219af03
to
27f525f
Compare
changelog/unreleased/kong/traditional_router_header_validation.yml
Outdated
Show resolved
Hide resolved
Successfully created cherry-pick PR for |
In my impression, the headers are using |
Fixup #12365 Fix KAG-4788 Co-authored-by: Qi <[email protected]>
Fixup #12365 Fix KAG-4788 Co-authored-by: Qi <[email protected]>
2 condtions: 1. only 1 header value presents 2. it starts with "~*" Fixup #12365 Fix KAG-4788 Co-authored-by: Qi <[email protected]>
2 condtions: 1. only 1 header value presents 2. it starts with "~*" Fixup #12365 Fix KAG-4788 Co-authored-by: Qi <[email protected]>
Summary
ATT
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix FTI-5403