Ticket #14405: patch-14405.3.diff

File patch-14405.3.diff, 1.8 KB (added by Mehdi Bayazee, 14 years ago)
  • views.py

     
    2727
    2828    redirect_to = request.REQUEST.get(redirect_field_name, '')
    2929
     30    # Light security check -- make sure redirect_to isn't garbage.
     31    if not redirect_to or ' ' in redirect_to:
     32        redirect_to = settings.LOGIN_REDIRECT_URL
     33
     34    # Heavier security check -- redirects to http://example.com should
     35    # not be allowed, but things like /view/?param=http://example.com
     36    # should be allowed. This regex checks if there is a '//' *before* a
     37    # question mark.
     38    elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to):
     39            redirect_to = settings.LOGIN_REDIRECT_URL
     40   
     41    # user already logged in
     42    if request.user.is_authenticated():
     43         return HttpResponseRedirect(redirect_to)
     44
    3045    if request.method == "POST":
    3146        form = authentication_form(data=request.POST)
    3247        if form.is_valid():
    33             # Light security check -- make sure redirect_to isn't garbage.
    34             if not redirect_to or ' ' in redirect_to:
    35                 redirect_to = settings.LOGIN_REDIRECT_URL
    36 
    37             # Heavier security check -- redirects to http://example.com should
    38             # not be allowed, but things like /view/?param=http://example.com
    39             # should be allowed. This regex checks if there is a '//' *before* a
    40             # question mark.
    41             elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to):
    42                     redirect_to = settings.LOGIN_REDIRECT_URL
    43 
    44             # Okay, security checks complete. Log the user in.
     48            # Log the user in.
    4549            auth_login(request, form.get_user())
    4650
    4751            if request.session.test_cookie_worked():
Back to Top