CVE-2022-21683 (published 2022-01-18T18:15Z)

Wagtail is a Django based content management system focused on flexibility and user experience. When notifications for new replies in comment threads are sent, they are sent to all users who have replied or commented anywhere on the site, rather than only in the relevant threads. This means that a user could listen in to new comment replies on pages they have not have editing access to, as long as they have left a comment or reply somewhere on the site. A patched version has been released as Wagtail 2.15.2, which restores the intended behaviour - to send notifications for new replies to the participants in the active thread only (editing permissions are not considered). New comments can be disabled by setting `WAGTAILADMIN_COMMENTS_ENABLED = False` in the Django settings file.

Severity: MEDIUM
CVSS v2 base score: 4.0 (AV:N/AC:L/Au:S/C:P/I:N/A:N)
CVSS v3 base score: 4.3, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N)

Weakness information:
cwe_id: CWE-200
cwe_name: Exposure of Sensitive Information to an Unauthorized Actor
description: The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
extended_description: 
	   There are many different kinds of mistakes that introduce information exposures. The severity of the error can range widely, depending on the context in which the product operates, the type of sensitive information that is revealed, and the benefits it may provide to an attacker.  Some kinds of sensitive information include:
       
         private, personal information, such as personal messages, financial data, health records, geographic location, or contact details
         system status and environment, such as the operating system and installed packages
		 business secrets and intellectual property
		 network status and configuration
		 the product's own code or internal state
         metadata, e.g. logging of connections or message headers
		 indirect information, such as a discrepancy between two internal operations that can be observed by an outsider
       
	    Information might be sensitive to different parties, each of which may have their own expectations for whether the information should be protected.  These parties include:
               
                  the product's own users
                  people or organizations whose information is created or used by the product, even if they are not direct product users
		  the product's administrators, including the admins of the system(s) and/or networks on which the product operates
                  the developer
               
	    Information exposures can occur in different ways:
               
                  the code explicitly inserts sensitive information into resources or messages that are intentionally made accessible to unauthorized actors, but should not contain the information - i.e., the information should have been "scrubbed" or "sanitized"
                  a different weakness or mistake indirectly inserts the sensitive information into resources, such as a web script error revealing the full system path of the program.
                  the code manages resources that intentionally contain sensitive information, but the resources are unintentionally made accessible to unauthorized actors. In this case, the information exposure is resultant - i.e., a different weakness enabled the access to the information in the first place.
               
	    It is common practice to describe any loss of confidentiality as an "information exposure," but this can lead to overuse of CWE-200 in CWE mapping. From the CWE perspective, loss of confidentiality is a technical impact that can arise from dozens of different weaknesses, such as insecure file permissions or out-of-bounds read.  CWE-200 and its lower-level descendants are intended to cover the mistakes that occur in behaviors that explicitly manage, store, transfer, or cleanse sensitive information.
         
         

Fix information:
repo_url: https://github.com/wagtail/wagtail
commit_details: repo_url: https://github.com/wagtail/wagtail
author: jacobtoppm
author_date: 2021-12-09 14:20:53+00:00
msg: Fix commenting thread notifications being sent to non-thread users
repository: repo_url: https://github.com/wagtail/wagtail
repo_name: wagtail/wagtail
description: A Django content management system focused on flexibility and user experience
repo_language: Python
owner: wagtail
file_changes: filename: test_edit_page.py
change_type: ModificationType.MODIFY
diff: @@ -2100,6 +2100,7 @@ class TestCommenting(TestCase, WagtailTestUtils):
         self.subscriber = self.create_user('subscriber')
         self.non_subscriber = self.create_user('non-subscriber')
         self.non_subscriber_2 = self.create_user('non-subscriber-2')
+        self.never_emailed_user = self.create_user('never-emailed')
 
         PageSubscription.objects.create(
             page=self.child_page,
@@ -2113,6 +2114,23 @@ class TestCommenting(TestCase, WagtailTestUtils):
             comment_notifications=True
         )
 
