Skip to content

fix(ops): the secrets gate called an undeliverable mailer "OK" - #489

Open
runyourempire wants to merge 1 commit into
mainfrom
fix/pages-secrets-deliverability-gate-v2
Open

fix(ops): the secrets gate called an undeliverable mailer "OK"#489
runyourempire wants to merge 1 commit into
mainfrom
fix/pages-secrets-deliverability-gate-v2

Conversation

@runyourempire

Copy link
Copy Markdown
Collaborator

The secrets gate called an undeliverable mailer "OK"

check-pages-secrets.cjs can only ever read variable names — Cloudflare never returns values — so "configured" and "able to send" were the same answer to it. Those come apart in one specific and dangerous way: set RESEND_API_KEY and RESEND_FROM_EMAIL while the sending domain is unverified, and Resend refuses every send with 403 while the gate reports green.

That is the same conflation the script was written to refuse, pointing the other way. Its own header says "could not check" must never read as "checked and fine"; a mailer that cannot send must not read as one that can.

Found while provisioning Resend for real. The account's key was send-only and 4da.ai was unverified, so setting the two variables at that moment would have turned an honest exit 1 into a green light over a delivery path that 403s on every sale. Refusing to create that false green is worth more than the round-trip it saves — and it is the second false-green found in this repo's gates this week, after the one in #485.

What it does now

A DNS lookup for resend._domainkey.4da.ai. No token, no secret values, no network credentials — either the record is published or it is not.

Three-valued, like the rest of the script:

DNS answer Verdict Exit
TXT records present verified 0
NXDOMAIN / ENOTFOUND / ENODATA genuinely absent 1
resolver unreachable (ESERVFAIL, timeout, unknown) unknown 2

The third row is load-bearing. Reporting an unreachable resolver as "not verified" would fail a release over a network blip and teach everyone to ignore the gate — the exact way a gate dies.

SENDING_DOMAIN is hard-coded for the same reason PROJECT is: Cloudflare will not disclose the value of RESEND_FROM_EMAIL, so the domain to check against cannot be discovered from the project.

Tests, which the script shipped without

A poor look for a gate whose entire purpose is not lying. Eight added, covering every DNS outcome and both mailer states.

One is worth calling out: main() must return a Promise. If it is ever reverted to synchronous, the require.main handler assigns a Promise to process.exitCode, which coerces to 0 — a permanently and silently green gate. That is precisely the failure this whole script exists to prevent, so it is pinned.

177 script tests pass, up from 169 on main.

Verified against live DNS, both directions

  • When resend._domainkey.4da.ai did not exist, this read absent (ENOTFOUND) — independently confirming Resend's own 403 without using the API key at all.
  • Now that the record is published, it reads verified.

Same code, opposite answers, tracking reality as it changed during the session.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Fq96xWyPQjx2bCCzWtsnC9

check-pages-secrets.cjs could only ever read variable NAMES -- Cloudflare
never returns values -- so "configured" and "able to send" were the same
answer to it. They come apart in one specific and dangerous way: set
RESEND_API_KEY and RESEND_FROM_EMAIL while the sending domain is
unverified, and Resend refuses every send with 403 while the gate reports
green.

That is the same conflation this script was written to refuse, pointing
the other way. Its own header says "could not check" must never read as
"checked and fine"; a mailer that cannot send must not read as one that
can.

Found while provisioning Resend for real: the account's key is send-only
and 4da.ai is not verified, so setting the two variables now would have
turned an honest exit 1 into a green light over a delivery path that 403s
on every sale. Refusing to create that false green is worth more than the
round-trip it saves.

The check is a DNS lookup for resend._domainkey.4da.ai -- no token, no
secret values, either the record is published or it is not. Three-valued
like the rest of the script: published is verified, NXDOMAIN/ENOTFOUND/
ENODATA is absent, and an unreachable resolver is UNKNOWN and exits 2,
because reporting a network blip as "not verified" would fail a release
for the wrong reason and teach everyone to ignore the gate.

Proven against live DNS both ways: resend._domainkey.4da.ai reads absent
(ENOTFOUND), independently confirming the Resend API's 403 without using
the key at all; a name that does publish TXT reads verified.

Also adds the tests the script shipped without, which is a poor look for
a gate whose whole purpose is not lying. Eight of them, including one
pinning that main() returns a Promise: if it is ever reverted to sync the
require.main handler assigns a Promise to process.exitCode, which coerces
to 0 and makes the gate permanently and silently green.

174 script tests pass, up from 166.
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