mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Added safety to URL decoding in is_safe_url() on Python 2
The errors='replace' parameter to force_text altered the URL before checking it, which wasn't considered sane. Refs24fc935218andada7a4aef.
This commit is contained in:
@@ -291,7 +291,10 @@ def is_safe_url(url, host=None):
|
||||
if not url:
|
||||
return False
|
||||
if six.PY2:
|
||||
url = force_text(url, errors='replace')
|
||||
try:
|
||||
url = force_text(url)
|
||||
except UnicodeDecodeError:
|
||||
return False
|
||||
# Chrome treats \ completely as / in paths but it could be part of some
|
||||
# basic auth credentials so we need to check both URLs.
|
||||
return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)
|
||||
|
||||
Reference in New Issue
Block a user