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

Host value does not get escaped correctly #71

Closed
nvie opened this issue Apr 28, 2016 · 2 comments
Closed

Host value does not get escaped correctly #71

nvie opened this issue Apr 28, 2016 · 2 comments

Comments

@nvie
Copy link

nvie commented Apr 28, 2016

The host property can be assigned an evil value that breaks the URL parsing and leads to furl outputting invalid URLs.

Steps to replicate

Values assigned to the host property don't get escaped correctly:

>>> u = furl('https://user:pass@myhost.com/path/goes/here')
>>> u.host = 'evil:hahaha@haxx0r.com'
>>> str(u)
'https://user:pass@evil:hahaha@haxx0r.com/path/goes/here'

Trying to parse this value with furl again leads to an error now:

>>> furl(str(u))
...
ValueError: Invalid port: 'hahaha@haxx0r.com'
Expected result

Either escape the value for the host property, or throw an error if this is impossible (i.e. even escaped chars are not allowed).

Actual result

A URL that's broken and ends up not being a valid URL.

@gruns
Copy link
Owner

gruns commented May 19, 2016

Awesome find.

Fixed in furl v0.4.95, where a ValueError is raised if the host is egregiously
invalid.

>>> import furl
>>> furl.__version__
'0.4.95'
>>> from furl import furl
>>> f = furl('https://user:pass@myhost.com/path/goes/here')
>>> f.host = 'evil:hahaha@haxx0r.com'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/furl/furl.py", line 1291, in __setattr__
    object.__setattr__(self, attr, value)
  File "/usr/local/lib/python2.7/dist-packages/furl/furl.py", line 930, in host
    raise ValueError(errmsg % host)
ValueError: Invalid host 'evil:hahaha@haxx0r.com'. Host strings must only contain [\.\-a-zA-Z0-9] and can't have adjacent periods.

Upgrade with pip install furl -U.

Thank you for the thorough, detailed Issue and bringing this bug to my
attention, Vincent. Don't hesitate to let me know if there's anything else I can
do for you.

@gruns gruns closed this as completed May 19, 2016
@nvie
Copy link
Author

nvie commented May 19, 2016

Thanks for the fix!

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

No branches or pull requests

2 participants