Skip to content

Commit 0334af4

Browse files
Add content_type_allowlist example to uploader template
Adds a commented example of `content_type_allowlist` (/image\//) to the generated uploader. It mirrors the existing `extension_allowlist` comment and helps users mitigate content-type spoofing attacks.
1 parent 8e5db8c commit 0334af4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/generators/templates/uploader.rb.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
4040
# %w(jpg jpeg gif png)
4141
# end
4242

43+
# Add a content_type_allowlist to restrict uploads by MIME type.
44+
# Without it, a user could upload a harmful file
45+
# with a safe extension (content-type spoofing).
46+
# For the previous extension_allowlist you might use something like this:
47+
# def content_type_allowlist
48+
# /image\//
49+
# end
50+
4351
# Override the filename of the uploaded files:
4452
# Avoid using model.id or version_name here, see uploader/store.rb for details.
4553
# def filename

0 commit comments

Comments
 (0)