-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Restrict URL preparation to HTTP/HTTPS #3713
Conversation
http+unix is used in Docker, Custodia and SSSD, e.g. https://github.com/latchset/custodia/blob/master/custodia/client.py#L60 with URI like |
This looks entirely reasonable to me, thanks @tiran! |
One note though: can we get a test for this? |
if ':' in url and not url.lower().startswith('http'): | ||
# `data`, `http+unix` etc to work around exceptions from `url_parse`, | ||
# which handles RFC 3986 only. | ||
if ':' in url and not url.lower().startswith(('http://', 'https://')): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we have this previously? Can we check the history and see if we can find why we switched to what we have today?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. This is written as it was introduced in #1717, so I'm clearly thinking of something else.
40d7cfa
to
f5b1264
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One little note and then I think we'll be good to go!
) | ||
) | ||
|
||
def test_prepare_http_unix(self, url): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is good, let's just make this a bit more tempting for people to extend in future by changing the name: test_url_passthrough
.
if ':' in url and not url.lower().startswith('http'): | ||
# `data`, `http+unix` etc to work around exceptions from `url_parse`, | ||
# which handles RFC 3986 only. | ||
if ':' in url and not url.lower().startswith(('http://', 'https://')): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the if ':' in url
portion of the conditional now since that's covered in the new startswith
tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it but got a test failure in the test case MissingSchema, 'hiwpefhipowhefopw'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, it's needed: it exists to allow for things that don't look to us like URLs at all but still might be handle-able by something down in the stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, oversight on my part.
Requests treats all URLs starting with the string 'http' as HTTP URLs. Preparation with IDNA breaks non-standard URIs like http+unix. Requests now prepares only URLs with prefix http:// and https://. Signed-off-by: Christian Heimes <[email protected]>
f5b1264
to
34af72c
Compare
Cool, thanks @tiran! All tests pass, so it seems like it's good to go. Thanks so much! ✨ 🍰 ✨ |
Requests treats all URLs starting with the string 'http' as HTTP URLs.
Preparation with IDNA breaks non-standard URIs like http+unix. Requests
now prepares only URLs with prefix http:// and https://.
Signed-off-by: Christian Heimes [email protected]