+        # Add comment and reply on a different page for the never_emailed_user
+        # They should never be notified
+        comment_on_other_page = Comment.objects.create(
+            page=self.root_page,
+            user=self.never_emailed_user,
+            text='a comment'
+        )
+
+        CommentReply.objects.create(
+            user=self.never_emailed_user,
+            comment=comment_on_other_page,
+            text='a reply'
+        )
+
+    def assertNeverEmailedWrongUser(self):
+        self.assertNotIn(self.never_emailed_user.email, [to for email in mail.outbox for to in email.to])
+
     def test_new_comment(self):
         post_data = {
             'title': "I've been edited!",
@@ -2144,6 +2162,7 @@ class TestCommenting(TestCase, WagtailTestUtils):
 
         # Check notification email
         self.assertEqual(len(mail.outbox), 1)
+        self.assertNeverEmailedWrongUser()
         self.assertEqual(mail.outbox[0].to, [self.subscriber.email])
         self.assertEqual(mail.outbox[0].subject, 'test@email.com has updated comments on "I\'ve been edited! (simple page)"')
         self.assertIn('New comments:\n - "A test comment"\n\n', mail.outbox[0].body)
@@ -2283,6 +2302,7 @@ class TestCommenting(TestCase, WagtailTestUtils):
 
         # Check notification email
         self.assertEqual(len(mail.outbox), 2)
+        self.assertNeverEmailedWrongUser()
         # The non subscriber created the comment, so should also get an email
         self.assertEqual(mail.outbox[0].to, [self.non_subscriber.email])
         self.assertEqual(mail.outbox[0].subject, 'test@email.com has updated comments on "I\'ve been edited! (simple page)"')
@@ -2337,6 +2357,7 @@ class TestCommenting(TestCase, WagtailTestUtils):
 
         # Check notification email
         self.assertEqual(len(mail.outbox), 1)
+        self.assertNeverEmailedWrongUser()
         self.assertEqual(mail.outbox[0].to, [self.subscriber.email])
         self.assertEqual(mail.outbox[0].subject, 'test@email.com has updated comments on "I\'ve been edited! (simple page)"')
         self.assertIn('Deleted comments:\n - "A test comment"\n\n', mail.outbox[0].body)
@@ -2398,6 +2419,7 @@ class TestCommenting(TestCase, WagtailTestUtils):
 
         # Check notification email
         self.assertEqual(len(mail.outbox), 3)
+        self.assertNeverEmailedWrongUser()
 
         recipients = [mail.to for mail in mail.outbox]
         # The other non subscriber replied in the thread, so should get an email

programming_language: Python
filename: edit.py
change_type: ModificationType.MODIFY
diff: @@ -141,11 +141,11 @@ class EditView(TemplateResponseMixin, ContextMixin, HookResponseMixin, View):
         # Get subscribers to individual threads
         replies = CommentReply.objects.filter(comment_id__in=relevant_comment_ids)
         comments = Comment.objects.filter(id__in=relevant_comment_ids)
-        thread_users = get_user_model().objects.exclude(pk=self.request.user.pk).exclude(pk__in=subscribers.values_list('user_id', flat=True)).prefetch_related(
+        thread_users = get_user_model().objects.exclude(pk=self.request.user.pk).exclude(pk__in=subscribers.values_list('user_id', flat=True)).filter(
+            Q(comment_replies__comment_id__in=relevant_comment_ids) | Q(**{('%s__pk__in' % COMMENTS_RELATION_NAME): relevant_comment_ids})
+        ).prefetch_related(
             Prefetch('comment_replies', queryset=replies),
             Prefetch(COMMENTS_RELATION_NAME, queryset=comments)
-        ).exclude(
-            Q(comment_replies__isnull=True) & Q(**{('%s__isnull' % COMMENTS_RELATION_NAME): True})
         )
 
         # Skip if no recipients

programming_language: Python