Skip to content

Commit 326a74c

Browse files
bug #31654 [HttpFoundation] Do not set X-Accel-Redirect for paths outside of X-Accel-Mapping (vilius-g)
This PR was merged into the 3.4 branch. Discussion ---------- [HttpFoundation] Do not set X-Accel-Redirect for paths outside of X-Accel-Mapping | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | #31604 but refactored for 3.4 Commits ------- a662f61 [HttpFoundation] Do not set X-Accel-Redirect for paths outside of X-Accel-Mapping
2 parents a26c6d3 + a662f61 commit 326a74c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,18 @@ public function prepare(Request $request)
227227

228228
if (substr($path, 0, \strlen($pathPrefix)) === $pathPrefix) {
229229
$path = $location.substr($path, \strlen($pathPrefix));
230+
// Only set X-Accel-Redirect header if a valid URI can be produced
231+
// as nginx does not serve arbitrary file paths.
232+
$this->headers->set($type, $path);
233+
$this->maxlen = 0;
230234
break;
231235
}
232236
}
233237
}
238+
} else {
239+
$this->headers->set($type, $path);
240+
$this->maxlen = 0;
234241
}
235-
$this->headers->set($type, $path);
236-
$this->maxlen = 0;
237242
} elseif ($request->headers->has('Range')) {
238243
// Process the range headers.
239244
if (!$request->headers->has('If-Range') || $this->hasValidIfRangeHeader($request->headers->get('If-Range'))) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ public function getSampleXAccelMappings()
338338
return [
339339
['/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'],
340340
['/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'],
341+
['/tmp/bar.txt', '"/var/www/"="/files/", "/home/Foo/"="/baz/"', null],
341342
];
342343
}
343344

0 commit comments

Comments
 (0)