Ticket #14405: patch-14405.diff

File patch-14405.diff, 2.1 KB (added by Chris Tandiono, 14 years ago)

patch

  • views.py

     
    2626    """Displays the login form and handles the login action."""
    2727
    2828    redirect_to = request.REQUEST.get(redirect_field_name, '')
     29   
     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
    2940
     41    # Okay, security checks complete.
    3042    if request.method == "POST":
    3143        form = authentication_form(data=request.POST)
    3244        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
    3645
    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.
     46            # Log the user in.
    4547            auth_login(request, form.get_user())
    4648
    4749            if request.session.test_cookie_worked():
     
    5052            return HttpResponseRedirect(redirect_to)
    5153
    5254    else:
     55        if request.user.is_authenticated(): # they are already logged in
     56             return HttpResponseRedirect(redirect_to)
    5357        form = authentication_form(request)
    5458
    5559    request.session.set_test_cookie()
Back to Top