Skip to content

Commit befbccc

Browse files
committed
Add a warning about security (CVE-2023-6551)
1 parent ea5515f commit befbccc

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ echo $handle->process();
168168
die();
169169
```
170170

171+
### Warning about security
172+
173+
By default, the class relies on MIME type detection to assess whether the file can be uploaded or not. Several MIME type detection methods are used, depending on the server configuration. The class relies on a blacklist of dangerous file extensions to prevent uploads (or to rename dangerous scripts as text files), as well as a whitelist of accepted MIME types.
174+
175+
But it is not the purpose of this class to do in-depth checking and heuristics to attempt to detect maliciously crafted files. For instance, an attacker can craft a file that will have the correct MIME type, but will carry a malicious payload, such as a valid GIF file which would contain some code leading to a XSS vulnerability. If this GIF file has a .html extension, it may be uploaded (depending on the class's settings) and display an XSS vulnerability.
176+
177+
However, you can mitigate this by restricting the kind of files that can be uploaded, using `allowed` and `forbidden`, to whitelist and blacklist files depending on their MIME type or extension. *The most secure option would be to only whitelist extensions that you want to allow through, and then making sure that your server always serves the file with the content-type based on the file extension.*
178+
179+
For instance, if you only want to allow one type of file, you could whitelist only its file extension. In the following example, only .html files are let through, and are not converted to a text file:
180+
```php
181+
$handle->allowed = array('html');
182+
$handle->forbidden = array();
183+
$handle->no_script = false;
184+
```
185+
186+
In the end, it is your responsibility to make sure the correct files are uploaded. But more importantly, it is your responsibility to serve the uploaded files correctly, for instance by forcing the server to always provide the content-type based on the file extension.
187+
171188

172189
### Troubleshooting
173190

src/class.upload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,8 @@ function init() {
18921892
'bat',
18931893
'phar',
18941894
'wsdl',
1895+
'html',
1896+
'htm',
18951897
);
18961898

18971899
$this->forbidden = array_merge($this->dangerous, array(
@@ -2118,7 +2120,7 @@ function __construct($file, $lang = 'en_GB') {
21182120
*/
21192121
function upload($file, $lang = 'en_GB') {
21202122

2121-
$this->version = '17/11/2023';
2123+
$this->version = '07/12/2023';
21222124

21232125
$this->file_src_name = '';
21242126
$this->file_src_name_body = '';

0 commit comments

Comments
 (0)