From 8fb089716020dab76c50398fe589959625ac1754 Mon Sep 17 00:00:00 2001 From: thomas girod <56346771+imperosol@users.noreply.github.com> Date: Sun, 11 Dec 2022 10:56:02 +0100 Subject: [PATCH] add a sentry capture for when eboutic basket regex validation fails. (#504) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Théo DURR --- .gitignore | 1 + eboutic/forms.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 511f5fbf..c6c093e6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ db.sqlite3 pyrightconfig.json dist/ .vscode/ +.idea/ env/ doc/html data/ diff --git a/eboutic/forms.py b/eboutic/forms.py index 8f1ddaf1..b93ee549 100644 --- a/eboutic/forms.py +++ b/eboutic/forms.py @@ -28,6 +28,7 @@ import typing from django.http import HttpRequest from django.utils.translation import gettext as _ +from sentry_sdk import capture_message from eboutic.models import get_eboutic_products @@ -104,6 +105,13 @@ class BasketForm: # check that the json is not nested before parsing it to make sure # malicious user can't ddos the server with deeply nested json if not BasketForm.json_cookie_re.match(basket): + # As the validation of the cookie goes through a rather boring regex, + # we can regularly have to deal with subtle errors that we hadn't forecasted, + # so we explicitly lay a Sentry message capture here. + capture_message( + "Eboutic basket regex checking failed to validate basket json", + level="error", + ) self.error_messages.add(_("The request was badly formatted.")) return try: