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

Restrict URL preparation to HTTP/HTTPS #3713

Merged
merged 1 commit into from
Nov 21, 2016

Conversation

tiran
Copy link
Contributor

@tiran tiran commented Nov 21, 2016

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]

@tiran
Copy link
Contributor Author

tiran commented Nov 21, 2016

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 http+unix://%2Fvar%2Frun%2Fcustodia.socket/secrets for HTTP over Unix sockets on socket file /var/run/custodia.socket.

@Lukasa
Copy link
Member

Lukasa commented Nov 21, 2016

This looks entirely reasonable to me, thanks @tiran!

@Lukasa
Copy link
Member

Lukasa commented Nov 21, 2016

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://')):
Copy link
Contributor

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?

Copy link
Contributor

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.

@tiran tiran force-pushed the strict_http_protocol_check branch from 40d7cfa to f5b1264 Compare November 21, 2016 17:24
Copy link
Member

@Lukasa Lukasa left a 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):
Copy link
Member

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://')):
Copy link
Member

@nateprewitt nateprewitt Nov 21, 2016

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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]>
@tiran tiran force-pushed the strict_http_protocol_check branch from f5b1264 to 34af72c Compare November 21, 2016 17:47
@Lukasa
Copy link
Member

Lukasa commented Nov 21, 2016

Cool, thanks @tiran! All tests pass, so it seems like it's good to go. Thanks so much! ✨ 🍰 ✨

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.

4 participants