Skip to content

Commit

Permalink
views: comments: moderation: Fix unsubscribe with invalid or incomple…
Browse files Browse the repository at this point in the history
…t key
  • Loading branch information
fliiiix committed Feb 27, 2022
1 parent 6379b87 commit ad59386
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions isso/tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,16 @@ def testUnsubscribe(self):
self.assertEqual(rv_unsubscribe_get.status_code, 200)
self.assertIn(b"Successfully unsubscribed", rv_unsubscribe_get.data)

# Incomplete key should fail
key = self.app.sign(['unsubscribe'])
rv_incomplete_key = self.client.get('/id/%d/unsubscribe/%s/%s' % (id_, email, key))
self.assertEqual(rv_incomplete_key.status_code, 403)

# Wrong key type should fail
key = self.app.sign(1)
rv_wrong_key_type = self.client.get('/id/%d/unsubscribe/%s/%s' % (id_, email, key))
self.assertEqual(rv_wrong_key_type.status_code, 403)


class TestPurgeComments(unittest.TestCase):

Expand Down
3 changes: 3 additions & 0 deletions isso/views/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ def unsubscribe(self, environ, request, id, email, key):
except (BadSignature, SignatureExpired):
raise Forbidden

if not isinstance(rv, list) or len(rv) != 2:
raise Forbidden

if rv[0] != 'unsubscribe' or rv[1] != email:
raise Forbidden

Expand Down

0 comments on commit ad59386

Please sign in to comment.