Skip to content
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

Merged
merged 2 commits into from
May 30, 2022
Merged

Conversation

flrgh
Copy link
Contributor

@flrgh flrgh commented May 20, 2022

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 function kong.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).

@flrgh flrgh added this to the 3.0 milestone May 20, 2022
@flrgh flrgh requested a review from a team as a code owner May 20, 2022 01:09
@flrgh flrgh requested review from bungle and dndx May 20, 2022 01:09
Copy link
Contributor

@jschmid1 jschmid1 left a 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.

@flrgh flrgh force-pushed the feat/pdk-get-normalized-path branch from ad537b6 to ce9be8e Compare May 26, 2022 16:33
--
-- kong.request.get_path() -- "/t/Abc 123ø%2F/test/"
function _REQUEST.get_path()
return normalize(_REQUEST.get_raw_path(), true)
Copy link
Contributor

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?

Copy link
Contributor Author

@flrgh flrgh May 27, 2022

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.

Copy link
Member

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.
@flrgh flrgh force-pushed the feat/pdk-get-normalized-path branch from ce9be8e to bf6b15a Compare May 27, 2022 18:43
kong/pdk/request.lua Outdated Show resolved Hide resolved
Co-authored-by: Datong Sun <datong.sun@konghq.com>
Copy link
Member

@dndx dndx left a 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.

@dndx dndx merged commit 9dfffb5 into master May 30, 2022
@dndx dndx deleted the feat/pdk-get-normalized-path branch May 30, 2022 07:39
locao pushed a commit that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants