-
Notifications
You must be signed in to change notification settings - Fork 2
Rework mime type white list #2198
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
base: master
Are you sure you want to change the base?
Rework mime type white list #2198
Conversation
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
src/onegov/pas/forms/data_import.py
Outdated
| people_source = UploadMultipleField( | ||
| label=_('People Data (JSON)'), | ||
| description=_('JSON file containing parliamentarian data.'), | ||
| validators=[WhitelistedMimeType(MIME_TYPES_JSON)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But of course json files are allowed if explicitly enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these import files aren't stored we could also just not have the validator here, since it could lead to false positives. There's nothing dangerous about a JSON parser opening these files, whatever they may contain.
|
I saw that files types are handled differently for |
|
Should I completely remove type |
We can make sure to set |
Daverball
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, but there's a couple of details we should iron out.
| 'text/csv', | ||
| 'text/plain', | ||
| }), | ||
| WhitelistedMimeType(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a file we store and could be downloaded by unsuspecting users after the fact, so the whitelist being strict isn't that important. That being said, we could probably trim it a little bit, since all we seem to accept for event imports are .xls and .xlsx files, it might be worth adding application/x-ole-storage though for old Excel files and application/octet-stream is probably fine here as well.
So I would keep the original whitelist, get rid of the bottom three and add application/x-ole-storage.
src/onegov/pas/forms/data_import.py
Outdated
| people_source = UploadMultipleField( | ||
| label=_('People Data (JSON)'), | ||
| description=_('JSON file containing parliamentarian data.'), | ||
| validators=[WhitelistedMimeType(MIME_TYPES_JSON)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these import files aren't stored we could also just not have the validator here, since it could lead to false positives. There's nothing dangerous about a JSON parser opening these files, whatever they may contain.
| action: Literal['keep', 'replace', 'delete'] | ||
| file: IO[bytes] | None | ||
| filename: str | None | ||
| validators = [WhitelistedMimeType()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very robust, we definitely should overwrite __init__ instead, the only remaining question is, whether or not we want to add an extra parameter allowed_mimetypes or if we want to change the default of the validators argument to (WhitelistedMimeType(),).
I kind of like the extra parameter better, since it means we don't need to import WhitelistedMimeType everywhere.
You can then pass it on to super().__init__ as validators=[*(validators or ()), WhitelistedMimeType(allowed_mimetypes)].
|
|
||
| upload_field_class: type[UploadField] = UploadField | ||
| upload_widget: Widget[UploadField] = UploadWidget() | ||
| validators = [WhitelistedMimeType()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here
It's probably fine to remove it for now. There may however be the rare false positive for any files that cannot be identified correctly by libmagic. Generally pdfs, zips and any other binary file formats can end up as |
| 'image/x-pcx', | ||
| 'image/x-portable-pixmap', | ||
| 'image/x-tga' | ||
| 'image/x-xcf', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the resulting list for get_supported_image_mime_types is:
- image/tiff
- image/palm
- image/x-MS-bmp
- image/avif
- image/x-portable-anymap
- image/x-icon
- image/xbm
- image/x-tga
- image/xpm
- image/icns
- image/mpo
- image/bmp
- image/webp
- image/jp2
- image/sgi
- image/vnd.adobe.photoshop
- video/mpeg
- image/jpeg
- image/png
- image/gif
- image/svg+xml
- image/x-pcx
Org: Ensure mime type validator on file upload fields in form code
TYPE: Feature
LINK: ogc-2738