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

Hotfix for dev/core#747 To fix generation of contact image urls #13663

Merged
merged 5 commits into from
Feb 22, 2019

Conversation

seamuslee001
Copy link
Contributor

Overview

This aims to fix the urls generated for displaying of contact images on the contact summary screen

Before

Image URLs broken

After

Image URLs fixed

ping @eileenmcnaughton @KarinG @totten

@civibot
Copy link

civibot bot commented Feb 22, 2019

(Standard links)

list($path, $mimeType) = CRM_Core_BAO_File::path($fileId, $entityId);
if (!empty($fileName)) {
$mimeType = '';
$path = CRM_Core_Config::singleton()->customFileUploadDir . $fileName;
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs a bit more care to avoid ../ trickery?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@totten this was exactly as it was before see 2762985#diff-b4dd4746dff586ca84ff742ac60afdacL42

Copy link
Member

@totten totten Feb 22, 2019

Choose a reason for hiding this comment

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

Good thing we removed it! 😜

More seriously... i've seen several formulations that effectively prohibit .., although they differ a bit on what files and subfolders are allowed. Examples:

  • Assert that $fileName does not (a) begin with a dot or (b) include any / or any \. (This prohibits all subfolders, parent folders, and dot files -- it only allows regular files stored directly in the data folder.)
  • Assert that $fileName matches basename($fileName). (This also only allows regular files from the regular data folder.)
  • Assert that $fileName matches a stricter affirmative pattern (like "alphanumerics plus one dot plus 3-5 alphanumerics). But we don't have a large organic corpus of examples or a valid formal spec, so it can be hard to make a good stricter pattern.

Note: Take care that Unix systems are consistent about using /, but PHP-Windows can be inconsistent about \ and /, so a more defensive approach is to check both.

Copy link
Member

Choose a reason for hiding this comment

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

@seamuslee001 I pushed up a change with a basename() trick.

$fileId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); // File ID
$fileName = CRM_Utils_Request::retrieve('filename', 'String', $this, FALSE);
if (empty($fileName) && (empty($entityId) || empty($fileId))) {
CRM_Core_Error::statusBounce("Either FIlename or Entity ID and FIle Id need to be passed in to retrieve files");
Copy link
Member

Choose a reason for hiding this comment

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

There are some typos ("FIle" / "File"). Maybe: Must pass either "Filename" or the combination of "Entity ID" + "File ID" ?

$cases[] = ['.helloworld', FALSE];
$cases[] = ['smartwatch_1736683_1280_9af3657015e8660cc234eb1601da871.jpg', TRUE];
return $cases;
}
Copy link
Member

Choose a reason for hiding this comment

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

Oooh, dataProvider-based unit test! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

now now @totten you aren't the ONLY one who writes those...

@totten
Copy link
Member

totten commented Feb 22, 2019

I've done some r-run to check activity attachments and security (with some weird filenames)... latest revision seems good on those fronts.

@eileenmcnaughton
Copy link
Contributor

merge on pass to reflect @totten comments & chat discussion

@seamuslee001 seamuslee001 changed the title Hotfix for dev/core#747 To fix generation of contact imimage urls Hotfix for dev/core#747 To fix generation of contact image urls Feb 22, 2019
@seamuslee001
Copy link
Contributor Author

unrelated fails merging

@seamuslee001 seamuslee001 merged commit f770b11 into civicrm:5.11 Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants