Skip to content

Commit 97bcc4b

Browse files
committed
bpo-14826 bpo-36276: Disallow control chars in http URLs.
Example possible fix for those issues.
1 parent 63b5fc5 commit 97bcc4b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/urllib/request.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ def full_url(self):
350350
def full_url(self, url):
351351
# unwrap('<URL:type://host/path>') --> 'type://host/path'
352352
self._full_url = _unwrap(url)
353+
# Sanity check self._full_url to avoid control characters in HTTP.
354+
# https://bugs.python.org/issue14826
355+
# https://bugs.python.org/issue36276
356+
# The same control characters check was adopted by Golang in:
357+
# https://go-review.googlesource.com/c/go/+/159157
358+
if (self._full_url.startswith('http') and
359+
re.search("[\x00- \x7f-\x9f]", self._full_url)):
360+
raise ValueError("URL can't contain control characters. %r" % (self._full_url,))
353361
self._full_url, self.fragment = _splittag(self._full_url)
354362
self._parse()
355363

0 commit comments

Comments
 (0)