fix: render portal contact-form html instead of escaping it#133
Merged
Conversation
The #123 mail-hardening commit switched the anonymous /api/mails/contact route to textToSafeHtml, which HTML-escapes the whole body. But the portal contact form composes an HTML body client-side (lists, bold labels, line breaks, optional bodyTemplate_html) and posts it in the `text` field, so recipients started seeing raw tags instead of rendered structure. Use sanitizeMailHtml on the contact route instead: structure renders while scripts and non-http(s)/mailto hrefs are stripped. The body is partly anonymous-visitor-controlled, so the sanitizer stays the trust boundary rather than reverting to raw passthrough. Update the test and docs/architecture/emails.md (invariants 3-4 and the contact-endpoint section) to match. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
The #123 mail-hardening commit switched the anonymous
/api/mails/contactroute to
textToSafeHtml, which HTML-escapes the whole body. But the portalcontact form composes an HTML body client-side (lists, bold labels, line
breaks, optional
bodyTemplate_html) and posts it in thetextfield, sorecipients started seeing raw tags instead of rendered structure.
Use
sanitizeMailHtmlon the contact route instead: structure renders whilescripts and non-
http(s)/mailtohrefs are stripped. Test anddocs/architecture/emails.mdupdated to match.Why: portal contact emails regressed to showing raw HTML after the mail
hardening pass; this restores rendering without reopening the injection path.
Heads-up: the body is partly anonymous-visitor-controlled, so the
server-side sanitizer (not raw passthrough) is the trust boundary. Unlike the
previous escape path,
sanitizeMailHtmldoes not turn\ninto<br>, sothe plain-text contact-form prefix no longer line-breaks in the HTML part —
cosmetic only.