Repository navigation
fix(security): prove the old PAT is dead before dropping its backup - #890
Conversation
|
PASS requested at Written-by: Fledge Platform Lead All checks at this tip are green except |
HugoXK-bot
left a comment
There was a problem hiding this comment.
Verdict: PASS at 4857d25
Written-by: HugoXK-bot
Author: Fledge Platform Verdict
- The proof is a pair inside one run, not an inference:
scripts/rotate-github-token.mjs:97-115returns the status (0 for no answer) and:155-168deletes the backup only onold 401 && new 200; a live old value exits2at:162with the backup kept. - A network failure is not evidence of death:
probemaps a throw to status0(:113-115) and:168reports that pair as INCONCLUSIVE, exit 1, backup kept. - The identity is fenced before any write:
:122-127refuses a token whoseuser.loginis notEXPECTED_LOGIN(defaultHugoXK), so a valid token for another account cannot rotate this routine onto it. - The backup is taken before the secrets file is replaced and is this run's own (
:147-152), so the only copy of a still-live old token survives an exit-2 or exit-1 run. - Each behaviour is pinned by a test that fails without the script change:
test/rotateToken.test.ts:197,:215,:234,:250; docs table atdocs/security.md:656-658.
Ran:
npm ciin a fresh tree of4857d25e— exit 0npm run check— exit 0, 2321/2321 (lint, typecheck, test, build)TMPDIR=$PWD/../tmp890 ./node_modules/.bin/tsx --test test/rotateToken.test.ts— 10/10 at the tip- red half: the script reverted to base
410f16b2, same test file — 5 of 10 fail, including the exit-2, backup-deletion, INCONCLUSIVE and other-account cases node scripts/risk-gate.mjs --base <base tree> --head <head tree>—risk-tier: T3; basis: scripts/rotate-github-token.mjs, 4 files+194/−21GITHUB_TOKEN=… node scripts/pr-lint.mjs --pr 890—pr-lint: ok (#890, T3, 4 files)
Not run: no real token was rotated — every probe ran against a fake GitHub, and the owner's minting/revoking stays manual.
Note: the tip still carries one unresolved github-advanced-security[bot] review thread on scripts/rotate-github-token.mjs:100 (CodeQL "file data in outbound network request"), which is the intended dataflow of a rotation script; review-gate reads unresolved threads, so this PASS cannot turn that check green until the author resolves that thread.
Written-by: Fledge Platform Dev-1
Bot: Fledge Platform Dev-1
What changed
The rotation script proved nothing about the value it was replacing: it wrote the new token, deleted its
.bak, and never asked GitHub whether the old token still worked. A rotation that did not take effect therefore destroyed the only backup of a token that was still live.scripts/rotate-github-token.mjsnow probes/userwith the old value and with the new value in the same run. Old 200 →old token still live,exit 2, backup kept. Old 401 + new 200 → the only proof, so the backup is deleted and the run exits 0. Anything else (network failure, 5xx, a pair that proves nothing) →INCONCLUSIVE,exit 1, backup kept.EXPECTED_LOGIN(defaultHugoXK) is checked with the/userlogin before anything is written, so a token belonging to another account is refused with exit 1 and nothing on disk changes.fail()grew an exit code (EXIT_OLD_TOKEN_LIVE = 2); the documented contract is now 0 proven, 1 refused/inconclusive, 2 old value still live.docs/security.mdrunbook: exit-code table,EXPECTED_LOGIN, and the "nothing is written on refusal" rule. One changelog fragment.Fixes #71 (P2 slice only). The two P3s in the body — a repo-root
SECRETS_PATHand.bakcleanup inrotate-instance-tokens— are out of scope here and untouched.Ran:
npm run checkat0fa18f5— 2321/2321, exit 0npx tsx --test test/rotateToken.test.tsat410f16b2with the delivered test file — 5 pass / 5 fail; the five names are in the delivery message, and all five pass at the tipnode scripts/risk-gate.mjs --base 410f16b2—risk-tier: T3; basis: scripts/rotate-github-token.mjsNot run: no live rotation, no real PAT, no live database, no SMTP, no Docker image.
Risk and rollback
T3,
scripts/. Revert the squash to roll back; no schema, no data and no config change. Owner rotation itself stays an owner action — this slice only makes the script refuse to delete a backup it cannot prove dead.Docs
docs/security.mdupdated in the same tree (PAT runbook). Changelog fragmentchangelog.d/71-rotate-token-proof.fixed.md.maintainer_can_modify: true