Skip to content

fix: scope CI tokens and validate releases before npm publish - #91

Merged
baiyuqing merged 1 commit into
mainfrom
baiyuqing/harden-ci-publish
Nov 5, 2026
Merged

baiyuqing merged 1 commit into
mainfrom
baiyuqing/harden-ci-publish

Conversation

@baiyuqing

Copy link
Copy Markdown
Collaborator

CI jobs currently inherit the repository's write-default GITHUB_TOKEN, and checkout persists credentials before running repository code. Set contents: read in all five workflows, disable checkout credential persistence, and pin the existing v4 actions to commit SHAs.

Before npm publication, check out the release event's exact commit, verify it is an ancestor of origin/main, and require lint and unit tests to succeed. Pin the publishing runtime to Node.js 24. Tests build the package before the npm token is supplied; publish with --ignore-scripts to avoid rebuilding with the token. Update the release guide accordingly. Release creation remains the maintainer authorization step; this does not introduce an environment approval gate or change repository settings.

Validation:

  • Build, all 55 unit tests, and lint pass on Node.js 24.22.2.
  • Workflow YAML assertions verify read-only permissions, disabled credential persistence, action SHA pins, release checkout, and validation before the token-bearing publish step.
  • A temporary Git fixture confirms the ancestry check accepts a merged commit and rejects an unmerged commit.
  • npm pack --dry-run --ignore-scripts includes the built distribution, and git diff --check passes.
  • No live database tests or npm publication were performed.

@ti-chi-bot ti-chi-bot Bot added the size/M label Nov 5, 2026
@baiyuqing
baiyuqing merged commit 8fe0313 into main Nov 5, 2026
3 checks passed
@baiyuqing
baiyuqing deleted the baiyuqing/harden-ci-publish branch November 5, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant