Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

No uri adapters #2435

Merged
merged 1 commit into from
Jan 23, 2018
Merged

No uri adapters #2435

merged 1 commit into from
Jan 23, 2018

Conversation

jyurek
Copy link

@jyurek jyurek commented Apr 21, 2017

Remove the URI adapters. Few people use them by default and they can allow insight into the internal networks of the server. If you want to enable them, add (for example) Paperclip.DataUriAdapter.register to your config/initializers/paperclip.rb file.

Additional note: this needs to be documented, but comments welcome as to where and how.

@@ -50,7 +55,7 @@ def download_content
end

def copy_to_tempfile(src)
while data = src.read(16*1024)
while data = src.read(16 * 1024)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment in condition - you probably meant to use ==.

@@ -58,6 +59,16 @@
end
end

Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|
cd (".") do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(...) interpreted as grouped expression.

@@ -58,6 +59,16 @@
end
end

Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ambiguous regexp literal. Parenthesize the method arguments if it's surely a regexp literal, or add a whitespace to the right of the / if it should be a division.

@@ -50,7 +55,7 @@ def download_content
end

def copy_to_tempfile(src)
while data = src.read(16*1024)
while data = src.read(16 * 1024)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment in condition - you probably meant to use ==.

@@ -58,6 +59,16 @@
end
end

Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|
cd (".") do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(...) interpreted as grouped expression.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be clearer to write this with no space between cd and (".").

@@ -58,6 +59,16 @@
end
end

Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ambiguous regexp literal. Parenthesize the method arguments if it's surely a regexp literal, or add a whitespace to the right of the / if it should be a division.

Copy link
Contributor

@mike-burns mike-burns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah totally -- I like the direction you took this. In the least I'm glad to have an .unregister method, but the explicit .register method is nice, too.

Also quite happy to have some of the adapters not be the default.

LGTM, but we need to get some docs on this in a future commit.

@@ -7,5 +7,6 @@
World(RSpec::Matchers)

Before do
aruba.config.command_launcher = ENV.fetch("DEBUG", nil) ? :debug : :spawn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Copy link

@gabebw gabebw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small code comments; I don't know enough to offer overarching feedback.

@@ -1,5 +1,10 @@
module Paperclip
class DataUriAdapter < StringioAdapter
def self.register
Paperclip.io_adapters.register self do |target|
String === target && target =~ Paperclip::DataUriAdapter::REGEXP
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be REGEXP, without the class qualifiers, since it's in this class?

@@ -1,15 +1,15 @@
module Paperclip
class HttpUrlProxyAdapter < UriAdapter
def self.register
Paperclip.io_adapters.register self do |target|
String === target && target =~ Paperclip::HttpUrlProxyAdapter::REGEXP
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about REGEXP.

@@ -58,6 +59,16 @@
end
end

Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|
cd (".") do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be clearer to write this with no space between cd and (".").

Copy link
Contributor

@mike-burns mike-burns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

README.md Outdated
IO Adapters
-----------

When a file is uploaded or attached, it an be in one of a few different input
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/can/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's documentation without some typos?

README.md Outdated
adding a line similar to the following into `config/initializers/paperclip.rb`:

```ruby
Paperclip::DataUriAdapter.regsiter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

register

@reedloden
Copy link

This issue has been assigned CVE-2017-0889.

@rongutierrez
Copy link

rongutierrez commented Nov 17, 2017

Any idea when this fix will be released? By making the CVE public you are making this high risk issue public without an available fix for users.

matches = @content.meta["content-disposition"].
match(/filename="([^"]*)"/)
if @content.meta.key?("content-disposition")
matches = @content.meta["content-disposition"].match(/filename="([^"]*)"/)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]

@@ -12,6 +12,10 @@ def register(handler_class, &block)
@registered_handlers << [block, handler_class]
end

def unregister(handler_class)
@registered_handlers.reject! {|_, klass| klass == handler_class }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space between { and | missing.

@@ -49,6 +50,16 @@
end
end

Given /^I comment out lines that contain "([^"]+)" in "([^"]+)"$/ do |contains, glob|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [85/80]

@@ -22,6 +22,7 @@
gem "rubysl", :platform => :rbx
"""
And I remove turbolinks
And I comment out lines that contain "action_mailer" in "config/environments/*.rb"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [86/80]

Remove the URI adapters. Few people use them by default and they can
allow insight into the internal networks of the server. If you want to
enable them, add (for example) `Paperclip.DataUriAdapter.register` to
your `config/initializers/paperclip.rb` file.

This is related to CVE-2017-0889.

Elsewhere fix CI: it's `s3.us-west-2` now, with a dot.
@juanibiapina
Copy link

This breaks API compatibility. Should have been a major bump.

@jvanbaarsen
Copy link

@juanibiapina What exactly does it break? (Can be helpful for other people to determine if they can upgrade or not)

@juanibiapina
Copy link

juanibiapina commented Jan 30, 2018

Now you have to manually enable the handlers, which means you need to make a code change for your application to continue working, otherwise you get Paperclip::AdapterRegistry::NoHandlerError. If you must do a code change, that's a major bump.

That means if you correctly configured bundler to automatically upgrade minor versions, your tests will (hopefully) blow up.

@Kevinrob
Copy link

Kevinrob commented Feb 1, 2018

Like @juanibiapina said, we lost few hours to understand why ours tests failed after upgrading...
A major version would have been nice. At least, a warning in the changelog 😄.


* `Paperclip::UriAdapter` - which accepts a `URI` instance.
* `Paperclip::HttpUrlProxyAdapter` - which accepts a `http` string.
* `Paperclip::DataUriAdapter` - which accepts a Base64-encoded `data:` string.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the risk with DataUriAdapter? How can we use it safely?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants