Skip to content

ci: harden GitHub Actions workflows - #102

Open
nantoniazzi wants to merge 2 commits into
mainfrom
ci/harden-github-actions
Open

nantoniazzi wants to merge 2 commits into
mainfrom
ci/harden-github-actions

Conversation

@nantoniazzi

Copy link
Copy Markdown

What

This repository publishes an npm package from GitHub Actions: the release workflow (started by hand) builds the package and runs semantic-release with the NPM_TOKEN and GITHUB_TOKEN secrets. This PR hardens those workflows against a compromised third-party action or dependency, without changing what they do:

  • Every action is pinned to a commit SHA instead of a tag, with the version kept in a comment (e.g. actions/checkout@fbc6f39… # v5.1.0). Each SHA is the commit the current tag already points to, so behavior is identical.
  • The release job no longer leaves the GitHub token in .git/config (persist-credentials: false on checkout). semantic-release authenticates through the GITHUB_TOKEN environment variable, as its documentation recommends.

Why

CodinGame received a sales email from a CI/CD security vendor pointing at this pattern across our public repositories. An outsider cannot trigger these release workflows: they only run on workflow_dispatch or on pushes by people with write access, and pull requests from forks run without secrets. The remaining risk is indirect, the same one behind the tj-actions (March 2025) and Shai-Hulud (2025) incidents:

  • a tag of a third-party action can be moved to malicious code, which would then run with the release secrets;
  • a compromised npm dependency can run an install script in the release job, read the token left in .git/config by actions/checkout, or tamper with node_modules before semantic-release runs with NPM_TOKEN.

Notable decisions

  • Same major versions, no upgrades. Pinning only freezes what already runs, so the PR carries no functional change to review. Dependabot (or Renovate) can keep the SHAs up to date from the version comments.
  • Install scripts stay enabled in this repository. Its dependencies include native modules or a preprepare step that need them (e.g. canvas, node-pty, kerberos, downloaded extensions), so --ignore-scripts would break the build. Only the token persistence is removed here.
  • NPM_TOKEN is still used. The next step is npm trusted publishing (OIDC, no long-lived token), which needs the package to be configured on npmjs.com first; it will come in a follow-up PR.
  • The release workflow only runs when someone starts it, so this PR's CI does not exercise the release job. The next manual release is the real test: if --ignore-scripts or the missing persisted credentials break something, the job fails before publishing anything, and reverting this commit restores the previous behavior.

Evidence

  • Pins are behavior-neutral: for each action, git ls-remote --tags showed the moving tag (v5, v4…) and the pinned exact tag resolve to the same commit.
  • Static scan: zizmor (offline) reports no high-severity finding on these workflows after the change (before: unpinned actions, plus credential persistence in the release job). The remaining medium findings concern the PR check jobs, which never receive secrets from forks.
  • YAML parses for every changed workflow file.

@nantoniazzi nantoniazzi self-assigned this Nov 23, 2026
A tag can be moved to point at other code if the action repository is
compromised. Each action is pinned to the commit its tag points at
today, so behavior is unchanged, with the version kept in a comment for
Dependabot and readers.
semantic-release authenticates through the GITHUB_TOKEN env var, so the
checkout does not need to leave the token in .git/config where
dependency install scripts could read it. Install scripts stay enabled
because native or prepare-time dependencies of this package need them.
@nantoniazzi
nantoniazzi force-pushed the ci/harden-github-actions branch from 15379a2 to e5abee4 Compare November 23, 2026 16:12
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