1. Resources
  2. Identity Threats
  3. GitHub

GitHub Actions Artifact and Cache Poisoning

Also known as: Actions cache poisoning, Artifact poisoning, workflow_run artifact abuse, Poisoned build cache

Code that runs in a low-trust GitHub Actions job writes an artifact or cache entry that a privileged release job later downloads and trusts, which moves the attacker into that job.

Platform
GitHub
Impact
High
Last updated
Attack difficulty
High
Detection difficulty
High
Privileges required: Any authenticated identity
For artifacts: a pull request whose build output a privileged workflow consumes. For caches: code execution in any job that runs in the default-branch context.
What the attacker gains
Code execution or tampered inputs in a release or deployment job: its secrets, its write token and the bytes it publishes.

How it works

Artifacts and caches are storage that jobs share. Both carry the trust level of whoever wrote them, and both are read later by jobs that may have far more privileges. An object is harmless while it sits in storage; the attack happens when a privileged consumer reads it and acts on it.

Artifacts. An artifact is output attached to a workflow run. The standard way to handle pull requests from forks safely is a split: an unprivileged pull_request workflow builds the code and uploads an artifact, and a workflow_run workflow, which GitHub starts with access to secrets and write tokens, downloads it and does the privileged part. The first half runs the contributor's code, and in a pull_request run the contributor can also change the workflow file itself, so the artifact's content is entirely attacker-chosen. If the second half unpacks it into the workspace, runs something from it, or publishes it, the attacker has crossed into the privileged job.

Caches. Cache lookup depends on the key, the cache version and the ref scope. A run can restore caches created on its own branch or on the default branch. A cache saved by a pull_request run is created for the merge ref and cannot be restored by the base branch or by other pull requests. So the scope rules protect the default branch from fork runs, but they do not protect it from other default-branch jobs. Workflows triggered by pull_request_target, workflow_run, issue_comment and similar events run in the default-branch context and share its cache.

Three properties make cache entries a good vehicle, as described in Adnan Khan's research:

  • Cache writes are authorized by the job's runtime token, not by the GITHUB_TOKEN. A job with a read-only token can still write cache entries.
  • Keys and versions are strings chosen by the client. The service does not check that an entry's content matches its key.
  • Restoring is an archive extraction that overwrites existing files, and it is not limited to the paths the workflow listed.

An existing entry cannot be changed, so the attacker either writes a key that does not exist yet (a predicted future key, or one that a restore-keys prefix will match, since the most recently created match wins) or forces eviction: repositories have a cache size limit, 10 GB by default, and filling it deletes the least recently used entries.

Prerequisites

  • Artifact route: a workflow_run (or later same-run) job with privileges that downloads an artifact produced by a job running untrusted code, and then extracts it over the workspace, executes it, reads values from it without validation, or publishes it.
  • Cache route: code execution in a job in the default-branch context (a pwn request, a script injection or a compromised action or dependency), and a more privileged workflow on the default branch that restores a cache, typically a release or deployment workflow.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Find producer and consumer pairs

# cache-poisoning flags cache use in release workflows and cache writes from privileged triggers;
# dangerous-triggers flags workflow_run consumers
zizmor --gh-token $(gh auth token) octo-org/octo-repo

export GH_TOKEN=<personal access token>
gato-x enumerate -r octo-org/octo-repo

# Manual: who downloads artifacts, who restores caches
grep -rnE "download-artifact|actions/cache|cache: " .github/workflows/

Read each consumer for what it does with the bytes. The vulnerable artifact pattern looks like this:

# INSECURE: privileged job unpacks a fork-built artifact into the workspace and runs it
on:
  workflow_run:
    workflows: ["Build PR"]
    types: [completed]

jobs:
  publish-preview:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          name: site
          path: .
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
      - run: ./scripts/deploy.sh
        env:
          DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}

2. Artifact route: ship files the consumer will run

Open a pull request from a fork that makes the build produce an artifact with the expected name and the attacker's content. Because the artifact is extracted into the repository root, a file named scripts/deploy.sh in the artifact replaces the trusted script before the next step runs it with DEPLOY_KEY. The same works for any file a later step executes or loads: build configuration, a package manifest, a local action.

Where the consumer does not execute anything, look for values it reads from the artifact, such as a pull request number or a version string, and uses in a script or an API call. A value used in a run step is an injection point.

3. Cache route: get into a default-branch job

Use one of the entry points from the prerequisites. The job does not need a write token or any secret; it only needs to run in the default-branch scope.

4. Cache route: write the entry

From inside that job, the payload takes the runtime token and cache service URL that the runner holds for the job and saves an entry under a key the privileged workflow will restore. Cacheract automates this: it runs in the job's post phase, adds its files to cache archives, creates default-branch entries for keys it has seen or derived from workflow files, and overwrites the checked-out copy of actions/checkout in later runs so that it re-plants itself on every cache hit. Since a change by GitHub, the write has to happen while the job is still running.

List what is in the cache to choose keys and to check the result:

gh cache list --repo octo-org/octo-repo --ref refs/heads/main \
  --json id,key,ref,version,createdAt,lastAccessedAt,sizeInBytes

5. Wait for the privileged consumer

The next release or deployment run on the default branch restores the entry. Files in the archive land in the workspace and tool directories, and the job runs them with its secrets, its write token and, where set, id-token: write. This is lateral movement between workflows of one repository.

Impact

The attacker reaches the most trusted jobs of a repository from the least trusted ones. In a release job that means signing keys, registry tokens and the published bytes; a poisoned release still has a clean source commit, a clean workflow file and valid provenance for the workflow that built it. Cacheract's author notes that a poisoned entry can persist for weeks or months while runs keep the cache warm.

OPSEC and artifacts

  • No source change. Nothing in the default branch changes, and the privileged workflow file stays as reviewed. The evidence is in storage and logs, not in the repository history.
  • Expected names. The attacker uses the artifact name and cache key the consumer expects. The artifact record still shows which run produced it: the REST API returns workflow_run.head_repository_id next to repository_id, and they differ when the producing run came from a fork.
  • Eviction noise. Forcing eviction means writing many gigabytes of junk entries in a short time. They are visible in the cache list with their creation times and sizes.
  • Post-phase execution. Running in the post phase with output suppressed keeps the step log quiet. The cache step still logs the key it restored and the key it matched, which differ when a restore-keys prefix was used.
  • Cleanup. Deleting the poisoned cache entries or the artifact removes the bytes that prove the attack. The deletions are recorded as actions_cache.delete and artifact.destroy. Entries also disappear on their own: unused caches are removed after 7 days and artifacts expire with the retention setting.

Detection

  • Fork-produced artifacts consumed by privileged runs. For each workflow_run consumer, join the consumer run to the artifact it downloaded and check the producer:
gh api /repos/octo-org/octo-repo/actions/runs/1234567890/artifacts \
  --jq '.artifacts[] | {id, name, digest, size_in_bytes, head: .workflow_run.head_sha,
        repo: .workflow_run.repository_id, head_repo: .workflow_run.head_repository_id}'
  • Digest continuity. Compare the artifact's digest at upload with what the consumer processed and with what was published. A digest supplied by the same untrusted producer proves nothing; the comparison needs an independent record.
  • Cache inventory. Review default-branch cache entries for keys no workflow computes, entries created by runs of workflows that should not write caches, sudden growth towards the size limit, and entries created shortly before a release run.
  • Requested key against matched key in the cache step's log. A hit through a restore key on a release build means the build consumed something other than an exact match.
  • Deleted evidence. The workflow run or logs deleted rules alert on deleted runs; cache and artifact deletions outside normal cleanup deserve the same attention.
  • Entry points. The Actions token or fork pull request policy rules cover the settings that decide whether fork runs get more than a read-only token.

A cache hit or a stale dependency alone is not evidence of poisoning. The finding needs the restored bytes, or a published output whose digest differs from an independently built one.

Mitigation

  • Do not restore caches in release and deployment workflows. Build sensitive outputs from the reviewed source and a locked dependency set, every time.
  • Keep untrusted code out of the default-branch context. Fixing pwn requests and script injections removes the cache route's entry point.
  • Handle artifacts as untrusted data. Download by run-id of the triggering run, extract to ${{ runner.temp }} instead of the workspace, validate every value, and do not execute or publish artifact content from the privileged job.
  • Verify provenance before use. Have trusted jobs attest what they build and have consumers check the attestation or an independently recorded digest before they sign or publish.
  • Keep credentials out of caches and artifacts. Anyone with read access can open a pull request and read the caches in its scope, and an artifact outlives the job that made it.
  • Give every job a minimal permissions block, following least privilege, so that a consumer that is tricked has less to lose.
  • After an incident, flush the cache with gh cache delete --all and rebuild, because a poisoned entry survives until it is deleted or evicted.

Detection rules for this attack

Log events to collect

FAQ

What is GitHub Actions cache poisoning?

It is writing a malicious entry into a repository's Actions cache from one job so that a different, more privileged job restores it. Cache restore is a plain archive extraction, so the entry can overwrite build files or tools, and the privileged job then runs the attacker's content.

Does a read-only GITHUB_TOKEN prevent cache poisoning?

No. Cache writes are authorized by the job's runtime token, which is separate from the GITHUB_TOKEN and does not follow the permissions block. A job with a read-only token can still save cache entries in its branch scope.

Can a pull request from a fork poison the cache of the main branch?

Not through a normal pull_request run. Its cache entries are created for the pull request's merge ref and cannot be restored by the base branch. The attacker needs code execution in a job that runs in the default-branch context, such as a pull_request_target job or an injectable workflow.

How do you use workflow_run artifacts safely?

Treat the artifact as untrusted input. Download it by the triggering run's id, extract it outside the workspace, validate every value you read from it, and never execute or publish it from the privileged job without an independent check.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.