Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #22638 -- Changed CookieWizardView to ignore invalid cookies #2673

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions django/contrib/formtools/exceptions.py

This file was deleted.

3 changes: 1 addition & 2 deletions django/contrib/formtools/tests/wizard/test_cookiestorage.py
@@ -1,6 +1,5 @@
from django.test import TestCase
from django.core import signing
from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponse

from django.contrib.auth.tests.utils import skipIfCustomUser
Expand All @@ -25,7 +24,7 @@ def test_manipulated_cookie(self):
self.assertEqual(storage.load_data(), {'key1': 'value1'})

storage.request.COOKIES[storage.prefix] = 'i_am_manipulated'
self.assertRaises(SuspiciousOperation, storage.load_data)
self.assertIsNone(storage.load_data())

def test_reset_cookie(self):
request = get_request()
Expand Down
10 changes: 1 addition & 9 deletions django/contrib/formtools/wizard/storage/cookie.py
@@ -1,8 +1,5 @@
import json

from django.core.signing import BadSignature

from django.contrib.formtools.exceptions import WizardViewCookieModified
from django.contrib.formtools.wizard import storage


Expand All @@ -16,12 +13,7 @@ def __init__(self, *args, **kwargs):
self.init_data()

def load_data(self):
try:
data = self.request.get_signed_cookie(self.prefix)
except KeyError:
data = None
except BadSignature:
raise WizardViewCookieModified('WizardView cookie manipulated')
data = self.request.get_signed_cookie(self.prefix, default=None)
if data is None:
return None
return json.loads(data, cls=json.JSONDecoder)
Expand Down
8 changes: 7 additions & 1 deletion docs/releases/1.8.txt
Expand Up @@ -41,7 +41,13 @@ Minor features
:mod:`django.contrib.formtools`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* ...
* A :doc:`form wizard </ref/contrib/formtools/form-wizard>` using the
:class:`~django.contrib.formtools.wizard.views.CookieWizardView` will now ignore
an invalid cookie, and the wizard will restart from the first step. An invalid
cookie can occur in cases of intentional manipulation, but also after a secret
key change. Previously, this would raise ``WizardViewCookieModified``, a
``SuspiciousOperation``, causing an exception for any user with an invalid cookie
upon every request to the wizard, until the cookie is removed.

:mod:`django.contrib.gis`
^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down