Skip to content
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

New validation option to check that file extension matches mime type #195

Open
tagliala opened this issue Jun 27, 2023 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@tagliala
Copy link
Contributor

Hi,

I would like to propose a new validation that checks if the extension matches the actual content type of the document. This should help to prevent upload of a .pdf which is actually a .docx

I don't know a good name for this validation, or if it should be an option of content_type, like match_extension: true

I can work on a PR if you are interested

@igorkasyanchuk
Copy link
Owner

Let's wait a few days for comment's. Could be useful.

@valscion
Copy link

valscion commented Jun 30, 2023

This sounds like content type spoofing validation. Similar to what file_validators has: https://github.com/musaffa/file_validators#security

@Mth0158 Mth0158 added the enhancement New feature or request label Nov 21, 2023
@lavaturtle
Copy link

lavaturtle commented Feb 1, 2024

Adding content type spoofing validation sounds like a good idea to me too. I think kt-paperclip has a feature like this: https://github.com/kreeti/kt-paperclip?tab=readme-ov-file#security-validations

@tagliala
Copy link
Contributor Author

tagliala commented Feb 1, 2024

NOTE: Also starting at version 4.0.0, Paperclip has another validation that cannot be turned off. This validation will prevent content type spoofing. That is, uploading a PHP document (for example) as part of the EXIF tags of a well-formed JPEG. This check is limited to the media type (the first part of the MIME type, so, 'text' in text/plain). This will prevent HTML documents from being uploaded as JPEGs, but will not prevent GIFs from being uploaded with a .jpg extension. This validation will only add validation errors to the form. It will not cause errors to be raised.

this is also interesting

@Mth0158
Copy link
Collaborator

Mth0158 commented Feb 2, 2024

Yes that looks like a really good addition to the gem, I'll work on it in the coming days, let me know if you want to help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants