Skip to content

fix(mails): gate session alert custom template on SMTP enabled - #15055

Merged
ArnabChatterjee20k merged 2 commits into
mainfrom
security/mails-session-alert-smtp-gate
Oct 28, 2026
Merged

ArnabChatterjee20k merged 2 commits into
mainfrom
security/mails-session-alert-smtp-gate

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

What

The session alert listener (src/Appwrite/Bus/Listeners/Mails.php) applied a project's stored custom sessionAlert subject and body regardless of whether the project's custom SMTP was enabled. Only the SMTP config itself was gated on smtp.enabled. With SMTP disabled the alert was sent through the platform SMTP sender, carrying the custom content.

Every other mail path (verification, recovery, magic URL, OTP, MFA, team invites) only applies a custom template when custom SMTP is enabled. Disabling SMTP does not clear stored templates, so the session alert was the one path where a custom template could be delivered through the platform sender.

Fix

Resolve the custom template only when smtp.enabled is true; otherwise the default session alert template is used. Sender/reply-to overrides were already inside the SMTP gate.

Tests

New e2e testSessionAlertIgnoresCustomTemplateWhenSMTPDisabled in tests/e2e/Services/Project/TemplatesBase.php (runs for both TemplatesConsoleClientTest and TemplatesCustomServerTest):

  • store a custom sessionAlert template, disable SMTP, trigger an alert: the mail uses the default subject and does not contain the custom body (failed before the fix, passes after)
  • re-enable SMTP, trigger an alert: the custom subject and body apply

Existing testSessionAlertUsesCustomTemplatePerLocale and the full Templates suites pass.

Tracking: appwrite-labs/cloud#7052

🤖 Generated with Claude Code

ArnabChatterjee20k and others added 2 commits October 28, 2026 16:11
The session alert listener applied the stored custom subject and body
even when the project's custom SMTP was disabled, so the mail went out
through the platform SMTP with the custom content. Every other mail path
only applies custom templates when custom SMTP is enabled; do the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change ensures the session-alert email uses the built-in locale default template when a project has no enabled SMTP configuration, so custom templates are only applied when the project controls its own mail delivery. A new e2e test helper creates two sessions and asserts the alert renders the correct template on each side.

Files Change
src/Appwrite/Bus/Listeners/Mails.php Only perform the custom template lookup when $smtpEnabled is true, keeping the default-locale fallback and enqueue path unchanged.
tests/e2e/Services/Project/TemplatesBase.php Adds e2e coverage that the session-alert mail uses the default template without SMTP and the custom template with SMTP enabled.

Reviewed commit: 8ae87f4

@ghost

ghost commented Oct 28, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The change implements the intended SMTP gate, and its e2e coverage verifies both sides of the behavior.

Session alert custom subject and body templates are now resolved only when the project has custom SMTP enabled. The Templates e2e coverage exercises both the disabled-SMTP default-template path and the enabled-SMTP custom-template path.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Bus/Listeners/Mails.php Gates session alert custom template lookup on the SMTP enabled flag and reuses that flag for SMTP configuration.
tests/e2e/Services/Project/TemplatesBase.php Adds an integration test for custom template behavior with SMTP disabled and re-enabled, plus a helper to trigger session alerts.

Reviewed 8ae87f4 · 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

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.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → security/mails-session-alert-smtp-gate (after).

Metric Before After Change
🚀 Requests/sec 213.85 217.8 ⚪ +1.8%
⏱️ Latency P50 79.68 ms 79.32 ms ⚪ -0.5%
⏱️ Latency P95 188.26 ms 186.51 ms ⚪ -0.9%
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 79.32 186.51 13,680 217.8 -1.75
Account 154.5 264.97 720 12.15 +6.8
TablesDB 76.96 145.42 7,440 121.24 -1.32
Storage 72.62 166.81 3,600 60.25 -23.14
Functions 113.55 224.28 1,920 32.92 -13.46

Top API waits (after)

API request Max wait (ms)
functions.create 525.17
account.name.update 392.12
tablesdb.rows.create 344.38
functions.variables.update 335.28
account.prefs.update 333.61

@ArnabChatterjee20k
ArnabChatterjee20k merged commit e03fb70 into main Oct 28, 2026
70 checks passed
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.

2 participants