Repository navigation
fix(mails): escape the redirect variable in email templates - #14822
Conversation
The redirect URL was inserted into href attributes and link text verbatim, while every other variable is HTML-escaped. Escape it like the rest; entity-encoded ampersands and quotes inside href are standard HTML, so links keep working.
|
Review complete. No issues found — approved ✅. All template variables passed to email templates are now HTML-escaped by default, including
Reviewed commit: 7fb03a0 |
🟢 Tier S · Ready to merge
The mail and notification workers now HTML-escape Latest changes: The password-recovery test now locates the injected-URL email by its escaped marker instead of matching the user ID in the HTML.
📂 Walkthrough · 5
Reviewed the commits since |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
…caping fix(mails): escape the redirect variable in email templates (cherry picked from commit aedd88a)
What
The mails and notifications workers HTML-escape every template variable except
redirect, which was left raw by an old hotfix for custom templates. The redirect URL is rendered intohref="{{redirect}}"and as link text in the magic URL, recovery, verification and invitation emails, so characters such as"and<in its path or fragment reached the email markup unescaped.redirectis now escaped withhtmlspecialchars(ENT_QUOTES)like every other variable, in bothWorkers/Mails.phpandWorkers/Notifications.php. Entity-encoded&and"inside anhrefare standard HTML and decode back to the same URL, so links keep working (the data export email already passes its download link through the same escaping). Scheme and host checks on the redirect URL are unchanged: it still has to pass theRedirectvalidator (registered platform hostnames over http/https or browser-extension schemes, plus allowed custom app schemes).Compatibility
Rendered email HTML now contains
&between query parameters in redirect links. Mail clients and browsers decode it to the same URL. Custom templates that use{{redirect}}inside an attribute or text get the escaped value, which is what HTML expects.Tests
AccountCustomClientTest::testCreateMagicUrlEscapesRedirect: a magic URL whose path and fragment contain"and<is escaped in the email HTML, and the decodedhrefstill signs the user in.ProjectsConsoleClientTest::testPasswordRecoveryUrlParamsandTeamsCustomClientTest::testTeamsInviteHTMLInjection, which previously asserted the unescaped markup, to assert the escaped form.E2E runs in CI only. Pint and PHPStan pass on the touched files.
Related: appwrite-labs/cloud#6666