-
Notifications
You must be signed in to change notification settings - Fork 243
FOUR-19429: Unrestricted File Upload: API needs to validate the mimetype #8429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,138 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | File Upload Configuration | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | This file contains configuration options for file uploads including | ||
| | allowed file extensions and MIME types for security validation. | ||
| | | ||
| */ | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Allowed File Extensions | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | List of file extensions that are allowed to be uploaded. | ||
| | Only files with these extensions will be accepted. | ||
| | Archive formats (.zip, .rar, .tar, .7z) are explicitly NOT allowed for security. | ||
| | | ||
| */ | ||
| 'allowed_extensions' => [ | ||
| // Documents | ||
| 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', | ||
| 'txt', 'csv', | ||
|
|
||
| // Images | ||
| 'jpg', 'jpeg', 'png', 'gif', 'svg', | ||
|
|
||
| // Audio | ||
| 'mp3', | ||
|
|
||
| // Video | ||
| 'mp4', | ||
| ], | ||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Extension to MIME Type Mapping | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | An associative array that maps each allowed file extension to one or more | ||
| | corresponding MIME types. This provides a strong validation to ensure that | ||
| | a file's content type (MIME type) matches its declared extension, | ||
| | preventing malicious files (like a script disguised as an image) from being uploaded. | ||
| | | ||
| */ | ||
| 'extension_mime_map' => [ | ||
| // Documents | ||
| 'pdf' => ['application/pdf'], | ||
| 'doc' => ['application/msword'], | ||
| 'docx' => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'], | ||
| 'xls' => ['application/vnd.ms-excel'], | ||
| 'xlsx' => ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], | ||
| 'ppt' => ['application/vnd.ms-powerpoint'], | ||
| 'pptx' => ['application/vnd.openxmlformats-officedocument.presentationml.presentation'], | ||
| 'txt' => ['text/plain'], | ||
| 'csv' => ['text/csv', 'application/csv'], | ||
|
|
||
| // Audio | ||
| 'jpg' => ['image/jpeg'], | ||
| 'jpeg' => ['image/jpeg'], | ||
| 'png' => ['image/png'], | ||
| 'gif' => ['image/gif'], | ||
| 'svg' => ['image/svg+xml'], | ||
|
|
||
| // Audio | ||
| 'mp3' => ['audio/mpeg'], | ||
|
|
||
| // Video | ||
| 'mp4' => ['video/mp4'], | ||
| ], | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Enable MIME Type Validation | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Whether to enable MIME type validation against allowed_mime_types list | ||
| | AND validate that MIME type corresponds to file extension using extension_mime_map. | ||
| | This provides comprehensive validation to prevent malicious files. | ||
| | Recommended to keep this enabled for security. | ||
| | | ||
| */ | ||
| 'enable_mime_validation' => env('ENABLE_MIME_VALIDATION', true), | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Enable Extension Validation | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Whether to enable basic file extension validation against allowed_extensions list. | ||
| | This validates that the file extension is in the allowed list. | ||
| | Recommended to keep this enabled for security. | ||
| | | ||
| */ | ||
| 'enable_extension_validation' => env('ENABLE_EXTENSION_VALIDATION', true), | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Security Dangerous File Extensions | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Archive formats (.zip, .rar, .tar, .7z, .gz, etc.) are explicitly | ||
| | NOT allowed for security reasons. These file types can contain | ||
| | malicious content and are blocked by default. | ||
| | | ||
| */ | ||
| 'dangerous_extensions' => [ | ||
| 'zip', 'rar', '7z', 'tar', 'gz', 'bz2', 'xz', 'lzma', | ||
| 'cab', 'ar', 'iso', 'dmg', 'pkg', 'deb', 'rpm', | ||
| ], | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Security Dangerous MIME Types | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | A list of MIME types associated with archives and executables. | ||
| | This provides an additional layer of security to prevent the upload of | ||
| | compressed files or other potentially dangerous content, even if their | ||
| | file extension has been tampered with. | ||
| | | ||
| */ | ||
| 'dangerous_mime_types' => [ | ||
| 'application/zip', | ||
| 'application/x-rar-compressed', | ||
| 'application/x-7z-compressed', | ||
| 'application/x-tar', | ||
| 'application/gzip', | ||
| 'application/x-bzip2', | ||
| 'application/x-xz', | ||
| 'application/x-lzma', | ||
| 'application/vnd.ms-cab-compressed', | ||
| 'application/x-iso9660-image', | ||
| ], | ||
| ]; |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.