Repository navigation
feat: add OTP-Token header to OTP emails - #15096
Conversation
Bind email OTP codes to the requesting origin with the OTP-Token header (draft-goto-otp-token), so mail clients and autofill can deliver the code to that origin only. Covers email token, recovery OTP, verification OTP and MFA email challenge emails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
This PR binds OTP codes to the requesting origin by attaching an RFC 9651-style
Reviewed commit: 9ba5e7e |
🟢 Tier S · Ready to merge
Adds a structured Latest changes: The latest commit changes the OTPToken unit test providers from returned arrays to yielded iterators and replaces nullable assertions with instance assertions.
📂 Walkthrough · 8
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
There was a problem hiding this comment.
Adds origin-bound OTP-Token email headers to OTP flows via a new OTPToken canonicalization library, with unit and e2e coverage.
Key findings
- 🟡 Add e2e coverage for MFA challenge
OTP-Tokenheader — AccountBase.php:221
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The CSRF hook already validates the request origin; OTPToken::from() enforces the draft's origin requirements. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document the OTP-Token header that Appwrite adds to email OTP, email verification, password recovery and MFA email challenge emails (appwrite#15096), and add the announcement post and the 2026-11-11 changelog entry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
Adds the new
OTP-Tokenemail header to every Appwrite email that carries a one-time code. Mail clients, browsers and password managers can then read the code from the header and autofill it, but only on the origin it is bound to. That means less copying codes between tabs and less risk of a phished code being typed into a lookalike site.Emails covered
POST /v1/account/tokens/emailPOST /v1/account/recovery/otpPOST /v1/account/verifications/email/otpPOST /v1/account/mfa/challenges(factor=email)Magic URL, link-based recovery and verification emails carry no code, so they are unchanged.
How the origin is chosen
The code is bound to the request's
Origin, which the existing CSRF hook ingeneral.phphas already checked against the project's registered platforms. The header is sent only when:https, orhttponlocalhost/*.localhost/127.0.0.0/8/[::1], as the draft requires (§3.1).Otherwise no header is sent, and the email is exactly as before. This covers server SDK calls without an
Origin, native mobile apps, custom schemes, browser extensions, and plain-http public hosts.Implementation
Appwrite\Auth\OTPTokenvalue object (src/Appwrite/Auth/OTPToken.php). It canonicalizes the origin and writes the value as an RFC 9651 Structured Field: ansf-stringitem with anoriginparameter. Escaping follows §3.3.3, and only printable ASCII is allowed.headers:to theMailmessage. The plumbing already existed:Mail::$headers→ mails worker →Utopia\Messaging\Messages\Email::$headers.Utopia\SMTP\Mime\Header::line()applies RFC 2047 encoded-words only to non-ASCII values, so the quoted ASCII value is sent as-is. Long lines are folded at spaces, and the draft (§3.2 step 2) says receivers unfold before parsing. This avoids the bug reported against Resend, where a provider RFC 2047-encoded the quotes (Otp-Token: =?UTF-8?Q?=22123456=22...) and broke parsing..github/ci/e2e.json: the new file is mapped to the Account lane.Things to note
OTPToken::HEADERconstant, so following a rename is a one-line change.token=parameter from §6.1 (Future Work), because it is not specified yet.Test Plan
tests/unit/Auth/OTPTokenTest.php): header format, sf-string escaping, origin canonicalization (case, default ports, custom ports, loopback hosts, IPv4/IPv6 loopback), and rejection of insecure http, lookalikelocalhost.example.com, opaquenull, custom schemes, extensions, path/query/userinfo, non-ASCII, and empty or control-character codes.AccountBase::testEmailOTPSessionasserts that the maildev message hasotp-token: "<code>"; origin="http://localhost", matching the code in the body.AccountCustomServerTest::testCreateTokenWithSessionsKeyasserts that an API-key request without anOriginsends noOTP-Tokenheader.Sources
Specification
OTP-TokenEmail Header Field" by S. Goto and M. West (Google), 21 Sep 2026 (txt)One-Time-Codeheader proposal)Normative references used here
OTP-Tokenregistration, §5 of the draft)Prior art the draft builds on
autocomplete="one-time-code", MDN: One-time passwordsEcosystem and discussion
OTP-Tokenheader (the motivating thread)#autofill-gmail-otp, Canary 154). This is related client-side work; it is not confirmed to use this header.Related PRs and Issues
Checklist
🤖 Generated with Claude Code