Join our Newsletter — 33% off our NHI Course
Home› Guides› GitHub Actions Cache Poisoning: How Shared Build Caches…
Guide Software & AI Supply Chain

GitHub Actions Cache Poisoning: How Shared Build Caches Become a Supply Chain Path

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 14 min read
On this page

A GitHub Actions cache is shared state that later jobs restore and trust without checking, so one low-trust workflow that can write a cache entry can quietly change what a release build ships. Cache poisoning needs no stolen secret and leaves nothing in the source tree: the tampering happens in the files a build pulls back from the cache. This guide explains how Actions caching is scoped, how poisoning happens at a conceptual level, and the customer-side settings that close the path, including the cache-mode key, trust separation between workflows and least-privilege tokens. It is written for DevSecOps and platform engineers who own GitHub Actions pipelines and goes deeper on one topic than the broader GitHub and GitHub Actions Security Guide.

This is an independent guide from NHI Mgmt Group, based on GitHub's public documentation as of November 2026. It is not sponsored or reviewed by GitHub. Product features change, so confirm settings against GitHub's current documentation.

Key takeaways

  • The default branch cache is the prize. Runs restore caches from their own branch and from the default branch, so whatever writes a default-branch cache entry can influence every later build that restores it.
  • Restored content is not verified. GitHub states that cache contents are not signed or verified, and its documentation warns that anyone with read access can open a pull request and access a cache's contents, so caches must never hold secrets and must be treated as untrusted input.
  • Low-trust triggers are the usual entry. pull_request_target, issue_comment, workflow_run and issue-driven automation (including AI triage agents) run in the default branch context; if they execute attacker-influenced code they sit next to the release cache.
  • Use cache-mode deliberately. Since 10 September 2026 workflows and jobs can declare read, write, write-only or none; low-trust events default to read, and release jobs that hold publishing credentials are best set to none.
  • Release integrity beats build speed. SLSA Build L3 requires that one build cannot inject false entries into a cache used by another and that output is identical with or without the cache: the simplest way to meet that for releases is not to restore caches there at all.

How Actions caching works

The actions/cache action (and the built-in caching in setup actions such as actions/setup-node) saves a set of paths, typically dependency directories like ~/.npm, ~/.m2 or ~/.cache/pip, as an archive under a key. A later job asks for that key and the archive is extracted back onto the runner. Points from GitHub's dependency caching reference that matter for security:

  • Lookup order: an exact match on key first, then prefix matches, then each restore-keys entry in order, then the same search against the default branch. For partial matches the most recent cache wins.
  • Immutability: an existing cache entry cannot be changed; a new entry needs a new key. This protects an entry once written, but it also means the first writer of a key decides its contents.
  • Version stamp: each entry carries a version derived from its path and compression tool, so a job only matches caches it can decompress. The version is metadata, not an integrity check of the contents.
  • Limits: keys can be at most 512 characters; the default storage limit is 10 GB per repository (configurable, with usage beyond it billed); entries not accessed in over 7 days are removed; and when the limit is reached the least recently accessed entries are evicted first.
  • No secrets: GitHub's guidance is "Don't store sensitive information in a cache"; store credentials as Actions secrets instead.

Independent research by Adnan Khan (May 2024, updated January 2025) adds that the values deciding a cache hit are set client-side, so the service does not check that an archive's contents match the key or the declared paths. GitHub has since stopped cache writes after a job finishes, but anything that runs inside a job with cache access can still save entries while the job runs.

Cache scope and branch rules

Scope is the main defence GitHub provides, and it is branch based. The table summarises the restore rules from the dependency caching reference.

Run contextCan restore caches fromCannot restore fromSecurity note
Push to a feature branchThat branch, then the default branchChild or sibling branchesFeature branches inherit default-branch entries, so a poisoned default entry spreads downwards
pull_request (including from forks)The pull request merge ref, the base branch (including a fork's base branch) and the default branchOther pull requests and sibling branchesCaches saved by the pull request run are scoped to the merge ref and only reused by re-runs of that pull request
Tag pushThat tag and the default branchDifferent tag namesRelease-by-tag jobs still fall back to default-branch entries
Push or schedule on the default branchThe default branchOther branchesTrusted trigger: default cache-mode is write
pull_request_target, issue_comment, workflow_runThe default branch (read-only)Not applicableLow-trust trigger: default cache-mode is read; an explicit write mode removes that protection

The pattern is that trust flows down from the default branch. Pull request runs from forks cannot write into the default scope on their own, which is why poisoning almost always needs code execution in a workflow that runs in the default branch context.

The cache-mode key

GitHub's changelog of 10 September 2026 introduced cache-mode, generally available on github.com for all plans, to "apply least-privilege access to the GitHub Actions cache at the workflow or job level". It is a top-level workflow key, overridable per job with jobs.<job_id>.cache-mode, and the cache service enforces it.

ValueRestoreSaveTypical use
readYesNoDefault for low-trust events; test and lint jobs that only consume caches
writeYesYesDefault for trusted events such as push; a dedicated, trusted cache-warming job
write-onlyNoYesA clean job that builds dependencies from the lockfile and publishes a fresh cache without consuming an older one
noneNoNoRelease, signing and publishing jobs; jobs that run AI agents or other untrusted automation

When a mode blocks an operation, the cache step logs an informational message and the job continues. In reusable workflows a called workflow cannot receive more cache access than its caller granted. Declaring write or write-only on a low-trust trigger overrides the read-only default, and GitHub adds a warning annotation when that happens.

How poisoning happens

This is the defender's model of the attack path, without procedure. Poisoning maps to ATT&CK T1677 Poisoned Pipeline Execution, with the downstream effect of T1195.002 Compromise Software Supply Chain when a tampered artefact is published.

  1. Foothold in the default branch context. An attacker gets code to run in a workflow that shares the default-branch cache scope: a pull_request_target job that checks out and builds pull request code, a script injection through a branch name or issue title (see the GitHub Actions Script Injection Guide), a compromised third-party action, a malicious dependency install script, or an AI agent prompted through issue text.
  2. Write a cache entry a trusted job will restore. With cache access from inside that job, the attacker saves an entry under a key or prefix that a release or nightly job looks up. Eviction behaviour and broad restore-keys make it easier for the attacker's entry to be the one selected.
  3. Trusted job restores and runs it. The release job extracts the archive and executes tools or dependencies from it with its own token, OIDC identity and publishing secrets.
  4. Signed, attested and wrong. The release workflow signs or attests its output as normal. Provenance proves which workflow built the artefact, not that its inputs were clean.

The Ultralytics PyPI compromise is the reference case: a pull_request_target workflow with an injectable branch name gave the foothold, and investigators believe the payload poisoned the Actions cache that the Trusted Publishing release job restored, so the legitimate pipeline published releases containing a cryptominer. In early 2026 a researcher reported that the Cline project's AI issue-triage workflow, which put issue titles into an agent prompt, shared a cache scope with nightly publishing workflows; the project's fix removed the triage workflows and stopped publish workflows from using the cache.

Defences

Separate workflows by trust

  • Build untrusted code under pull_request: it runs in an isolated scope with a read-only token and no secrets for forks. GitHub's secure use reference says to avoid pull_request_target if it is not necessary and that such workflows "must not explicitly check out untrusted code".
  • Two-stage pattern for write actions: do the build in pull_request, then do the privileged step (commenting, labelling) in a workflow_run workflow that treats uploaded artefacts as passive data and extracts them to runner.temp, never the workspace.
  • Avoid label gates as a fix: GitHub Security Lab notes that "safe to test" label checks are prone to a race condition and should only be a temporary measure. To find exposed workflows, see How to Find GitHub Workflows Exposed to pull_request_target.
  • Treat AI agents as untrusted code: any workflow where an agent reads issue, comment or pull request text gets cache-mode: none, a read-only token and no publishing secrets.

Set cache-mode per job

  • Set a workflow default: cache-mode: read at the top of most workflows, then grant write only to the single job meant to warm the cache.
  • Release jobs: cache-mode: none for any job that signs, attests, publishes packages or deploys to production. Accept the slower build.
  • Never widen low-trust triggers: treat a warning annotation for a write mode on a low-trust trigger as a defect, and block it in review.

Cache key hygiene

PracticeWhy it helps
Key on runner.os plus hashFiles() of the lockfile (for example package-lock.json, poetry.lock, go.sum)An exact key is tied to the declared dependency set, so stale or unrelated entries do not match
Keep restore-keys narrow or drop them in sensitive workflowsBroad prefixes restore "the most recent" matching entry, which is the easiest one to plant
Prefix keys by purpose and trust level (for example ci- versus rel-)Stops a test job's cache being picked up by a release lookup
Cache downloaded packages, not build outputs or tools that executePackage managers can re-verify downloads against lockfile hashes; compiled binaries and toolchains cannot be checked so easily
Re-verify after restore (lockfile integrity check, npm ci, pip install --require-hashes, go mod verify)Turns the cache into an accelerator rather than a source of truth
Never cache paths that hold credentials, such as ~/.npmrc, ~/.docker/config.json or cloud CLI configCache contents are readable through pull requests

Least privilege tokens and identities

  • Read-only default: set the organisation default for GITHUB_TOKEN to read-only contents and grant more per job in permissions:. See How to Restrict GITHUB_TOKEN Permissions in Workflows.
  • actions: write only where needed: this scope lets a token manage workflow runs and is used for cache deletion; do not give it to jobs that process untrusted input.
  • Separate release identities: nightly and production publishing should not share one publishing credential or OIDC trust policy. Scope cloud OIDC trust to the release workflow file and protected environment; see the GitHub Actions OIDC Federation Hardening Guide.
  • Protected environments: put publishing secrets in an environment with required reviewers and branch or tag restrictions, so a poisoned nightly job cannot reach them.
  • Pin actions to full commit SHAs: a compromised action is one of the easiest ways into the default branch context. See How to Pin GitHub Actions to Commit SHAs.

Choosing an approach

For a small project with one maintainer, the minimum is: no pull_request_target that runs pull request code, read-only token default, SHA-pinned actions and no cache in the publish job. Large organisations with many repositories should add an organisation-wide workflow policy (required workflows or rulesets that block write modes on low-trust triggers), a dedicated cache-warming workflow per repository, and periodic scans of workflow files for risky triggers. Where build time on releases really matters, use write-only in a trusted job to produce a clean cache from the lockfile, and keep the release job itself on none.

Detection

Poisoning rarely shows in source control, so detection focuses on workflow configuration, cache activity and build behaviour.

  • Workflow configuration: alert on new or changed workflows that use pull_request_target, workflow_run or issue_comment with a checkout of the pull request head, on cache-mode: write or write-only on those triggers, and on warning annotations about cache write access. Code scanning queries for Actions help here.
  • Cache inventory: review the Caches page (Actions tab, Management) or run gh cache list on a schedule; look for default-branch entries created by workflows that should only read, unexpected keys matching release prefixes, and unusual entry sizes.
  • Audit log: watch for changes to Actions permissions, allowed actions and workflow settings in the organisation audit log; see the GitHub Audit Log Detection Guide.
  • Build behaviour: compare release artefacts built with and without cache (reproducible build check), and watch runners for unexpected outbound connections during scheduled jobs.
  • Response: if poisoning is suspected, delete affected entries (users with write access can delete from the UI, or use gh cache delete or the REST API), rebuild releases with caching off, and rotate any credentials the restoring jobs could reach. The CI/CD Pipeline Compromise Playbook covers the wider response.
MetricTarget
Release and publish jobs with cache-mode: none100%
Workflows using pull_request_target that check out pull request codeZero
Repositories with read-only GITHUB_TOKEN default100%
Third-party actions pinned to full commit SHAAbove 95%, trending to 100%
Cache keys derived from lockfile hashes in CI workflows100% of caching workflows
Releases verified as identical with and without cacheEvery release for projects that claim SLSA Build L3

Framework mapping

FrameworkReferenceHow it applies
MITRE ATT&CKT1677 Poisoned Pipeline Execution; T1195.002 Compromise Software Supply ChainFoothold in the pipeline and the resulting tampered release
SLSA v1.0Build L3, IsolatedNo cross-build cache injection; output identical with or without cache
NIST SP 800-53 Rev 5SA-10, SA-15, CM-5, SI-7, AC-6, SR-4Developer configuration management, process and tools, change access restrictions, integrity, least privilege, provenance
NIST CSF 2.0PR.PS-01, GV.SC-07Configuration management of pipelines; supplier and dependency risk

Practitioner checklist

  • Inventory every workflow using pull_request_target, workflow_run, issue_comment or issue-driven AI agents, and remove any checkout or execution of untrusted code.
  • Set cache-mode: none on all release, signing, publishing and deployment jobs.
  • Set cache-mode: read as the workflow default and grant write to one trusted cache-warming job.
  • Derive cache keys from lockfile hashes, prefix them by purpose and remove broad restore-keys from sensitive workflows.
  • Re-verify dependencies after restore and never cache credential files or executable build outputs.
  • Make GITHUB_TOKEN read-only by default and keep actions: write out of untrusted jobs.
  • Separate nightly and production publishing credentials and protect release secrets with environments.
  • Pin third-party actions to full commit SHAs and restrict allowed actions.
  • Schedule a cache inventory review and know how to purge entries and rotate credentials if poisoning is suspected.

Standards and references

Related NHI Mgmt Group resources: GitHub and GitHub Actions Security Guide · How to Pin GitHub Actions to Commit SHAs · Software Supply Chain Security Guide · CI/CD Pipeline Identity Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.