From 877fa21a092e3496f33e417621a8cb4fdf41eb4d Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Tue, 20 Jan 2026 19:19:06 +0100 Subject: [PATCH] Fix XSS vulnerability in event invitation emails Replace `.html_safe` with `sanitize()` for event descriptions in email templates to prevent potential XSS attacks while still allowing safe HTML formatting tags. Changes: - Replace @event.description.html_safe with sanitize(@event.description) in invite_student.html.haml - Replace @event.description.html_safe with sanitize(@event.description) in invite_coach.html.haml - Add XSS protection test specs to verify dangerous tags are stripped while safe content is preserved The sanitize helper uses Rails' built-in SafeListSanitizer which: - Strips dangerous tags like

Safe content

') + end + let(:invitation_with_html) { Fabricate(:invitation, event: event_with_html, member: member) } + + it 'sanitizes description in invite_student email' do + EventInvitationMailer.invite_student(event_with_html, member, invitation_with_html).deliver_now + + expect(email.body.encoded).not_to include('