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
19 changes: 13 additions & 6 deletions attachments/.htaccess
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
AddHandler cgi-script .php .php2 .php3 .php4 .php5 .php6 .php7 .php8 .php9 .pl .py .js .jsp .asp .htm .html .$

Options -ExecCGI -Indexes

#grant access only if files with specific extensions are uploaded
<FilesMatch "(?i)\.(bmp|csv|doc|docx|heic|html|jpeg|jpg|msg|odg|odt|pages|pdf|png|ppt|pptx|rtf|tiff|wpd|wps|xls|xlsx|xps)$">
Require all granted
</FilesMatch>
# Deny all direct HTTP access to files stored in this directory.
# Attachments must be served through the application (AttachmentsUI) so that authentication and authorization checks are always enforced.

# For Apache 2.4 and later (using mod_authz_core): deny all requests to this directory.
<IfModule mod_authz_core.c>
Require all denied
</IfModule>

# For older Apache versions or when mod_authz_core is not available: use the legacy access control syntax to deny all requests to this directory.
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
21 changes: 21 additions & 0 deletions lib/Attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,27 @@ public function createFromUpload($dataItemType, $dataItemID, $fileField,
return false;
}

/* Restrict uploads to a whitelist of allowed file extensions.
* This is a server-side validation which cannot be bypassed by
* manipulating client-side restrictions.
*/
$allowedExtensions = array(
'bmp', 'csv', 'doc', 'docx', 'heic',
'jpeg', 'jpg', 'msg', 'odg', 'odt',
'pages', 'pdf', 'png', 'ppt', 'pptx',
'rtf', 'tiff', 'wpd', 'wps', 'xls',
'xlsx', 'xps'
);

$extension = FileUtility::getFileExtension($originalFilename);

if (!in_array($extension, $allowedExtensions, true))
{
$this->_isError = true;
$this->_error = 'This file type is not allowed for upload.';
return false;
}

/* This usually indicates an error. */
if ($fileSize <= 0)
{
Expand Down