-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for malicious uploads (#429)
* chore: add tests for malicious uploads * Apply fixes from StyleCI * chore: remove debug code * test zip/apk, include additional polyglot * Apply fixes from StyleCI * refine tests further * Apply fixes from StyleCI * chore: add migration to update previous insecure image regex * Apply fixes from StyleCI * chore: update README --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
- Loading branch information
1 parent
85264fa
commit f456fc6
Showing
18 changed files
with
436 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
migrations/2025_02_06_000000_alter_default_image_mime_expression.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/upload. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* Copyright (c) Flagrow. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Builder; | ||
|
||
return [ | ||
'up' => function (Builder $schema) { | ||
$db = $schema->getConnection(); | ||
|
||
$oldRegex = '^image\/.*'; | ||
$newRegex = '^image\/(jpeg|png|gif|webp|avif|bmp|tiff|svg\+xml)$'; | ||
|
||
$setting = $db->table('settings')->where('key', 'fof-upload.mimeTypes')->first(); | ||
|
||
if ($setting && isset($setting->value)) { | ||
$decodedValue = json_decode($setting->value, true); | ||
|
||
if (is_array($decodedValue)) { | ||
$updatedValue = []; | ||
|
||
foreach ($decodedValue as $mime => $config) { | ||
if ($mime === $oldRegex) { | ||
// Replace the old regex with the new one | ||
$updatedValue[$newRegex] = $config; | ||
} else { | ||
// Preserve all other settings | ||
$updatedValue[$mime] = $config; | ||
} | ||
} | ||
|
||
$jsonUpdated = json_encode($updatedValue, JSON_UNESCAPED_SLASHES); | ||
|
||
if ($jsonUpdated !== $setting->value) { | ||
$db->table('settings')->where('key', 'fof-upload.mimeTypes')->update(['value' => $jsonUpdated]); | ||
} | ||
} | ||
} | ||
}, | ||
|
||
'down' => function (Builder $schema) { | ||
$db = $schema->getConnection(); | ||
|
||
$oldRegex = '^image\/(jpeg|png|gif|webp|avif|bmp|tiff|svg\+xml)$'; | ||
$newRegex = '^image\/.*'; | ||
|
||
$setting = $db->table('settings')->where('key', 'fof-upload.mimeTypes')->first(); | ||
|
||
if ($setting && isset($setting->value)) { | ||
$decodedValue = json_decode($setting->value, true); | ||
|
||
if (is_array($decodedValue)) { | ||
$revertedValue = []; | ||
|
||
foreach ($decodedValue as $mime => $config) { | ||
if ($mime === $newRegex) { | ||
// Revert back to the old regex | ||
$revertedValue[$oldRegex] = $config; | ||
} else { | ||
// Preserve all other settings | ||
$revertedValue[$mime] = $config; | ||
} | ||
} | ||
|
||
$jsonReverted = json_encode($revertedValue, JSON_UNESCAPED_SLASHES); | ||
|
||
if ($jsonReverted !== $setting->value) { | ||
$db->table('settings')->where('key', 'fof-upload.mimeTypes')->update(['value' => $jsonReverted]); | ||
} | ||
} | ||
} | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Malicious Upload</title> | ||
</head> | ||
<body> | ||
<script>alert("XSS Attack!");</script> | ||
<p>This is a test file.</p> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FLIF<?xml foo="bar"?> | ||
<!DOCTYPE html><html> | ||
<script> | ||
alert("XSS Attack!"); | ||
</script> | ||
<p>Blaklis!</p> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.