Skip to content

Commit 3b04a5e

Browse files
Merge branch '6.4' into 7.4
* 6.4: [Runtime] Fix CVE-2024-50340 patch bypass by gating argv on $_SERVER['QUERY_STRING']
2 parents 287771d + 0cd0d2f commit 3b04a5e

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Generator/UrlGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function doGenerate(array $variables, array $defaults, array $requirem
174174

175175
if (!$optional || $important || !\array_key_exists($varName, $defaults) || (null !== $mergedParams[$varName] && (string) $mergedParams[$varName] !== (string) $defaults[$varName])) {
176176
// check requirement (while ignoring look-around patterns)
177-
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]] ?? '')) {
177+
if (null !== $this->strictRequirements && !preg_match('#^(?:'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).')$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]] ?? '')) {
178178
if ($this->strictRequirements) {
179179
throw new InvalidParameterException(strtr($message, ['{parameter}' => $varName, '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$varName]]));
180180
}
@@ -227,7 +227,7 @@ protected function doGenerate(array $variables, array $defaults, array $requirem
227227
foreach ($hostTokens as $token) {
228228
if ('variable' === $token[0]) {
229229
// check requirement (while ignoring look-around patterns)
230-
if (null !== $this->strictRequirements && !preg_match('#^'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).'$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
230+
if (null !== $this->strictRequirements && !preg_match('#^(?:'.preg_replace('/\(\?(?:=|<=|!|<!)((?:[^()\\\\]+|\\\\.|\((?1)\))*)\)/', '', $token[2]).')$#i'.(empty($token[4]) ? '' : 'u'), $mergedParams[$token[3]])) {
231231
if ($this->strictRequirements) {
232232
throw new InvalidParameterException(strtr($message, ['{parameter}' => $token[3], '{route}' => $name, '{expected}' => $token[2], '{given}' => $mergedParams[$token[3]]]));
233233
}

Tests/Generator/UrlGeneratorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ public function testGenerateForRouteWithInvalidParameter()
367367
$this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);
368368
}
369369

370+
public function testGenerateForRouteWithAlternationRequirementRejectsSubstringMatch()
371+
{
372+
$routes = $this->getRoutes('test', new Route('/{_locale}/blog', [], ['_locale' => 'en|fr|vi|de']));
373+
374+
$this->expectException(InvalidParameterException::class);
375+
$this->getGenerator($routes)->generate('test', ['_locale' => '/evil.com']);
376+
}
377+
370378
public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
371379
{
372380
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));

0 commit comments

Comments
 (0)