Skip to content

roots: Build the accepted roots into a minified snippet for each zone - #70

Merged
robstradling merged 2 commits into
mainfrom
build-time-roots
Nov 16, 2026
Merged

robstradling merged 2 commits into
mainfrom
build-time-roots

Conversation

@robstradling

Copy link
Copy Markdown
Member

What

  • Build-time roots lists. ACCEPTED_ROOTS in the source holds placeholders: the URLs of the CTLogs PEM bundles, which are authoritative. npm run build (tools/build.mjs) fetches each bundle and replaces it with the sorted FNV-1a hashes of the roots' subject names, as a hex string. The snippet no longer fetches roots at runtime. Its only subrequest is the forward, so it fits every plan's subrequest limit and has no exposure to error 1201.

    • That removes the runtime fetching, its caching, rootsCacheSeconds, and the "CF_CTreq Accepted Roots v1" format, along with the roots-hashes script.
    • Lists are decoded lazily, on a log's first request that needs them.
  • Every Sectigo log gets its roots checked:

    • sectigo: Monument, Statue, Elephant and Tiger (monument-ca-roots.pem)
    • Billboard, Standee, Dumbo and Tigger: one list each.
  • One snippet per zone. logEnvironments entries are grouped in conditions on ZONE. Terser (compress.passes: 2) removes the other zones' entries and lists.

    File Roots Size
    dist/cf_ctreq.ct.sectigo.com.min.js 238 + 12 12.7 KB
    dist/cf_ctreq.ctlabs.sectigo.com.min.js 676 + 907 + 133 24.3 KB
    dist/cf_ctreq.min.js (generic: no zone's logs) none 10.5 KB
  • Layout. The source is now src/cf_ctreq.js, and the generated snippets are in dist/.

  • Build and CI.

    • npm run build -- --offline rebuilds with the lists the snippets already have; CI's test jobs use it.
    • The build fails if the minifier doesn't keep each list exactly once, in ACCEPTED_ROOTS order.
    • The minification workflow commits dist/ and now also runs hourly, to pick up changes to the CTLogs bundles.
  • Tests and docs.

    • The roots tests are rewritten for build-time lists.
    • New tests check each zone's build (its own logs and lists only; the generic build has none), and that every dist/ file matches the source.
    • test:forwarding runs the local build for the log's zone.
    • The README is updated throughout.

Testing

  • npm test and npm run test:minified pass in all four environments.
  • npm run test:differential reports no false rejections, against both the source and dist/cf_ctreq.min.js.
  • An offline rebuild reproduces all three dist/ files exactly.

Before deploying

  • Deploy dist/cf_ctreq.ct.sectigo.com.min.js and dist/cf_ctreq.ctlabs.sectigo.com.min.js to their zones.
  • Run test:resubmit against Standee and Dumbo, then against a production log once it's enabled there.
  • When I compared them, the production logs' get-roots returned 8 roots that aren't in the PEM bundle. Chains to those roots would be rejected until the logs are updated to match CTLogs.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Rather than fetching each log's accepted roots at runtime, ACCEPTED_ROOTS in
the source holds placeholders (the URLs of CTLogs' PEM bundles), which
npm run build (tools/build.mjs) fetches and replaces with the hashes of the
roots' subject names. So the snippet makes no subrequests besides forwarding,
and works on any plan.

logEnvironments entries are grouped by Cloudflare zone, in conditions on
ZONE, and the build writes a snippet for each zone (ct.sectigo.com and
ctlabs.sectigo.com), with only its logs and lists, and a generic one with no
zone's. Each Sectigo log now has its accepted roots checked.

The source moves to src/, and the minified snippets to dist/. --offline
rebuilds them with the lists that they already have (as CI's tests do), and
the minification workflow also runs hourly, to pick up changes to the lists.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/cf_ctreq.js Fixed
Comment thread src/cf_ctreq.js Fixed
Comment thread src/cf_ctreq.js Fixed
Comment thread src/cf_ctreq.js Fixed
Comment thread src/cf_ctreq.js Fixed
CodeQL (js/incomplete-hostname-regexp) assumed that a placeholder URL in a
logEnvironments entry could reach search(), which would compile a string as
a regular expression; it can't, as only an entry's first element, which must
be a RegExp, is used as its pattern. test() takes no string, so there's
nothing to flag. It starts at lastIndex for a pattern with the g or y flag,
so that's reset first, as search() did.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@robstradling
robstradling merged commit 801882f into main Nov 16, 2026
21 of 22 checks passed
@robstradling
robstradling deleted the build-time-roots branch November 16, 2026 19:42
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