Repository navigation
fix: decode percent-encoded static file paths once before lookup - #1107
Open
rootsiemen wants to merge 1 commit into
Open
rootsiemen wants to merge 1 commit into
rootsiemen 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.
Closes #905
Problem
StaticFilesMiddlewareused the raw request path, and WorkermanRequest::path()does not decode percent-encoding. A file likehello world.txtrequested as/hello%20world.txt(or a UTF-8 name likeza%C5%BC%C3%B3%C5%82%C4%87.txt) was looked up with%20in the name, missed, and fell through to Symfony with a 404.Fix
__invoke()now callsrawurldecode()on the path exactly once and passes the decoded path to bothisAllowlistExtensionMismatch()andgetPublicPathFile()(which now takes the path string instead of the request).getPublicPathFile()run on the decoded path, andrealpath()plus the root-prefix check stay as the last guard.%252e%252edecodes once to the literal name%2e%2e, never to...rawurldecode()(noturldecode()) is used so+is not turned into a space.Tests
testPercentEncodedSpaceAndUtf8NamesAreServed:/hello%20world.txtand a percent-encoded UTF-8 name are served with 200. The UTF-8 name is built from its percent-encoded form so the test file stays ASCII-only.testEncodedTraversalAndDoubleEncodingPassToNext(data provider):%2e%2e/,%00,%252e%252eand%5C..%5Cpaths all fall through to$nextinstead of being served.Note: this environment has no PHP runtime, so the PHPUnit suite could not be run here — the change is small, follows the issue's fix idea exactly, and CI's test job is the verification step. Please let me know if CI flags anything.