8000 bug #60292 [HttpFoundation] Encode path in `X-Accel-Redirect` header … · symfony/symfony@ebb9e65 · GitHub
[go: up one dir, main page]

Skip to content

Commit ebb9e65

Browse files
committed
bug #60292 [HttpFoundation] Encode path in X-Accel-Redirect header (Athorcis)
This PR was merged into the 6.4 branch. Discussion ---------- [HttpFoundation] Encode path in `X-Accel-Redirect` header | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT The path in `X-Accel-Redirect` header needs to be encoded otherwise nginx fail when certain characters are present in it (like % or ?) * rack/rack#1306 Commits ------- bcf20bc [HttpFoundation] Fix: Encode path in X-Accel-Redirect header
2 parents a1228e4 + bcf20bc commit ebb9e65

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function prepare(Request $request): static
229229
$path = $location.substr($path, \strlen($pathPrefix));
230230
// Only set X-Accel-Redirect header if a valid URI can be produced
231231
// as nginx does not serve arbitrary file paths.
232-
$this->headers->set($type, $path);
232+
$this->headers->set($type, rawurlencode($path));
233233
$this->maxlen = 0;
234234
break;
235235
}

src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,15 @@ public function testXAccelMapping($realpath, $mapping, $virtual)
314314
$property->setValue($response, $file);
315315

316316
$response->prepare($request);
317-
$this->assertEquals($virtual, $response->headers->get('X-Accel-Redirect'));
317+
$header = $response->headers->get('X-Accel-Redirect');
318+
319+
if ($virtual) {
320+
// Making sure the path doesn't contain characters unsupported by nginx
321+
$this->assertMatchesRegularExpression('/^([^?%]|%[0-9A-F]{2})*$/', $header);
322+
$header = rawurldecode($header);
323+
}
324+
325+
$this->assertEquals($virtual, $header);
318326
}
319327

320328
public function testDeleteFileAfterSend()
@@ -361,6 +369,7 @@ public static function getSampleXAccelMappings()
361369
['/home/Foo/bar.txt', '/var/www/=/files/,/home/Foo/=/baz/', '/baz/bar.txt'],
362370
['/home/Foo/bar.txt', '"/var/www/"="/files/", "/home/Foo/"="/baz/"', '/baz/bar.txt'],
363371
['/tmp/bar.txt', '"/var/www/"="/files/", "/home/Foo/"="/baz/"', null],
372+
['/var/www/var/www/files/foo%.txt', '/var/www/=/files/', '/files/var/www/files/foo%.txt'],
364373
];
365374
}
366375

0 commit comments

Comments
 (0)
0