Skip to content

Commit

Permalink
Restrict URL userinfo to NWG RFC 3986
Browse files Browse the repository at this point in the history
  • Loading branch information
deckar01 committed Feb 22, 2024
1 parent bf33daf commit 3e1366a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/marshmallow/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def _regex_generator(
# this is validated separately against allowed schemes, so in the regex
# we simply want to capture its existence
r"(?:[a-z0-9\.\-\+]*)://",
# basic_auth, for URLs encoding a username:password
# userinfo, for URLs encoding authentication
# e.g. 'ftp://foo:[email protected]/'
r"(?:[^:@]+?(:[^:@]*?)?@|)",
r"(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?",
# netloc, the hostname/domain part of the URL plus the optional port
r"(?:",
"|".join(hostname_variants),
Expand Down
9 changes: 9 additions & 0 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"http://www.example.com:8000/foo",
"http://[email protected]",
"http://user:[email protected]",
"http://:[email protected]",
"http://@example.com",
"http://AZaz09-._~%2A!$&'()*+,;=:@example.com",
],
)
def test_url_absolute_valid(valid_url):
Expand Down Expand Up @@ -58,6 +61,12 @@ def test_url_absolute_valid(valid_url):
" ",
"",
None,
"http://user@[email protected]",
"http://@[email protected]",
"http://@@example.com",
"http://^@example.com",
"http://%[email protected]",
"http://%@example.com",
],
)
def test_url_absolute_invalid(invalid_url):
Expand Down

0 comments on commit 3e1366a

Please sign in to comment.