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

fix(files): mitigate issues with special chars in file names #10673

Merged
merged 1 commit into from
Dec 27, 2016

Conversation

mrclay
Copy link
Member

@mrclay mrclay commented Dec 24, 2016

Relative paths to files that contain special characters in the name will now be encoded with base64 to avoid malformatted URLs and HMAC mismatches resulting from unescaped characters. URLs generated prior to this change will continue working.

Refs #10608

@mrclay
Copy link
Member Author

mrclay commented Dec 24, 2016

(tests were failing because base64 was putting "+" in the URL. Base64URL fixes this.)

// Using special characters to test against files that have been
// uploaded prior to implementation of filename sanitization
// See #10608
$file->setFilename("foo'baž.txt");
Copy link
Member Author

Choose a reason for hiding this comment

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

I think filesystem name mapping issues are causing the tests to not find this file, so I'm going to try reading the name from disk.

$file->setFilename('foo');
$dir = dirname($file->getFilenameOnFilestore());
$files = glob("$dir/bing*");
$filename = basename($files[0]);
Copy link
Member Author

Choose a reason for hiding this comment

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

I should just create the file here and clean up after.

Relative paths to files that contain special characters in the name
will now be encoded with base64 to avoid malformatted URLs and
HMAC mismatches resulting from unescaped characters.
URLs generated prior to this change will continue working.

Refs Elgg#10608
@@ -106,6 +108,12 @@ public function getURL() {
return false;
}

if (preg_match('~[^a-zA-Z0-9_\./ ]~', $relative_path)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this because \w may match multibyte chars depending on locale

Copy link
Contributor

Choose a reason for hiding this comment

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

I am sure we will be dealing with some hickups in the future, so as long as we get most of the craziness covered, I can live with it.

@mrclay mrclay merged commit 2ad2509 into Elgg:2.2 Dec 27, 2016
@mrclay mrclay deleted the serve_filename_22 branch December 27, 2016 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants