-
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
feat(pdk) normalize kong.request.get_path #8823
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.
A general +1 on the abstraction for the actual path normalization.
ad537b6
to
ce9be8e
Compare
-- | ||
-- kong.request.get_path() -- "/t/Abc 123ø%2F/test/" | ||
function _REQUEST.get_path() | ||
return normalize(_REQUEST.get_raw_path(), true) |
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.
This would change the default behavior of this API, any possibility to add another API like get_normalized_path
?
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.
That was actually the original idea, but after some discussion it was decided that we want get_path()
to be normalized so that it's secure by default when used for string comparison. Sorry I didn't make this more apparent in the description! This reminds me to add a breaking change entry for the changelog though.
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.
It is a security fix, so the change is expected.
This changes the behavior of kong.request.get_path() by performing path normalization on the value before returning it to the caller. The new PDK function kong.request.get_raw_path() performs no normalization.
ce9be8e
to
bf6b15a
Compare
Co-authored-by: Datong Sun <datong.sun@konghq.com>
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.
Eventually it will be nice if we can cache the result of the normalized request URI, but that can happen after the router refactor. Approving for now.
…n roles (`admin` and `workspace-admin`) (#8823)
This changes the behavior of
kong.request.get_path()
such that it performs path normalization on the value before returning it to the caller. The new PDK functionkong.request.get_raw_path()
performs no normalization and contains a notice about its potential security pitfalls when used unwisely.Note: there has been much discussion on the underlying implementation/methodology of our normalization strategy (see #8140). This pull request does not attempt to resolve that discussion and only focuses on the PDK interface. The assumption here is that the implementation of
kong.tools.uri.normalize
can be updated/finalized at a later date if we wish (though some test cases and LuaDoc annotations may need to be updated depending on what changes are made).