ja...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 973d905

Security fix. Announcement forthcoming.

  • Participants
  • Parent commits bfed23b
  • Branches 0.91-bugfixes

Comments (0)

Files changed (2)

File django/contrib/admin/templates/admin/login.html

 <p class="aligned">
 <label for="id_password">{% trans 'Password:' %}</label> <input type="password" name="password" id="id_password" />
 <input type="hidden" name="this_is_the_login_form" value="1" />
-<input type="hidden" name="post_data" value="{{ post_data }}" />{% comment %} <span class="help">{% trans 'Have you <a href="/password_reset/">forgotten your password</a>?' %}</span>{% endcomment %}
 <div class="aligned ">

File django/contrib/admin/views/

 from django.utils import httpwrappers
 from django.utils.html import escape
 from django.utils.translation import gettext_lazy
-import base64, datetime, md5
-import cPickle as pickle
+import base64, datetime
 ERROR_MESSAGE = gettext_lazy("Please enter a correct username and password. Note that both fields are case-sensitive.")
 LOGIN_FORM_KEY = 'this_is_the_login_form'
 def _display_login_form(request, error_message=''):
-    if request.POST and request.POST.has_key('post_data'):
-        # User has failed login BUT has previously saved post data.
-        post_data = request.POST['post_data']
-    elif request.POST:
-        # User's session must have expired; save their post data.
-        post_data = _encode_post_data(request.POST)
-    else:
-        post_data = _encode_post_data({})
     return render_to_response('admin/login', {
         'title': _('Log in'),
         'app_path': escape(request.path),
-        'post_data': post_data,
         'error_message': error_message
     }, context_instance=DjangoContext(request))
-def _encode_post_data(post_data):
-    pickled = pickle.dumps(post_data)
-    pickled_md5 = + SECRET_KEY).hexdigest()
-    return base64.encodestring(pickled + pickled_md5)
-def _decode_post_data(encoded_data):
-    encoded_data = base64.decodestring(encoded_data)
-    pickled, tamper_check = encoded_data[:-32], encoded_data[-32:]
-    if + SECRET_KEY).hexdigest() != tamper_check:
-        from django.core.exceptions import SuspiciousOperation
-        raise SuspiciousOperation, "User may have tampered with session cookie."
-    return pickle.loads(pickled)
 def staff_member_required(view_func):
     Decorator for views that checks that the user is logged in and is a staff
     def _checklogin(request, *args, **kwargs):
         if not request.user.is_anonymous() and request.user.is_staff:
             # The user is valid. Continue to the admin page.
-            if request.POST.has_key('post_data'):
-                # User must have re-authenticated through a different window
-                # or tab.
-                request.POST = _decode_post_data(request.POST['post_data'])
             return view_func(request, *args, **kwargs)
         assert hasattr(request, 'session'), "The Django admin requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.middleware.sessions.SessionMiddleware'."
         # If this isn't already the login page, display it.
         if not request.POST.has_key(LOGIN_FORM_KEY):
             if request.POST:
-                message = _("Please log in again, because your session has expired. Don't worry: Your submission has been saved.")
+                message = _("Please log in again, because your session has expired.")
                 message = ""
             return _display_login_form(request, message)
                 request.session[users.SESSION_KEY] =
                 user.last_login =
-                if request.POST.has_key('post_data'):
-                    post_data = _decode_post_data(request.POST['post_data'])
-                    if post_data and not post_data.has_key(LOGIN_FORM_KEY):
-                        # overwrite request.POST with the saved post_data, and continue
-                        request.POST = post_data
-                        request.user = user
-                        return view_func(request, *args, **kwargs)
-                    else:
-                        request.session.delete_test_cookie()
-                        return httpwrappers.HttpResponseRedirect(request.path)
+                return httpwrappers.HttpResponseRedirect(request.path)
                 return _display_login_form(request, ERROR_MESSAGE)