Skip to content

fix: sanitize workshop description in invitation emails#2676

Open
mroderick wants to merge 2 commits into
masterfrom
fix/sanitize-description-in-emails
Open

fix: sanitize workshop description in invitation emails#2676
mroderick wants to merge 2 commits into
masterfrom
fix/sanitize-description-in-emails

Conversation

@mroderick

@mroderick mroderick commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

This PR is branched from #2674 to inherit its fix for the flaky tests. Please review and merge that one first, then rebase this one.


Problem

Norwich chapter organisers reported that workshop invitation emails contain escaped HTML, including <!DOCTYPE html>. The email shows raw HTML source like &lt;!DOCTYPE html&gt;&lt;html&gt;... instead of rendered content.

image

Root Cause

Two things combined:

  1. Data: Norwich organisers have been pasting full HTML documents (<!DOCTYPE html>...) into the workshops.description field via the admin form. This started April 2026 — all 5 subsequent Norwich workshops (IDs 3687, 3688, 3735, 3736, 3761) contain full <html> documents in their descriptions. The description column is text with no format validation.

  2. Rendering mismatch: The mailer views render the description with HAML's default escaped output (=), which HTML-escapes the entire value. On the web, the description is rendered with sanitize() (allows safe HTML through). Other chapters also use HTML tags like <strong>, <p>, <b> in descriptions (278 workshops across all chapters contain HTML-like content), which were also being escaped in emails.

The description was added to invitation emails in commit 47c7a900 (Aug 2025, "feat: add description to invitation emails") and has always used escaped rendering — this isn't a regression, just the first time a chapter pasted a full document.

Change

Wrap @workshop.description with sanitize() in all four mailer templates, matching how the web views render it:

  • app/views/workshop_invitation_mailer/invite_student.html.haml
  • app/views/workshop_invitation_mailer/invite_coach.html.haml
  • app/views/workshop_invitation_mailer/attending.html.haml
  • app/views/workshop_invitation_mailer/attending_reminder.html.haml

Testing

Updated both #attending renders workshop description as HTML, not escaped tests to use HTML content in the description and assert the tags are rendered, not escaped — they would catch a revert back to =.

27 examples, 0 failures

… spec

The test constructs an expected string from Faker-generated city names,
which can contain apostrophes (e.g. O'Connerstad). ERB::Util.html_escape
escapes ' to &#39;, but the expected value used raw characters, making the
test pass or fail depending on which random city Faker returns.

Wrap each component in ERB::Util.html_escape to match the presenter's
behaviour, eliminating the flake.
@mroderick mroderick force-pushed the fix/sanitize-description-in-emails branch from cce5094 to 1a1a938 Compare June 29, 2026 17:15
Mailer views rendered @workshop.description with HAML's default
escaped output (=), which HTML-escapes any HTML in the description.
Many chapters use HTML tags (<strong>, <p>, <b>) in descriptions,
and Norwich organisers paste full HTML documents (including doctype)
into the field — all of which appeared as escaped text in emails.

Render with sanitize() instead, matching the web views.

Includes a test guard: description with HTML tags asserts the tags
are rendered, not escaped. Also fixes the address presenter spec
which was flaky on Ruby 3.4+ where ERB::Util.html_escape escapes
apostrophes — used deterministic address values instead.
@mroderick mroderick force-pushed the fix/sanitize-description-in-emails branch from 1a1a938 to d1e6c13 Compare June 29, 2026 17:18
@mroderick mroderick marked this pull request as ready for review June 29, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant