Skip to content

validators.url hang  #65

Closed
Closed

Description

@librah

When validating the following url, the call gets blocked and CPU spikes to 100%

$ pip freeze | grep validator
validators==0.12.0
$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import validators
>>> validators.url('http://172.20.201.135-10.10.10.1656172.20.11.80-10.10.10.1746172.16.9.13-192.168.17.68610.10.10.226-192.168.17.64610.10.10.226-192.168.17.63610.10.10.226-192.168.17.62610.10.10.226-192.168.17.61610.10.10.226-192.168.17.60610.10.10.226-192.168.17.59610.10.10.226-192.168.17.58610.10.10.226-192.168.17.57610.10.10.226-192.168.17.56610.10.10.226-192.168.17.55610.10.10.226-192.168.17.54610.10.10.226-192.168.17.53610.10.10.226-192.168.17.52610.10.10.226-192.168.17.51610.10.10.195-10.10.10.2610.10.10.194-192.168.17.685172.20.11.52-10.10.10.195510.10.10.226-192.168.17.50510.10.10.186-172.20.11.1510.10.10.165-198.41.0.54192.168.84.1-192.168.17.684192.168.222.1-192.168.17.684172.20.11.52-10.10.10.174410.10.10.232-172.20.201.198410.10.10.228-172.20.201.1983192.168.17.135-10.10.10.1423192.168.17.135-10.10.10.122310.10.10.224-172.20.201.198310.10.10.195-172.20.11.1310.10.10.160-172.20.201.198310.10.10.142-192.168.17.1352192.168.22.207-10.10.10.2242192.168.17.66-10.10.10.1122192.168.17.135-10.10.10.1122192.168.17.129-10.10.10.1122172.20.201.198-10.10.10.2282172.20.201.198-10.10.10.2242172.20.201.1-10.10.10.1652172.20.11.2-10.10.10.1412172.16.8.229-12.162.170.196210.10.10.212-192.168.22.133')

Control+C breaking the execution shows the following stacks:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<decorator-gen-18>", line 2, in url
  File "/Users/librah/virtualenv/w4cs/lib/python2.7/site-packages/validators/utils.py", line 78, in wrapper
    value = func(*args, **kwargs)
  File "/Users/librah/virtualenv/w4cs/lib/python2.7/site-packages/validators/url.py", line 108, in url
    result = pattern.match(value)
KeyboardInterrupt

Activity

  1. kvesteri commented on Sep 26, 2017

    @kvesteri
    Collaborator

    Woah, PRs welcome for this!

  2. librah commented on Sep 29, 2017

    @librah
    Author

    @kvesteri I found it challenging for me to troubleshoot the regex that validating urls. I work around the issue via checking the hostname/ip max length first before using your URL validator.

    from urlparse import urlparse
    
    import validators
    
    def url_validate(url):
        parse_result = urlparse(url)
    
        # max hostname length is 254
        # reference: https://en.wikipedia.org/wiki/Hostname
        if len(parse_result.netloc) >= 255:
            return False
        else:
            return validators.url(url)
  3. m-novikov commented on Oct 17, 2017

    @m-novikov

    It looks like ReDoS case
    Culprit is domain subexpression

  4. vlad43210 commented on Mar 9, 2023

    @vlad43210

    Just found this same issue in 0.20.0. Any idea if this will be fixed / any workarounds?

  5. added
    bugIssue: Works not as designed
    outdatedIssue/PR: Open for more than 3 months
    on Mar 14, 2023
  6. added a commit that references this issue on Mar 17, 2023
    c43826c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue: Works not as designedoutdatedIssue/PR: Open for more than 3 months

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions