diff --git a/README.md b/README.md index df327179..8e7ddeaa 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,24 @@ php flarum cache:clear Enable the extension, a new tab will appear on the left hand side. This separate settings page allows you to further configure the extension. +On new installations, a pre-defined regex will be inserted for you that enables image uploads, restricted to safe image types. We now include SVG as safe, due to our SVG sanitization method. Default image types allowed are: + +- JPEG +- PNG +- GIF +- WebP +- AVIF +- BMP +- TIFF +- SVG + +The regex for these types is `^image\/(jpeg|png|gif|webp|avif|bmp|tiff|svg\+xml)$`, and can be modified as required. We **STRONGLY** discourage the use of a wildcard such as `^image\/.*`, as this could introduce vulnerabilities in the uploaded files. Versions of `fof/upload` prior to `1.8.0` used this as default, and is considered insecure. + Make sure you configure the upload permission on the permissions page as well. ### Mimetype regular expression -Regular expressions allow you a lot of freedom, but they are also very difficult to understand. Here are some pointers, but feel free to ask -for help on the official Flarum forums. +Regular expressions allow you a lot of freedom, but they are also very difficult to understand. Here are some pointers, but feel free to ask for help on the official Flarum forums, or check out [regex101.com](https://regex101.com/) where you can interactively build and test your regex pattern. In case you want to allow all regular file types including video, music, compressed files and images, use this: @@ -121,6 +133,30 @@ The following (to resume) will happen when this command is put into a recurring - the command will go over all uploads to discover in which posts they have been used - delete those files that have been uploaded "last year" that have not been found in posts +## Testing and Security Measures + +FoF Upload includes **automated tests** to ensure: + +✅ Valid files upload successfully +✅ Restricted files are blocked +✅ SVG sanitization removes potential XSS risks + +### 🔍 Security Tests for Malicious Files +We specifically test against: +- HTML Injection (`.html` disguised as an image) +- MIME Spoofing (e.g., `.png` containing a script) +- Polygot Files (Files that act as two different formats) +- SVG Sanitization (` +

This is a test file.

+ + diff --git a/tests/fixtures/Malicious.svg b/tests/fixtures/Malicious.svg new file mode 100644 index 00000000..79581cfe --- /dev/null +++ b/tests/fixtures/Malicious.svg @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + +

Click me!

+ +
+ + + + + + +
diff --git a/tests/fixtures/Polyglot.flif b/tests/fixtures/Polyglot.flif new file mode 100644 index 00000000..a3839a55 --- /dev/null +++ b/tests/fixtures/Polyglot.flif @@ -0,0 +1,7 @@ +FLIF + + +

Blaklis!

+ diff --git a/tests/fixtures/Polyglot.jpg b/tests/fixtures/Polyglot.jpg new file mode 100644 index 00000000..25707e91 --- /dev/null +++ b/tests/fixtures/Polyglot.jpg @@ -0,0 +1,8 @@ +FFD8FFE000104A46494600010101006000600000FFDB00430008060607060508... + + + + + + + diff --git a/tests/fixtures/Safe.svg b/tests/fixtures/Safe.svg new file mode 100644 index 00000000..b53302ee --- /dev/null +++ b/tests/fixtures/Safe.svg @@ -0,0 +1,3 @@ + + + diff --git a/tests/fixtures/SpoofedMime.png b/tests/fixtures/SpoofedMime.png new file mode 100644 index 00000000..2115ef84 --- /dev/null +++ b/tests/fixtures/SpoofedMime.png @@ -0,0 +1,11 @@ +89504E470D0A1A0A0000000D49484452000000640000006408060000005702F987... + + + + + + + +

This file is not actually a PNG!

+ + diff --git a/tests/fixtures/TextFileWithPngExtension.png b/tests/fixtures/TextFileWithPngExtension.png new file mode 100644 index 00000000..7a8013e1 --- /dev/null +++ b/tests/fixtures/TextFileWithPngExtension.png @@ -0,0 +1 @@ +This is a text file pretending to be an image. diff --git a/tests/integration/api/FileUploadSecurityTest.php b/tests/integration/api/FileUploadSecurityTest.php new file mode 100644 index 00000000..eecd5783 --- /dev/null +++ b/tests/integration/api/FileUploadSecurityTest.php @@ -0,0 +1,140 @@ +extension('fof-upload'); + + $this->prepareDatabase([ + 'users' => [ + $this->normalUser(), + ], + ]); + } + + /** + * @test + * + * We allow SVG due to the built in santization. Here we test that