You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CVE-2025-0938] urlparse does not flag hostname *containing* [ or ] as incorrect #105704
#103848 updated the URL parsing algorithm to handle IPv6 and IPvFuture addresses when parsing URLs.
However, the algorithm is incomplete. [ and ] are only permitted in the hostname portion if they are the first and last characters and only if they then contain an IPv6 or IPvFuture address. The current implementation ignores everything before the first [ and everything after the first ] found in the netloc portion.
I think this should return a valid object only if the hostname starts with a [ and ends with ]. With the current logic any string with [ and ] inside the hostname is being considered as a valid IPv6 or IPvFutire hostnames. I believe we must verify the start and end characters of a hostname as mentioned here for IPv6 and optionally IPvFuture.
I'm using django, django-environ and postgres. This issue is quite significant since I, unfortunately, happen to have brackets inside the postgres passwords in several prod/staging servers. This password is given inside a URL to django-environ that parses it (using urllib) then sends it back to django.
As far as Python 3.11.3, everything was going well, but since 3.11.4 it's all broken now.
It is related to what is stated above. urlsplit now spots '[' and ']' inside the netloc and what's inside theses brackets (a fragment of the password) is wrongfully considered a hostname. It then throws an exception since it tries to convert it to an ip address.
The lines that seem to be of importance :
in urllib/parse.py -- urlsplit()
if '[' in netloc and ']' in netloc:
bracketed_host = netloc.partition('[')[2].partition(']')[0]
_check_bracketed_host(bracketed_host)
It feels like an important breaking change/regression that doesn't seem documented
Reacted by LostAquilae, dbachelot, SatreP-M, pschoen-itsc and Taras
I'm using django, django-environ and postgres. This issue is quite significant since I, unfortunately, happen to have brackets inside the postgres passwords in several prod/staging servers. This password is given inside a URL to django-environ that parses it (using urllib) then sends it back to django.
As far as Python 3.11.3, everything was going well, but since 3.11.4 it's all broken now.
It is related to what is stated above. urlsplit now spots '[' and ']' inside the netloc and what's inside theses brackets (a fragment of the password) is wrongfully considered a hostname. It then throws an exception since it tries to convert it to an ip address.
The lines that seem to be of importance : in urllib/parse.py -- urlsplit()
if '[' in netloc and ']' in netloc:
bracketed_host = netloc.partition('[')[2].partition(']')[0]
_check_bracketed_host(bracketed_host)
It feels like an important breaking change/regression that doesn't seem documented
I experienced the same problem. Just to be sure I also checked the URL spec referenced in the code and it states that username and password can be an ASCII string, so this is clearly a bug.
Hi @orsenthil. Are you going to be able to take a look at my PR? If not, in a week or so I can post on Discourse and see if someone else can take a look. Thanks.
changed the title [-]urlparse does not flag hostname *containing* [ or ] as incorrect[/-][+][CVE-2025-0938] urlparse does not flag hostname *containing* [ or ] as incorrect[/+]on Feb 3, 2025
Activity
arhadthedev commentedon Jun 12, 2023
@orsenthil (as an urllib module expert)
csreddy98 commentedon Jun 12, 2023
I think this should return a valid object only if the hostname starts with a
[and ends with]. With the current logic any string with[and]inside the hostname is being considered as a valid IPv6 or IPvFutire hostnames. I believe we must verify the start and end characters of a hostname as mentioned here for IPv6 and optionally IPvFuture.lscottod commentedon Jun 29, 2023
Just to add to this thread,
I'm using django, django-environ and postgres. This issue is quite significant since I, unfortunately, happen to have brackets inside the postgres passwords in several prod/staging servers. This password is given inside a URL to django-environ that parses it (using urllib) then sends it back to django.
As far as Python 3.11.3, everything was going well, but since 3.11.4 it's all broken now.
It is related to what is stated above. urlsplit now spots '[' and ']' inside the netloc and what's inside theses brackets (a fragment of the password) is wrongfully considered a hostname. It then throws an exception since it tries to convert it to an ip address.
The lines that seem to be of importance :
in urllib/parse.py -- urlsplit()
It feels like an important breaking change/regression that doesn't seem documented
pschoen-itsc commentedon Jul 11, 2023
I experienced the same problem. Just to be sure I also checked the URL spec referenced in the code and it states that username and password can be an ASCII string, so this is clearly a bug.
bcail commentedon Oct 23, 2023
@orsenthil Is it OK if I open a PR for this issue for you to look at?
orsenthil commentedon Oct 23, 2023
@bcail , yes please.
pythongh-105704: Disallow IPv6 URLs with invalid prefix/suffix
bcail commentedon Oct 24, 2023
@orsenthil I opened a PR.
bcail commentedon Nov 29, 2023
Hi @orsenthil. Are you going to be able to take a look at my PR? If not, in a week or so I can post on Discourse and see if someone else can take a look. Thanks.
pythongh-105704: Disallow IPv6 URLs with invalid prefix/suffix
pythongh-105704: Disallow IPv6 URLs with invalid prefix/suffix
14 remaining items
[-]urlparse does not flag hostname *containing* [ or ] as incorrect[/-][+][CVE-2025-0938] urlparse does not flag hostname *containing* [ or ] as incorrect[/+]pythongh-105704: Disallow square brackets (`[` and `]`) in domain nam…
[CVE-2025-0938] disallow square brackets (`[` and `]`) in domain name…
Update python39 to version 3.9.21 / rev 71 via SR 1244103
Update python310 to version 3.10.16 / rev 56 via SR 1244096
Update urlmatch tests for Python fixes
[3.11] gh-105704: Disallow square brackets (`[` and `]`) in domain na…
[3.10] gh-105704: Disallow square brackets (`[` and `]`) in domain na…
[3.9] gh-105704: Disallow square brackets (`[` and `]`) in domain nam…
Disable connection URI tests broken by a recent Python fix
Disable connection URI tests broken by a recent Python fix (#1244)
[3.9] pythongh-105704: Disallow square brackets (`[` and `]`) in doma…
Update python39 to version 3.9.22 / rev 73 via SR 1269058
Update urlmatch tests for Python fixes