[Django] #29528: Invalid URLs passing validation by URLValidator

76 views
Skip to first unread message

Django

unread,
Jun 26, 2018, 7:21:14 PM6/26/18
to django-...@googlegroups.com
#29528: Invalid URLs passing validation by URLValidator
----------------------------------------+------------------------
Reporter: Tim Bell | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
Since #20003, `core.validators.URLValidator` accepts URLs with usernames
and passwords. RFC 1738 section 3.1 requires "Within the user and password
field, any ":", "@", or "/" must be encoded"; however, those characters
are currently accepted without being %-encoded. That allows certain
invalid URLs to pass validation incorrectly. (The issue originates in
Diego Perini's [https://gist.github.com/dperini/729294 gist], from which
the implementation in #20003 was derived.)

An example URL that should be invalid is `http://foo/b...@example.com`;
furthermore, many of the test cases in `tests/validators/invalid_urls.txt`
would be rendered valid under the current implementation by appending a
query string of the form `?m=f...@example.com` to them.

I note Tim Graham's
[https://code.djangoproject.com/ticket/20003#comment:12 concern] about
adding complexity to the validation regex. However, I take the opposite
position to Danilo Bargen about
[https://code.djangoproject.com/ticket/20003#comment:13 invalid URL edge
cases]: it's not fine if invalid URLs (even so-called "edge cases") are
accepted when the regex could be fixed simply to reject them correctly. I
also note that a URL of the form above was encountered in a production
setting, so that this is a genuine use case, not merely an academic
exercise.

I'll add a pull request to address this issue shortly.

--
Ticket URL: <https://code.djangoproject.com/ticket/29528>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 26, 2018, 7:31:58 PM6/26/18
to django-...@googlegroups.com
#29528: Invalid URLs passing validation by URLValidator
------------------------------+--------------------------------------

Reporter: Tim Bell | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by Tim Bell:

Old description:

> Since #20003, `core.validators.URLValidator` accepts URLs with usernames
> and passwords. RFC 1738 section 3.1 requires "Within the user and
> password field, any ":", "@", or "/" must be encoded"; however, those
> characters are currently accepted without being %-encoded. That allows
> certain invalid URLs to pass validation incorrectly. (The issue
> originates in Diego Perini's [https://gist.github.com/dperini/729294
> gist], from which the implementation in #20003 was derived.)
>
> An example URL that should be invalid is `http://foo/b...@example.com`;
> furthermore, many of the test cases in
> `tests/validators/invalid_urls.txt` would be rendered valid under the
> current implementation by appending a query string of the form
> `?m=f...@example.com` to them.
>
> I note Tim Graham's
> [https://code.djangoproject.com/ticket/20003#comment:12 concern] about
> adding complexity to the validation regex. However, I take the opposite
> position to Danilo Bargen about
> [https://code.djangoproject.com/ticket/20003#comment:13 invalid URL edge
> cases]: it's not fine if invalid URLs (even so-called "edge cases") are
> accepted when the regex could be fixed simply to reject them correctly. I
> also note that a URL of the form above was encountered in a production
> setting, so that this is a genuine use case, not merely an academic
> exercise.
>
> I'll add a pull request to address this issue shortly.

New description:

Since #20003, `core.validators.URLValidator` accepts URLs with usernames
and passwords. RFC 1738 section 3.1 requires "Within the user and password
field, any ":", "@", or "/" must be encoded"; however, those characters
are currently accepted without being %-encoded. That allows certain
invalid URLs to pass validation incorrectly. (The issue originates in
Diego Perini's [https://gist.github.com/dperini/729294 gist], from which
the implementation in #20003 was derived.)

An example URL that should be invalid is `http://foo/b...@example.com`;
furthermore, many of the test cases in `tests/validators/invalid_urls.txt`
would be rendered valid under the current implementation by appending a
query string of the form `?m=f...@example.com` to them.

I note Tim Graham's
[https://code.djangoproject.com/ticket/20003#comment:12 concern] about
adding complexity to the validation regex. However, I take the opposite
position to Danilo Bargen about
[https://code.djangoproject.com/ticket/20003#comment:13 invalid URL edge
cases]: it's not fine if invalid URLs (even so-called "edge cases") are
accepted when the regex could be fixed simply to reject them correctly. I
also note that a URL of the form above was encountered in a production
setting, so that this is a genuine use case, not merely an academic
exercise.

Pull request: https://github.com/django/django/pull/10097

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29528#comment:1>

Django

unread,
Jun 30, 2018, 4:12:51 AM6/30/18
to django-...@googlegroups.com
#29528: Invalid URLs passing validation by URLValidator
------------------------------+------------------------------------

Reporter: Tim Bell | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Claude Paroz):

* stage: Unreviewed => Accepted


Comment:

Looks legitimate to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/29528#comment:2>

Django

unread,
Jul 13, 2018, 7:22:59 PM7/13/18
to django-...@googlegroups.com
#29528: Make URLValidator reject invalid characters in the username and password
------------------------------+------------------------------------

Reporter: Tim Bell | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/29528#comment:3>

Django

unread,
Jul 15, 2018, 7:28:08 AM7/15/18
to django-...@googlegroups.com
#29528: Make URLValidator reject invalid characters in the username and password
------------------------------+------------------------------------
Reporter: Tim Bell | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Herbert Fortes):

* cc: Herbert Fortes (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29528#comment:4>

Django

unread,
Jul 20, 2018, 3:49:10 AM7/20/18
to django-...@googlegroups.com
#29528: Make URLValidator reject invalid characters in the username and password
-------------------------------------+-------------------------------------

Reporter: Tim Bell | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29528#comment:5>

Django

unread,
Jul 23, 2018, 10:30:53 AM7/23/18
to django-...@googlegroups.com
#29528: Make URLValidator reject invalid characters in the username and password
-------------------------------------+-------------------------------------
Reporter: Tim Bell | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"cdcf4164bec9dc09465424d7042c3f9d4f0f1fdc" cdcf416]:
{{{
#!CommitTicketReference repository=""
revision="cdcf4164bec9dc09465424d7042c3f9d4f0f1fdc"
Fixed #29528 -- Made URLValidator reject invalid characters in the
username and password.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29528#comment:6>

Reply all
Reply to author
Forward
0 new messages