rewrite: fix wrong index check in trimPathPrefix#7812
Merged
Conversation
Contributor
Author
|
done! |
Member
|
Thanks; however the PR template is missing, can you please restore the assistance disclosure? Also, the CLA still seems to not be signed -- maybe make sure your commits are with an email on your GH account. |
9f38ea4 to
21874f7
Compare
Contributor
Author
|
Restored the disclosure section in the PR body, sorry about dropping it. The CLA failure was down to a typo in my commit email ( |
Member
|
Alright, thank you! |
mholt
approved these changes
Jun 12, 2026
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.
Repro: with
uri strip_prefix /aaaaaa, a request for/%61%61(which decodes to/aa) comes back rewritten to/aainstead of being left untouched./aais not under/aaaaaa, so nothing should be stripped.Cause:
trimPathPrefixwalks the escaped path and the prefix in lock-step, then decides it matched withiPath >= len(prefix).iPathindexes the escaped request path whilelen(prefix)is the prefix length, so a short percent-encoded path whose byte length reacheslen(prefix)exits the loop with the prefix only partly consumed yet still passes that check and is treated as a match.strip_path_suffixreaches the same code through the reversed call.Fix: compare
iPrefixagainstlen(prefix)so a match requires the whole prefix to have been consumed.Assistance Disclosure
I used an LLM to help analyse the loop and sanity-check the repro; I wrote and verified the fix and the regression test locally.