summaryrefslogtreecommitdiff
path: root/Lib/urllib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2011-03-29 12:53:55 -0700
committerGuido van Rossum <guido@python.org>2011-03-29 12:53:55 -0700
commit07ef62c47c14ea80e9fd0923e1693d222df506ff (patch)
tree8958a5f93c705f737f0a0932d8ad2512a7e24aa7 /Lib/urllib.py
parent3c599bdbd1d7fd3436fff47d1338593dff3e58a2 (diff)
parent079381d236f6e62db3a48cbffb14978124d94d14 (diff)
downloadcpython-git-07ef62c47c14ea80e9fd0923e1693d222df506ff.tar.gz
Merge issue 11662 from 2.6.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r--Lib/urllib.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 84e9dbc347..62c08c99d5 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -644,6 +644,18 @@ class FancyURLopener(URLopener):
fp.close()
# In case the server sent a relative URL, join with original:
newurl = basejoin(self.type + ":" + url, newurl)
+
+ # For security reasons we do not allow redirects to protocols
+ # other than HTTP, HTTPS or FTP.
+ newurl_lower = newurl.lower()
+ if not (newurl_lower.startswith('http://') or
+ newurl_lower.startswith('https://') or
+ newurl_lower.startswith('ftp://')):
+ raise IOError('redirect error', errcode,
+ errmsg + " - Redirection to url '%s' is not allowed" %
+ newurl,
+ headers)
+
return self.open(newurl)
def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):