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

Commit

Permalink
Merge pull request #462 from kanarip/dev/directory-traversal
Browse files Browse the repository at this point in the history
Fix directory traversal issue
  • Loading branch information
Arkanius authored Jan 21, 2021
2 parents 87aebd3 + 96a93e9 commit 41fe378
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit 41fe378

Please sign in to comment.