Skip to content

Commit

Permalink
FIX Allow double dots in path when not attempting directory traversal (
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored May 6, 2024
1 parent 44f77ec commit a92baea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Core/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function join(...$parts)
$fullPath = static::normalise(implode(DIRECTORY_SEPARATOR, $parts));

// Protect against directory traversal vulnerability (OTG-AUTHZ-001)
if (strpos($fullPath ?? '', '..') !== false) {
if ($fullPath === '..' || str_ends_with($fullPath, '/..') || str_contains($fullPath, '../')) {
throw new InvalidArgumentException('Can not collapse relative folders');
}

Expand Down
4 changes: 4 additions & 0 deletions tests/php/Core/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function providerTestJoinPaths()
[['\\', '', '/root', '/', ' ', '/', '\\'], '/root'],
// join blocks of paths
[['/root/dir', 'another/path\\to/join'], '/root/dir/another/path/to/join'],
// Double dot is fine if it's not attempting directory traversal
[['/root/my..name/', 'another/path\\to/join'], '/root/my..name/another/path/to/join'],
];

// Rewrite tests for other filesystems (output arg only)
Expand Down Expand Up @@ -79,6 +81,8 @@ public function providerTestJoinPathsErrors()
[['/base', '../passwd'], 'Can not collapse relative folders'],
[['/base/../', 'passwd/path'], 'Can not collapse relative folders'],
[['../', 'passwd/path'], 'Can not collapse relative folders'],
[['..', 'passwd/path'], 'Can not collapse relative folders'],
[['base/..', 'passwd/path'], 'Can not collapse relative folders'],
];
}

Expand Down

0 comments on commit a92baea

Please sign in to comment.