Skip to content

ci: harden GitHub Actions workflows - #1

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 and skips dependency install scripts (persist-credentials: false on checkout, npm ci --ignore-scripts). The build still runs explicitly, and 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.
  • --ignore-scripts only in the release job. I checked package-lock.json: no dependency used on Linux needs an install script here (fsevents is macOS only; esbuild 0.19, where present, gets its binary from an optional dependency and works without its script). The PR check job keeps a plain npm ci, since a pull request from a fork never sees the secrets anyway.
  • 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.
The release job no longer persists the GITHUB_TOKEN in .git/config
(semantic-release authenticates through the GITHUB_TOKEN env var) and
installs dependencies with --ignore-scripts, so a compromised package
cannot run code next to the npm token. No Linux dependency of this
package needs an install script; the build still runs explicitly.
@nantoniazzi
nantoniazzi force-pushed the ci/harden-github-actions branch from 26d7f94 to cdfdf03 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