Skip to content

fix(mails): escape the redirect variable in email templates - #14822

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/email-redirect-escaping
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/email-redirect-escaping

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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 into href="{{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.

redirect is now escaped with htmlspecialchars(ENT_QUOTES) like every other variable, in both Workers/Mails.php and Workers/Notifications.php. Entity-encoded &amp; and &quot; inside an href are 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 the Redirect validator (registered platform hostnames over http/https or browser-extension schemes, plus allowed custom app schemes).

Compatibility

Rendered email HTML now contains &amp; 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

  • New e2e AccountCustomClientTest::testCreateMagicUrlEscapesRedirect: a magic URL whose path and fragment contain " and < is escaped in the email HTML, and the decoded href still signs the user in.
  • Updated ProjectsConsoleClientTest::testPasswordRecoveryUrlParams and TeamsCustomClientTest::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

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.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


All template variables passed to email templates are now HTML-escaped by default, including redirect URLs, closing a stored HTML injection path into email bodies via user-controlled parameters. Escaped entities decode correctly in href attribute contexts, so magic-link, invite, and recovery flows continue to function. E2E tests for Account, Projects, and Teams were updated to cover the escaped rendering end-to-end.

Files Change
src/Appwrite/Platform/Workers/Mails.php, src/Appwrite/Platform/Workers/Notifications.php Drop the redirect special case in Template::setParam calls so all variables are HTML-escaped by default
tests/e2e/Services/Account/AccountCustomClientTest.php, tests/e2e/Services/Projects/ProjectsConsoleClientTest.php, tests/e2e/Services/Teams/TeamsCustomClientTest.php Update assertions to expect escaped redirect URLs, including a full magic-link session flow through the decoded link

Reviewed commit: 7fb03a0

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental test change still identifies the escaped-URL email and checks the complete expected URL; no issue needs fixing.

The mail and notification workers now HTML-escape redirect when rendering email templates. E2E coverage checks escaped redirect values in magic-link, recovery, and invitation emails, including that escaped links remain usable.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
src/Appwrite/Platform/Workers/Mails.php HTML-escapes redirect values when rendering mail templates.
src/Appwrite/Platform/Workers/Notifications.php HTML-escapes redirect values when rendering notification email templates.
tests/e2e/Services/Account/AccountCustomClientTest.php Adds regression coverage that magic URLs with markup characters are escaped while the decoded link works.
tests/e2e/Services/Projects/ProjectsConsoleClientTest.php Checks escaped redirect URLs in recovery emails, including matching the injected-URL email by its escaped content.
tests/e2e/Services/Teams/TeamsCustomClientTest.php Updates invitation-email injection assertions for escaped redirect output.

Reviewed the commits since 7fb03a0 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/email-redirect-escaping (after).

Metric Before After Change
🚀 Requests/sec 213.64 218.09 ⚪ +2.1%
⏱️ Latency P50 79.48 ms 78.85 ms ⚪ -0.8%
⏱️ Latency P95 191.14 ms 188.07 ms ⚪ -1.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 78.85 188.07 13,680 218.09 -3.08
Account 159.05 291.06 720 11.96 +16
TablesDB 76.65 141.67 7,440 119.96 -2.08
Storage 71.74 164.68 3,600 60.3 -16.33
Functions 115.23 228.14 1,920 32.93 -0.14

Top API waits (after)

API request Max wait (ms)
account.prefs.update 430.66
tablesdb.rows.create 349.7
functions.create 346.63
functions.variables.update 346.42
account.name.update 342.63

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@ChiragAgg5k
ChiragAgg5k merged commit aedd88a into main Oct 22, 2026
34 checks passed
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
…14822)

The notifications worker does not exist on 1.9.x.

(cherry picked from commit aedd88a)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…caping

fix(mails): escape the redirect variable in email templates

(cherry picked from commit aedd88a)
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