Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions Tests/InputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,30 @@ public static function casesGeneric(): array
'C:\Documents\Newsletters\tmp',
'From generic cases',
],
'path with parent traversal segment' => [
'path',
'uploads/../config.php',
'',
'From generic cases',
],
'path with leading parent traversal' => [
'path',
'../secret',
'',
'From generic cases',
],
'path with trailing parent traversal' => [
'path',
'uploads/..',
'',
'From generic cases',
],
'filename containing dots is kept' => [
'path',
'archive/backup..2018/file.txt',
'archive/backup..2018/file.txt',
'From generic cases',
],
'user_01' => [
'username',
'&<f>r%e\'d',
Expand Down
6 changes: 6 additions & 0 deletions src/InputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,12 @@ private function cleanHtml($source)
*/
private function cleanPath($source)
{
// Reject any parent-directory (`..`) segment. The patterns below otherwise let a
// single `..` through on Linux-style paths (e.g. images/../config.php).
if (preg_match('#(?:^|[\\\\/])\.\.(?:[\\\\/]|$)#', $source)) {
return '';
}

$linuxPattern = '/^[A-Za-z0-9_\/-]+[A-Za-z0-9_\.-]*([\\\\\/]+[A-Za-z0-9_-]+[A-Za-z0-9_\.-]*)*$/';

if (preg_match($linuxPattern, $source)) {
Expand Down
Loading