The OTP-Token header: verification codes, no guessing
In the post about /\d{6}/ the problem was getting the verification code out of an email full of order numbers, prices, years and links. The answer was to look for the number closest to a word like "code". It works for mo
In the post about /\d{6}/ the problem was getting the verification code out of an email full of order numbers, prices, years and links. The answer was to look for the number closest to a word like "code". It works for most emails, but it's still guessing.
In September 2026, two people from Google published an IETF draft that removes the guessing: the OTP-Token header. The app sending the email declares the code in a header, and whoever reads the email doesn't need to search the text at all. Appwrite has been sending it since November, and saci.cc now reads it.
What the header looks like
OTP-Token: "482913"; origin="https://your-app.com"
It has two parts:
- The code, in quotes. The same one the body shows, the way a person would type it.
-
The
origin, the site that asked for the code. Same format aslocation.originin the browser: scheme, domain and port, no path and no trailing slash.
The draft sets a few rules that matter to whoever reads it:
-
originis required, and it has to behttps://, orhttp://localhostin development. - Only one
OTP-Tokenper email. With two or more, none of them count. - The header has to be in the email's own headers, not inside a MIME part.
Why it matters
For the person receiving the email, the idea is what WebOTP already does with SMS: the email client or the browser finds the code and offers to fill it in, without opening the email. That part is still a proposal: no IETF working group has adopted the draft, and the security side (for example, whether the origin has to match the email's DKIM signature) is still open.
For tests and agents, the gain is already here:
- No guessing. The code is declared. An order number in the subject or a year in the footer can't get in the way anymore.
-
The right code from the right app. With the
origin, a test can require the code to belong to the site it's testing, and not to another email that landed in the same inbox.
Sending the header from your app
It takes one more header when sending. With Nodemailer:
import nodemailer from "nodemailer";
const transporter = nodemailer.createTransport(process.env.SMTP_URL);
await transporter.sendMail({
from: "Your App <[email protected]>",
to: user.email,
subject: "Your verification code",
text: `Your verification code is ${code}. It expires in 10 minutes.`,
// The same code as in the text, declared for whoever reads the email
headers: { "OTP-Token": `"${code}"; origin="https://your-app.com"` },
});
Resend, SES and most sending services take a similar headers field. A few tips:
- Keep the code in the text too. The header is for machines; people still need to see the code.
- Put the address where the person types the code in
origin:https://staging.your-app.comin staging,http://localhost:3000in development. - Don't add anything besides the code and the
origin. Unknown parameters are ignored, but they don't help anyone.
Reading the header on saci.cc
When an email arrives with a valid OTP-Token, saci.cc takes the code from the header instead of searching the text, and keeps the origin with it. Without the header, the search from before still applies.
-
In the API: the inbox list and each email have
verificationCodeOriginnext toverificationCode. It'snullwhen the code came from the text. The webhook sends the same field. -
In the npm package:
waitForCode({ origin })only takes codes the sender bound to that site. -
In MCP:
get_verification_codereturns theoriginand takes the same filter, for agents signing up on several sites.
{
"messageId": "0100019a2b3c4d5e-6f7a8b9c-...",
"from": "Your App <[email protected]>",
"subject": "Your verification code",
"verificationCode": "482913",
"verificationCodeOrigin": "https://your-app.com",
...
}
In a Playwright test:
import { createInbox } from "saci.cc";
const inbox = await createInbox();
await page.getByLabel("Email").fill(inbox.address);
// Note the time before the click that sends the email
const sentAt = new Date();
await page.getByRole("button", { name: "Send code" }).click();
// Only a code your app bound to its own site
const code = await inbox.waitForCode({ origin: "https://your-app.com", after: sentAt });
await page.getByLabel("Verification code").fill(code);
origin also takes "your-app.com" or "https://your-app.com/login"; saci.cc reduces it to the header's format. One catch: with origin, emails without the header don't count. Use it only when your app already sends the header, or the test waits until it times out.
In short
-
OTP-Tokendeclares the code and its site in a header:OTP-Token: "482913"; origin="https://your-app.com". - Sending it takes one line where you send the email, and the code stays in the text.
- On saci.cc, the header's code comes first, and
verificationCodeOrigin,waitForCode({ origin })and MCP'soriginlet you require the code to come from the right app.
I build saci.cc, temporary email inboxes for end-to-end tests and AI agents. The npm package is saci.cc and the client is open source on GitHub.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.