diff --git a/corbo/views.py b/corbo/views.py index 5e38cb5..ff07bb7 100644 --- a/corbo/views.py +++ b/corbo/views.py @@ -163,7 +163,10 @@ class UnsubscribeView(DeleteView): model = models.Subscription def get_object(self, queryset=None): - data = signing.loads(self.kwargs['unsubscription_token']) + try: + data = signing.loads(self.kwargs['unsubscription_token']) + except signing.BadSignature: + raise Http404 try: return models.Subscription.objects.get(category__pk=data['category'], identifier=data['identifier']) diff --git a/tests/test_broadcasting.py b/tests/test_broadcasting.py index 4b4fa74..5eda09d 100644 --- a/tests/test_broadcasting.py +++ b/tests/test_broadcasting.py @@ -152,6 +152,9 @@ def test_unsubscription_link(app, categories, announces, custom_mailoutbox): 'category': announce.category.pk, 'identifier': destination.identifier} unsubscription_link_sentinel = unsubscription_link + # refuse altered signature + resp = app.get(unsubscription_link + 'altered', status=404) + # make sure the uri schema is not in the page resp = app.get(unsubscription_link) assert scheme not in resp.content