Commit 377dc728 authored by Seamus Lee's avatar Seamus Lee

Resolve security/core#45 by validating the mimeType of the file with the supplied mime-type

parent 04b25912
......@@ -74,6 +74,11 @@ class CRM_Core_Page_File extends CRM_Core_Page {
CRM_Core_Error::statusBounce('Could not retrieve the file');
}
$testMimeType = CRM_Utils_File::getMimeType($path);
if ($testMimeType != $mimeType) {
throw new CRM_Core_Exception("Supplied Mime Type does not match file Mime Type");
}
$buffer = file_get_contents($path);
if (!$buffer) {
CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
......
......@@ -1066,4 +1066,13 @@ HTACCESS;
return FALSE;
}
/**
* Get the Mime-Type of a file based on the url path
* @param string $path full filename path
* @return string|bool
*/
public function getMimeType($path = NULL) {
return mime_content_type($path);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment