Skip to content

Commit cad232f

Browse files
authored
Prevent cache poisoning vuln in GitHub Actions sample workflows (#1935)
The PR #1917 bumped the `actions/setup-node` action from v4 to v6. This made the publishing GitHub Actions sample workflows potentially vulnerable to cache poisoning, because v5 and later enable caching by default (see https://github.com/actions/setup-node/blob/53b83947a5a98c8d113130e565377fae1a50d02f/README.md#breaking-changes-in-v5). v6 only enables automatic caching if the `packageManager` field in package.json is set to `npm`. Consuming GitHub Actions cache in publishing workflows is discouraged, because the cache may be poisoned by compromising any low-privileged workflow in the same repository. Normally, a code injection vulnerability in a low-privileged workflow (for example `permissions: {contents: read}` and no secrets) is not a big deal, because the attacker cannot do much more than poison the repository cache (which requires no permissions). If caching is only used in other low-privileged workflows, the impact is limited. However, if a high-privileged workflow like the release build consumes the cache, then it becomes a real problem. As @AdnaneKhan concludes in his blog posts about GitHub Actions cache poisoning, such as https://adnanthekhan.com/2024/05/06/the-monsters-in-your-build-cache-github-actions-cache-poisoning/#dont-use-actions-caching-in-release-builds: "the best way to protect the integrity of releases is to avoid using GitHub Actions caching entirely for release workflows." The README of `actions/setup-node` also recommends `package-manager-cache: false` for privileged workflows (see https://github.com/actions/setup-node/blob/53b83947a5a98c8d113130e565377fae1a50d02f/README.md#breaking-changes-in-v5): > For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation. ## References Related to #1917
1 parent e93dc35 commit cad232f

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

content/packages-and-modules/securing-your-code/generating-provenance-statements.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ jobs:
9191
contents: read
9292
id-token: write
9393
steps:
94-
- uses: actions/checkout@v4
95-
- uses: actions/setup-node@v4
94+
- uses: actions/checkout@v6
95+
- uses: actions/setup-node@v6
9696
with:
97-
node-version: '20.x'
97+
node-version: '24.x'
9898
registry-url: 'https://registry.npmjs.org'
99+
package-manager-cache: false # never use caching in release builds
99100
- run: npm ci
100101
- run: npm publish --provenance --access public
101102
env:

content/packages-and-modules/securing-your-code/trusted-publishers.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ jobs:
106106
with:
107107
node-version: '24'
108108
registry-url: 'https://registry.npmjs.org'
109+
package-manager-cache: false # never use caching in release builds
109110
- run: npm ci
110111
- run: npm run build --if-present
111112
- run: npm test
@@ -298,10 +299,11 @@ While trusted publishing handles the publish operation, you may still need authe
298299

299300
```yaml
300301
# GitHub Actions example
301-
- uses: actions/setup-node@v4
302+
- uses: actions/setup-node@v6
302303
with:
303304
node-version: '24'
304305
registry-url: 'https://registry.npmjs.org'
306+
package-manager-cache: false # never use caching in release builds
305307
# Use a read-only token for installing dependencies
306308
- run: npm ci
307309
env:

0 commit comments

Comments
 (0)