fix(state): guard hex2bin against malformed query parameter keys#8255
Merged
Merged
Conversation
When a query string contains unclosed brackets with multibyte or non-hex bytes (e.g. `?y%5B%C2%9D=`), parse_str() mangles the hex-encoded key into a value hex2bin() cannot decode, triggering an E_WARNING that Symfony's debug error handler converts into a 500. Pre-check the key shape and pass mangled keys through verbatim. Closes api-platform#8250 Co-authored-by: Wietse Warendorff <313525+wietsewarendorff@users.noreply.github.com>
acc1329 to
e468a34
Compare
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.
Summary
Supersedes #8250 (kept author credit via
Co-authored-by).When a query string contains unclosed brackets with multibyte or non-hex bytes (e.g.
?y%5B%C2%9D=),parse_str()mangles the hex-encoded key into a valuehex2bin()cannot decode. PHP emits anE_WARNINGwhich Symfony's debug error handler converts into a 500.Change
Pre-check key shape with a single regex (
/\A(?:[0-9a-f]{2})+\z/) before callinghex2bin(). Mangled keys pass through verbatim — no warning, no crash, no silent empty-key collision.Differences vs #8250:
strlen % 2+strspn(no double\strlencall, no duplicated hex validation)?y%5B%C2%9D=) and the even-length-non-hex (?z%5Bg=) branches independentlyTest plan
vendor/bin/phpunit src/State/Tests/Util/RequestParserTest.php— 6/6 green''(silent empty-key) onmainbefore fixCloses #8250