-
Notifications
You must be signed in to change notification settings - Fork 48
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
Restrict file types #370
base: develop
Are you sure you want to change the base?
Restrict file types #370
Conversation
validate_filename(filename) | ||
|
||
|
||
def validate_file(head, filename): |
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.
I am not sure why we do not have one function for validating mime types and extensions?
Pull Request Test Coverage Report for Build 13240989483Details
💛 - Coveralls |
Current approach is (in web security recommended) whitelist. Here's the suggestion:
|
This looks more sensible for me now. |
whitelist: ALLOWED_MIME_TYPES = { |
edbca50
to
67ac1ee
Compare
def is_supported_extension(filepath) -> bool: | ||
"""Check whether file's extension is supported.""" | ||
ext = os.path.splitext(filepath)[1].lower() | ||
return ext and ext not in FORBIDDEN_EXTENSIONS |
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.
Do not we have some input specific file that would not give extension? Just to make sure we do not break something with forbidden files with no ext.
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.
there could be empty extension.
>>> import os
>>> os.path.splitext("Makefile")
('Makefile', '')
Resolves https://github.com/MerginMaps/server-private/issues/2732
Problem:
We allow users to upload any file, even the (potentially) malicious ones 🏴☠️
See tickets for more details and the Pentest report
Solution:
We are more confident with using blacklists. 🛡️
Validate extension during project push - aka
push_start
. Abort the upload if it includes files with blacklisted extensions.Do not rely solely on the extension check. Determine the file type from its header and block blacklisted types - once we have the file on our filesystem (in
push_finish
).Zipping the unsupported makes it possible to upload it.
E.g. block
.exe
Extension renaming of the unsupported file doesn't help ⛔
Potential whitelists are in the comment
Do not allow to sync files with extensions unless whitelistedWhitelist approach is suggested in this PR as it is considered to be safer. However, using blacklists is also a way, see this comment for suggested blacklists.