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

No uri adapters#2435

Merged
mike-burns merged 1 commit into
masterfrom
jy-no-uri-adapters
Jan 23, 2018
Merged

No uri adapters#2435
mike-burns merged 1 commit into
masterfrom
jy-no-uri-adapters

Conversation

@jyurek

@jyurek jyurek commented Apr 21, 2017

Copy link
Copy Markdown

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.


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

Copy link
Copy Markdown

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 ==.

end

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(...) interpreted as grouped expression.

end
end

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

Copy link
Copy Markdown

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.


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

Copy link
Copy Markdown

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 ==.

end

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

Copy link
Copy Markdown

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
Copy Markdown

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 (".").

end
end

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

Copy link
Copy Markdown

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.

@mike-burns mike-burns left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread features/support/env.rb
World(RSpec::Matchers)

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice.

@gabebw gabebw left a comment

Copy link
Copy Markdown

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.

class DataUriAdapter < StringioAdapter
def self.register
Paperclip.io_adapters.register self do |target|
String === target && target =~ Paperclip::DataUriAdapter::REGEXP

Copy link
Copy Markdown

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?

class HttpUrlProxyAdapter < UriAdapter
def self.register
Paperclip.io_adapters.register self do |target|
String === target && target =~ Paperclip::HttpUrlProxyAdapter::REGEXP

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same here about REGEXP.

end

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

Copy link
Copy Markdown

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 (".").

@mike-burns mike-burns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment thread README.md Outdated
IO Adapters
-----------

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

Copy link
Copy Markdown
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
Copy Markdown
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?

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

```ruby
Paperclip::DataUriAdapter.regsiter

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

register

@reedloden

Copy link
Copy Markdown

This issue has been assigned CVE-2017-0889.

@rongutierrez

rongutierrez commented Nov 17, 2017

Copy link
Copy Markdown

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="([^"]*)"/)

Copy link
Copy Markdown

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]

Comment thread lib/paperclip/io_adapters/registry.rb Outdated
end

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Space between { and | missing.

end
end

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

Copy link
Copy Markdown

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]

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

Copy link
Copy Markdown

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
Copy Markdown

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

@jvanbaarsen

Copy link
Copy Markdown

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

@juanibiapina

juanibiapina commented Jan 30, 2018

Copy link
Copy Markdown

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

Kevinrob commented Feb 1, 2018

Copy link
Copy Markdown

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 😄.

Comment thread README.md

* `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
Copy Markdown

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
Copy Markdown

Choose a reason for hiding this comment

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants