Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow RTLO char in filenames #10030

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ public function verifyPath($path, $fileName) {
}
}

// Do not allow RTLO char
if (mb_strpos($fileName, mb_chr(8238, 'utf8')) !== false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mb_chr is php 7.2+ so we can't use it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new InvalidCharacterInPathException('RTLO not allowed');
}

if (isset($fileName[255])) {
throw new FileNameTooLongException();
}
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/Files/PathVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ public function providesAstralPlane() {
];
}


/**
* @dataProvider providesInvalidUnicode
*/
public function testPathVerificationInvalidUnicode(string $fileName) {
$this->expectException(InvalidPathException::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't you throwing an InvalidCharacterInPathException instance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that it's a specialization but I just wanted to bring it up in case this wasn't intentional 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we are. But it is internal mainly. The point here is that we get that the path is invalid :)

$this->expectExceptionMessage('File name contains at least one invalid character');

$this->view->verifyPath('', $fileName);
}

public function providesInvalidUnicode() {
return [
['foo' . mb_chr(8238, 'utf8') . 'txt.html'], //RTLO
];
}

/**
* @dataProvider providesInvalidCharsPosix
* @expectedException \OCP\Files\InvalidCharacterInPathException
Expand Down