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

Properly handle query strings on image import to prevent security error #35

Merged
merged 3 commits into from
Aug 16, 2017

Conversation

ethanclevenger91
Copy link
Contributor

If you're trying to import an image with a query string (such as from Placeholder.com using custom copy), WordPress says Sorry, this file type is not permitted for security reasons. because the query string makes it all the way to file name, so the file fails validation.

This PR strips the query string when passing it along, and only does the operation if the file is remote.

@danielbachhuber
Copy link
Member

Thanks for the pull request @ethanclevenger91.

This PR strips the query string when passing it along, and only does the operation if the file is remote.

I don't think this is quite the right approach. These two images are technically different images:

The correct approach would be to use the full URL with query strings. Is this possible?

@ethanclevenger91
Copy link
Contributor Author

@danielbachhuber So the file that is ultimately copied is pulled with the query string intact, but yeah, if you ran both of those, they would have the same name in the WP media library (well, with -1 attached).

You could move the query string to before the file extension? Even if you could work around the validation, I worry having a query string at the end of the filename WordPress is importing may cause problems elsewhere (though nothing jumps to mind).

@danielbachhuber
Copy link
Member

So the file that is ultimately copied is pulled with the query string intact, but yeah, if you ran both of those, they would have the same name in the WP media library (well, with -1 attached).

Oh. The query string remains intact, and the image is imported at two different resolutions?

@ethanclevenger91
Copy link
Contributor Author

Exactly. So if I hit Placeholder.com for two images and pull, for example:

http://via.placeholder.com/350x150.jpg?text=Foo
http://via.placeholder.com/350x150.jpg?text=Bar

My media library gets two different images, one that says "Foo" and one that says "Bar". Their names reflected in the library, however, are:

350x150.jpg
350x150-1.jpg

@danielbachhuber
Copy link
Member

@ethanclevenger91 Makes sense. This pull request is fine then.

Can you add some tests, please? We can use the placeholder service you mentioned for sample data.

Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Needs tests reflecting the changes.

@ethanclevenger91
Copy link
Contributor Author

ethanclevenger91 commented Aug 14, 2017 via email

@ethanclevenger91
Copy link
Contributor Author

Wait, where are existing tests?

@schlessera
Copy link
Member

@danielbachhuber danielbachhuber added this to the 1.0.5 milestone Aug 15, 2017
@danielbachhuber
Copy link
Member

Thanks for your work on this @ethanclevenger91 !

@danielbachhuber danielbachhuber merged commit 3b3b817 into wp-cli:master Aug 16, 2017
@ethanclevenger91 ethanclevenger91 deleted the handle-query-string branch August 16, 2017 17:29
@danielbachhuber danielbachhuber changed the title Handle query strings on URL import. Properly handle query strings on image import to prevent security error Oct 1, 2017
danielbachhuber added a commit that referenced this pull request Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants