Skip to content

Load the cron handler without importing the ES-module route, compare CRON_SECRET in constant time, and read any NPM_CONFIG_DRY_RUN value but false, 0 or empty as a dry run (#67) - #68

Merged
thebenignhacker merged 1 commit into
mainfrom
integrate/2026-10-08-r2
Oct 8, 2026
Merged

thebenignhacker merged 1 commit into
mainfrom
integrate/2026-10-08-r2

Conversation

@thebenignhacker

Copy link
Copy Markdown
Contributor

This pull request carries one commit, the follow-up fixes listed in #67: the cron route's request handler moves into lib/cron.js so tests load it with require() instead of importing the ES-module route file, the CRON_SECRET bearer comparison goes through crypto.timingSafeEqual on equal-length SHA-256 digests, and the PyPI country collector reads npm_config_dry_run set to any value other than false, 0 or empty as a dry run. The README and a test comment that gave the wrong edit distance are corrected to match.

Included

  • Load the cron handler without importing the ES-module route, compare CRON_SECRET in constant time, and read any NPM_CONFIG_DRY_RUN value but false, 0 or empty as a dry run (Follow-up fixes after #66 (4 items) #67)

What the code on this branch does:

  • pages/api/cron/collect.js is now two lines: it imports cronHandler from lib/cron.js and exports it as the default. A test reads the route file and asserts exactly those two lines.
  • isAuthorized returns false when CRON_SECRET is unset or empty or when the header is not a string; otherwise it compares the SHA-256 digest of the header with the digest of Bearer <secret> using crypto.timingSafeEqual. The test asserts that Bearer s3cret is accepted, that Bearer s3cres and a longer wrong token are refused, that an array header is refused without reaching the comparison, and that each comparison receives two buffers of equal length.
  • npmDryRun matches the variable name npm_config_dry_run in any letter case and treats the value, trimmed and lower-cased, as a dry run unless it is empty, false or 0. The tests assert true, TRUE, True, 1 and yes select a dry run and false, FALSE, False, 0 and empty do not, and that NPM_CONFIG_DRY_RUN=TRUE and =1 without credentials take the dry-run path, exit 1 with "nothing was measured", and write no run status file.

Verified on this exact tree

Run with Node 24.21.0, the version both workflows and .node-version select.

  • npm ci --no-audit --no-fund: completed, native module for better-sqlite3 built.
  • npm run build (next build): exit 0, "Compiled successfully", 3 of 3 static pages generated.
  • node --test --test-concurrency=4 test/*.test.js: 18 test files; 258 tests, 258 passed, 0 failed, 0 cancelled, 0 skipped.
  • Typecheck, lint and changelog check: the repository has no such scripts, so none ran.
  • git status --porcelain after the tests and the build printed nothing.

No pre-existing or load-related failures: every test passed in the single full run.

Not included

None.

How to merge

Rebase and merge, so that each change stays its own commit on main.

…CRON_SECRET in constant time, and read any NPM_CONFIG_DRY_RUN value but false, 0 or empty as a dry run (#67)

Fixes #67
@vercel

vercel Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
github-analytics-tracker Ready Ready Preview Oct 8, 2026 2:17am UTC

Request Review

@thebenignhacker
thebenignhacker merged commit 1738676 into main Oct 8, 2026
3 checks passed
@thebenignhacker
thebenignhacker deleted the integrate/2026-10-08-r2 branch October 8, 2026 02:18

This branch was successfully deployed

1 active deployment
Preview — 7c7d6eeb Deployed Oct 8, 2026 by vercel[bot]
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