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

Fix overly aggressive remote image url escaping in specific instances #2457

Closed
wants to merge 4 commits into from

Conversation

courtsimas
Copy link
Contributor

@courtsimas courtsimas commented Mar 14, 2020

Closes #2456 - which is an issue where in specific instances, when the remote download is trying to parse and escape the remote absolute image url, it can improperly escape some characters that are actually needed in order for the image/download to work - specifically when the image source is actually in the query string, and not in the base portion of the path.

You'll see this type of pattern semi-often; where the image path/source is actually defined in the query parameter in on-the-fly overlays/mashups of images (which imgix supports) and in the way Vimeo's thumbnail images work as well (among others).

The related issue at #2456 has more information and an example.

@@ -40,7 +40,9 @@ def download(url, remote_headers = {})
def process_uri(uri)
uri_parts = uri.split('?')
encoded_uri = Addressable::URI.parse(uri_parts.shift).normalize.to_s
encoded_uri << '?' << Addressable::URI.encode(uri_parts.join('?')).gsub('%5B', '[').gsub('%5D', ']') if uri_parts.any?
encoded_uri << '?' << Addressable::URI.encode(uri_parts.join('?')).
gsub('%5B', '[').gsub('%253A%252F%252F', '%3A%2F%2F').
Copy link
Contributor Author

@courtsimas courtsimas Mar 14, 2020

Choose a reason for hiding this comment

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

This is specifically targeting for the :// portion of the https:// or http:// or some-protocol:// and removing the double escape. This, coupled with the change in the next line, is what fixes the issue.

@coneybeare
Copy link
Contributor

Also related to #2473, but different

@courtsimas
Copy link
Contributor Author

Ping. Anyone using Vimeo or imgix for mashups (overlays) defining the secondary image in a query param can’t use carrierwave in this manner.

mshibuya pushed a commit that referenced this pull request Jan 17, 2021
@mshibuya mshibuya closed this in 3faf749 Jan 17, 2021
@courtsimas
Copy link
Contributor Author

@mshibuya since your commit doesn't actually seem to address the issue my PR addressed (albeit, maybe mine wasn't the best approach, but it worked), what's an easy way of overriding the process_uri method?

@mshibuya
Copy link
Member

What do you mean?
Your test case in this PR was already merged in c3b4cc6, and my commit 3faf749 made it pass.

@courtsimas
Copy link
Contributor Author

Dude I apologize. You’re right. Thanks man.

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

Successfully merging this pull request may close these issues.

remote download improperly escapes query params in specific cases
3 participants