fix: HTML-escape sender/subject in reply/forward quote header (#482)#488
Merged
rathlinus merged 1 commit intoJun 24, 2026
Merged
Conversation
…kmail#482) The forward quote header renders "From: Name <email>", but the HTML variant interpolated the sender string unescaped. In the rich-text composer the "<email>" portion is parsed by the browser as a bogus HTML tag and dropped, so the address silently disappears - the user sees only "From: Display Name". The plain-text variant and the details panel escape correctly, which is why the address shows there. This is the regression from bulwarkmail#367, which added the "<email>" into the HTML string without escaping it. Fix: HTML-escape the user-controlled values (sender, subject, date) in every HTML quote-header path - the production builder in lib/quote-header.ts and the composer's inline fallback (both htmlBody and plain-body branches), for forward and reply. The reply line keeps the bare display name by design (bulwarkmail#367), but its HTML form is now escaped too so a display name containing markup can't break out. As a side benefit this closes an HTML-injection vector: a crafted subject or display name was previously injected raw into the composer document. Adds lib/__tests__/quote-header.test.ts covering: forward text keeps "Name <email>"; forward HTML escapes the angle brackets (address survives) and a markup subject/display name; reply stays bare-name and HTML-safe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replying to / forwarding a message whose sender has a display name produced a
quote header that dropped the email address:
Expected: From: Display Name user@domain.tld
Actual: From: Display Name
The forward header builder already emits the full "Name " sender. The bug
is that the HTML variant interpolated that string UNESCAPED:
lib/quote-header.ts (forward):
const html =
... From: ${fromStrFull} ...; // fromStrFull = "Name "The composer is rich-text (HTML). When this markup is inserted into the editor,
the browser parses the "user@domain.tld" run as a bogus/unknown HTML tag and
does not render it - so only "From: Display Name" remains. The plain-text variant
and the message details panel escape correctly, which is why the address shows
THERE but vanishes in the composer body (the reporter read this as "the data is
present, so it's a builder issue" - correct: it is an HTML-escaping bug).
Reproduced directly against current main:
FORWARD html =
...
^^^^^^^^^^^^^^^^^^^ eaten as a tag
Regression origin: PR #367 ("localize reply/forward quote header incl. sender
address", commit 05e2837) added the "" into the HTML string without
escaping it. Before #367 the forward header showed only the bare name, so the
missing-address symptom is new since #367.
Changes
HTML-escape the user-controlled values (sender, subject, date) in EVERY HTML
quote-header path; the plain-text variants are unchanged. Uses the existing
escapeHtml() from lib/email-sanitization.ts.
buildQuoteHeader): escape fromStrFull + subject + date in the forward HTML;
escape the reply-line's interpolated from/date in the reply HTML.
page-prepared header is present): same escaping in both HTML branches
(htmlBody original and plain-body original), for forward and reply.
After the fix the forward HTML is:
From: Display Name <user@domain.tld>
which the editor renders as the intended "From: Display Name user@domain.tld".
Side benefit (security): the subject and display name were previously injected
") is now escaped - this closes an HTML-injection vector
RAW into the composer document. A crafted subject or display name (e.g.
"
into the compose editor.
Related Issues
Closes #482
Type of Change
Checklist
npm run typecheck && npm run lintand there are no errorsnpm run build)locales/) if my changes affect user-facing textScreenshots / Demo
Notes for Reviewers