Skip to content

Commit

Permalink
Prevent open redirect vulnerabilities.
Browse files Browse the repository at this point in the history
Before submitting a SAML2 authentication request, check that the
next URL in the login flow is safe to return to.
  • Loading branch information
qwrrty committed Jan 6, 2017
1 parent e845c38 commit 572375f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions django_saml2_auth/views.py
Expand Up @@ -20,6 +20,7 @@
from django.views.decorators.csrf import csrf_exempt
from django.template import TemplateDoesNotExist
from django.http import HttpResponseRedirect
from django.utils.http import is_safe_url

try:
import urllib2 as _urllib
Expand Down Expand Up @@ -183,6 +184,10 @@ def signin(r):
except:
next_url = r.GET.get('next', get_reverse('admin:index'))

# Only permit signin requests where the next_url is a safe URL
if not is_safe_url(next_url):
return HttpResponseRedirect(get_reverse([denied, 'denied', 'django_saml2_auth:denied']))

r.session['login_next_url'] = next_url

saml_client = _get_saml_client(get_current_domain(r))
Expand Down

0 comments on commit 572375f

Please sign in to comment.