diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2012-11-17 22:00:53 +0100 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2012-12-10 22:11:39 +0100 |
| commit | a2f2a399566dd68ce7e312fff5a5ba857066797d (patch) | |
| tree | 6c03894150f1f5bdfeb121fd20bc6f4c304aad31 /django/utils/http.py | |
| parent | 0cdfa76e68468ddf0a99198e1db07a703354b5af (diff) | |
Fixed #18856 -- Ensured that redirects can't be poisoned by malicious users.
Diffstat (limited to 'django/utils/http.py')
| -rw-r--r-- | django/utils/http.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index 1c3b0039b5..0ab5198804 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -227,3 +227,15 @@ def same_origin(url1, url2): """ p1, p2 = urllib_parse.urlparse(url1), urllib_parse.urlparse(url2) return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port) + +def is_safe_url(url, host=None): + """ + Return ``True`` if the url is a safe redirection (i.e. it doesn't point to + a different host). + + Always returns ``False`` on an empty url. + """ + if not url: + return False + netloc = urllib_parse.urlparse(url)[1] + return not netloc or netloc == host |
