From 15367a5504e2133264760eeba571e824abeb59b3 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Mon, 13 Jul 2026 11:35:07 -0400 Subject: [PATCH] fix: escape user input in notification content templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Discussion thread titles (and other user-controlled context fields — replier_name, author_name, username) were interpolated raw into notification.content via `str.format(**context)`. That output is rendered with Django's `|safe` filter in digest_content.html, which is included by both the email_digest and batched_email body templates, so a `evil', '<style>body{background:red}</style>evil'), + ('', '<script>alert(1)</script>'), + ('AT&T "quoted"', 'AT&T "quoted"'), + ], +) +def test_get_notification_content_escapes_user_input(user_input, escaped): + """ + Regression test for GHSA-rv5w-f4r5-h77g: user-controlled context values + must be HTML-escaped before being interpolated into a content_template + via `str.format`. Structural context keys (`p`, `strong`) are exempt so + the template can still emit real

/ tags. + """ + context = {'replier_name': 'alice', 'post_title': user_input} + content = base_notification.get_notification_content('new_response', context) + assert '