Skip to content

Commit 312126a

Browse files
author
Jon Yurek
committed
v4.0.0
1 parent c132f6c commit 312126a

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

NEWS

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
New in 4.0.0:
2+
3+
* Security: Attachments are checked to make sure they're not pulling a fast one.
4+
* Security: It is now *enforced* that every attachment has a file/mime validation.
5+
* Bug Fix: Removed a call to IOAdapter#close that was causing issues.
6+
* Improvement: Added bullets to the 3.5.3 list of changes. Very important.
7+
* Improcement: Updated the copyright to 2014
8+
19
New in 3.5.3:
210

311
* Improvement: After three long, hard years... we know how to upgrade

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Quick Start
104104
class User < ActiveRecord::Base
105105
attr_accessible :avatar
106106
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
107+
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
107108
end
108109
```
109110

@@ -112,6 +113,7 @@ end
112113
```ruby
113114
class User < ActiveRecord::Base
114115
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
116+
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
115117
end
116118
```
117119

@@ -302,6 +304,38 @@ validates_attachment :avatar,
302304
`Paperclip::ContentTypeDetector` will attempt to match a file's extension to an
303305
inferred content_type, regardless of the actual contents of the file.
304306

307+
Security Validations
308+
====================
309+
310+
NOTE: Starting at version 4.0.0, all attachments are *required* to include a
311+
content_type validation, a file_name validation, or to explicitly state that
312+
they're not going to have either. *Paperclip will raise an error* if you do not
313+
do this.
314+
315+
```ruby
316+
class ActiveRecord::Base
317+
has_attached_file :avatar
318+
# Validate content type
319+
validates_attachment_content_type :avatar, :content_type => /\Aimage/
320+
# Validate filename
321+
validates_attachment_file_name :avatar, :matches => [/png\Z/, /jpe?g\Z/]
322+
# Explicitly do not validate
323+
do_not_validate_attachment_file_type :avatar
324+
end
325+
```
326+
327+
This keeps Paperclip secure-by-default, and will prevent people trying to mess
328+
with your filesystem.
329+
330+
NOTE: Also starting at version 4.0.0, Paperclip has another validation that
331+
cannot be turned off. This validation will prevent content type spoofing. That
332+
is, uploading, say, a PHP document as part of the EXIF tags of a well-formed
333+
JPEG. This check is limited to the media type (the first part of the MIME type,
334+
so, 'text' in 'text/plain'). This will prevent HTML documents from being
335+
uploaded as JPEGs, but will not prevent GIFs from being uploaded with a .jpg
336+
extension. This validation will only add validation errors to the form. It will
337+
not cause Errors to be raised.
338+
305339
Defaults
306340
--------
307341
Global defaults for all your paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash, this can be useful for setting your default storage settings per example so you won't have to define them in every has_attached_file definition.

lib/paperclip/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Paperclip
2-
VERSION = "3.5.3" unless defined? Paperclip::VERSION
2+
VERSION = "4.0.0" unless defined? Paperclip::VERSION
33
end

0 commit comments

Comments
 (0)