Repository navigation
fix(router): forward the matched path when nginx normalizes the request uri - #14035
Open
shreemaan-abhishek wants to merge 1 commit into
Open
shreemaan-abhishek wants to merge 1 commit into
shreemaan-abhishek wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Routes are matched on the normalized
$uri: Nginx percent-decodes the path, resolves dot segments (including encoded ones such as..%2Fand%2e%2e) and merges consecutive slashes. With$upstream_urileft empty,proxy_passthen forwards the original request line. When normalization changed the path, the upstream receives a different path from the one the route was matched on. For example,/admin/..%2Fapi/xmatches a route for/api/*, but the upstream receives/admin/..%2Fapi/x.This PR forwards the path the route was matched on whenever Nginx did more than percent-decode it:
http_access_phase, if a plain percent-decode of the raw request path differs from$uri,$upstream_uriis set to the re-encoded$uriplus the original query string. This reuses the same equivalence check asmatch_uri_encoded_slash.%2Finside path parameters and other encodings are preserved.$upstream_urilater (such asproxy-rewrite) still take precedence.normalize_uri_like_servletis left as is, since it already forwards the normalized path.Behavior change
Upstreams that received raw dot segments or consecutive slashes in the request path (
/a/../b,/a/%2e%2e/b,/a//b) now receive the normalized path (/b,/a/b). Requests without these are unaffected.Which issue(s) this PR fixes:
Fixes #
Checklist