Skip to content

Commit 86a09b3

Browse files
fix(state): guard hex2bin against malformed query parameter keys (#8255)
Co-authored-by: Wietse Warendorff <313525+wietsewarendorff@users.noreply.github.com> Closes #8250
1 parent d5d8176 commit 86a09b3

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/State/Tests/Util/RequestParserTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static function parseRequestParamsProvider(): array
4242

4343
// urlencoded [] (square brackets) in query string.
4444
['a%5B1%5D=%2525', ['a' => ['1' => '%25']]],
45+
46+
['y%5B%C2%9D=', ['79_'."\xC2\x9D" => '']],
47+
['z%5Bg=', ['7a_g' => '']],
4548
];
4649
}
4750
}

src/State/Util/RequestParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ public static function parseRequestParams(string $source): array
5151
// parse_str urldecodes both keys and values in resulting array.
5252
parse_str($source, $params);
5353

54-
return array_combine(array_map('hex2bin', array_keys($params)), $params);
54+
$keys = array_map(
55+
static fn (string $key): string => preg_match('/\A(?:[0-9a-f]{2})+\z/', $key) ? hex2bin($key) : $key,
56+
array_keys($params),
57+
);
58+
59+
return array_combine($keys, $params);
5560
}
5661

5762
/**

0 commit comments

Comments
 (0)