Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Fix directory traversal issue #462

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Transformers/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,20 @@ public static function handleStatic($swooleRequest, $swooleResponse, string $pub
{
$uri = $swooleRequest->server['request_uri'] ?? '';
$extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?');
$fileName = $publicPath . $uri;
$fileName = @realpath($publicPath . $uri);

if (!$fileName) {
return false;
}

if ($extension && in_array($extension, static::EXTENSION_BLACKLIST)) {
return false;
}

if (substr($fileName, 0, strlen($publicPath)) != $publicPath) {
return false;
}

if (! is_file($fileName) || ! filesize($fileName)) {
return false;
}
Expand Down