Skip to content

fix(state): guard hex2bin against invalid hex strings in malformed query parameters#8250

Closed
wietsewarendorff wants to merge 1 commit into
api-platform:mainfrom
wietsewarendorff:main
Closed

fix(state): guard hex2bin against invalid hex strings in malformed query parameters#8250
wietsewarendorff wants to merge 1 commit into
api-platform:mainfrom
wietsewarendorff:main

Conversation

@wietsewarendorff
Copy link
Copy Markdown
Contributor

Summary

When a query string contains unclosed brackets with multibyte characters (e.g., ?y%5B=), parse_str() mangles the parameter name into a non-hex string. The subsequent hex2bin() call then fails with "Hexadecimal input string must have an even length", crashing the request.

Change

This fix validates keys are valid hex (even length, only 0-9a-f) before decoding. Mangled keys from malformed input are preserved as-is, preventing the crash while maintaining all valid parameter handling.

Tests

/src/State/Tests/RequestParser: included a new entry in the dataprovider to assert fix, green

@soyuka
Copy link
Copy Markdown
Member

soyuka commented Jun 5, 2026

Hi @wietsewarendorff — thanks for spotting and reporting this! I've opened #8255 with a slightly different shape (single regex pre-check + extra test for the even-length non-hex branch). You're credited via Co-authored-by on the commit. Feel free to close this one in favor of #8255.

soyuka added a commit to soyuka/core that referenced this pull request Jun 5, 2026
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>
@wietsewarendorff
Copy link
Copy Markdown
Contributor Author

hi @soyuka , thanks for picking this up! Closing this in favor of #8255

soyuka added a commit that referenced this pull request Jun 5, 2026
Co-authored-by: Wietse Warendorff <313525+wietsewarendorff@users.noreply.github.com>
Closes #8250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants