Executive Summary & Direct Answer

If a GitHub Actions job runs cargo miri with secrets in its environment and caches target/, those secrets may be written into cacheable artifacts. A pull-request workflow that can restore a cache may then expose data left by a trusted run, even when the pull-request job cannot write to that cache. The durable fix is to keep secrets out of every process that populates shared caches, use a Miri release that limits persisted environment variables, and clear affected caches. Scoping secrets to a later, separate step is safer than relying on tool-specific redaction.

This issue is about the interaction between Miri’s environment handling and GitHub Actions cache access—not a general guarantee that Rust build artifacts are secret-free. Treat anything that runs while secrets are available as capable of writing them to disk.

Environment and baseline

This guide targets Rust 1.82+ (Edition 2021) for the project, with nightly Rust for Miri. cargo miri requires the nightly toolchain; pin a specific nightly in CI rather than letting it float. The Rust Blog reported that the Miri release in the 2026-09-22 nightly no longer had this behavior. Confirm the behavior against the exact nightly you pin; do not assume an older nightly has the fix.

The relevant components are GitHub Actions, Cargo’s target/ directory, Miri, and a cache action such as actions/cache or swatinem/rust-cache. The problem does not require a vulnerable application dependency or a particular Rust edition. It arises when a process can see a secret, writes environment information into target/, and that directory is later restored by a less-trusted workflow.

How the exposure happens

Miri needs to retain build-relevant environment variables between invocations of cargo miri. In the reported implementation, it stored all environment variables under target/. Since target/ is commonly cached for faster CI, a cache could contain values that were present in the Miri job’s environment.

GitHub Actions cache permissions make this relevant to pull requests: workflows on the base branch can commonly create caches that pull-request workflows can restore, while PR workflows are prevented from writing to the base branch’s cache scope. That write restriction helps prevent cache poisoning, but it does not make cached contents confidential. A PR that can read a cache can potentially inspect files in it.

This creates a chain:

  1. A trusted workflow exposes a token or other secret to a step that runs cargo miri.
  2. Miri or another process writes environment-derived data below target/.
  3. The workflow saves target/ to a cache accessible to PR runs.
  4. A PR workflow restores the cache and accesses the persisted data.

A malicious contributor who can open or update a PR may be able to trigger a run that reads accessible cache contents. Approval requirements for a first-time contributor do not protect against all later runs. The security boundary is therefore not “can this workflow write the cache?” but also “who can restore it, and what sensitive data did the cache-producing process see?”

The risky workflow pattern

A broad workflow-level environment is a common source of accidental exposure:

# Risky: the token is present for the Miri process.
env:
  PRIVATE_REGISTRY_TOKEN: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}

jobs:
  miri:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: swatinem/rust-cache@v2

      - run: cargo miri test

Even if the token is only needed for publishing or a private registry, setting it at workflow or job scope makes it available to commands that do not need it. Depending on cache-action configuration, target/ may be saved after the Miri run. Do not treat masking in logs as protection: a masked log value can still have been written to a file and persisted in a cache.

A safer workflow separates untrusted-test work from secret-bearing work. Run Miri without secrets, and only provide credentials to the specific later step that needs them:

name: Rust checks

on:
  pull_request:
  push:
    branches: [main]

jobs:
  miri:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: nightly-2026-09-22
          components: miri

      # Cache only if this job and its toolchain are reviewed.
      - uses: swatinem/rust-cache@v2

      - run: cargo miri setup
      - run: cargo miri test

This example deliberately grants no application secret to the Miri job. If a later publishing step needs a token, put it in that step’s env, not at workflow or job level. Prefer a separate job with narrowly scoped permissions and no shared target/ cache. A step-level environment is not a substitute for reviewing every command in that step: any executable invoked there can read the variable.

Short-term containment

If you cannot confirm that the pinned Miri version includes the fix, use one of these controls immediately:

  • Disable caching for the Miri job, especially caching all of target/.
  • Remove secrets from the job and any preceding step that exports them into a persisted environment.
  • Temporarily disable Miri in workflows that must receive secrets.
  • Clear caches that may have been produced by a secret-bearing Miri run.
  • Rotate credentials that could have been exposed.

The Rust-side mitigation reported by the Rust Security Response Team narrows what Miri preserves: it keeps CARGO_ variables except CARGO__TOKEN, and OUT_DIR, rather than saving every environment variable. This reduces the particular exposure path, but it is not a general promise that target/ is safe for secrets. Build scripts and other tools can still write environment-derived values to disk.

Compare the controls

ApproachSecret-bearing variables visible to MiriCache exposure surfaceOperational cost
Job-wide secrets plus cached target/All variables in job environmentHigh: artifacts may persist valuesLow initially; unacceptable risk
Patched Miri, but job still receives secretsSecrets remain visible to other processesReduced for this Miri behavior; not eliminatedLow
Miri job receives no secretsNone, if no earlier step exports themLow for secret leakage through this jobRequires separating secret-dependent work
No target/ cache for Miri jobSecrets may still reach local artifacts during the runLower persistence through that cache; other artifact paths remainSlower CI
No secrets and no shared cacheNoneLowest exposure for this pathHighest CI runtime or infrastructure cost

These are security-surface comparisons, not benchmark results. Actual runtime savings from caching depend on the workspace, runner, and cache hit rate. The decisive metric is whether a cache-producing process can see a credential—not whether a cache action successfully masks log output.

Production pitfalls and edge cases

Check inherited environments, not just YAML placement. A token may be exported by a previous shell step, written to GITHUB_ENV, injected by a reusable workflow, or supplied by an action. Search workflow files and reusable workflows for env:, GITHUB_ENV, and secret references. A job with no obvious env: block can still inherit sensitive values through a preceding step.

Review every cache path. target/ is the reported risk, but caches may include custom target directories, Cargo home directories, generated files, or build outputs elsewhere. Conversely, turning off one cache action is insufficient if another action restores or saves the same material.

Do not rely on cache keys for confidentiality. A unique key can reduce accidental collisions but does not make a cache private from workflows that are authorized to restore it. Cache scopes and branch behavior are access controls; verify which events can read each cache in your repository’s actual workflow configuration.

Treat build scripts as code that can persist inputs. Cargo and Rust do not guarantee that environment variables are safe from being copied into compilation artifacts. A dependency’s build.rs can read its environment, and non-Miri tooling may persist values too. Avoid giving build and test jobs credentials unless strictly necessary.

Clear, then rotate where appropriate. After removing the exposure, delete relevant caches so a later PR cannot restore old contents. If a secret was available to an affected job and the cache could be read by untrusted PR workflows, treat it as potentially exposed: revoke or rotate it, then check its use in provider audit logs. Deleting a cache does not undo a copy already made.

Keep cache permissions least-privileged. Use narrowly scoped permissions for GITHUB_TOKEN; avoid granting write access to PR jobs unless required. This limits other attack paths but does not prevent reading a cache that the job is allowed to restore.

Verification workflow

First inventory the toolchain and cache behavior in the workflow. Pin nightly and print the active versions so a CI log proves which Miri was used:

- run: |
    rustc --version --verbose
    cargo --version
    cargo miri --version

Then verify the workflow structurally:

  1. Confirm the Miri job has no secret references in workflow-, job-, or step-level environment, and does not receive values through GITHUB_ENV.
  2. Confirm whether cache actions include target/ and which events can restore those entries.
  3. Run the Miri job with a canary value in a local, disposable test environment only, not a real credential. Inspect the resulting target/ tree for that unique marker. This is a regression check for the specific toolchain and workflow path, not proof that arbitrary build tools cannot persist data.
  4. Test pull-request workflows from a fork or an appropriately restricted test repository. Confirm the intended cache read/write behavior without introducing real secrets.
  5. After remediation, delete relevant cache entries and rotate any credential that was exposed to an affected run.

Useful repository checks include:

grep -RInE 'secrets\.|GITHUB_ENV|PRIVATE_.*TOKEN|RUST.*TOKEN' .github/workflows
cargo +nightly-2026-09-22 miri test

The grep is an inventory aid, not a complete security proof: reusable workflows, actions, and shell scripts can pass values indirectly. Review those dependencies and generated environment files as well. For general CI hygiene, keep credentials out of unrelated tooling; for example, registry credentials should not be exposed to a Miri test job simply because a different job publishes packages. Where credentials must be handled, apply the scoping and lifecycle practices in Preventing Unsafe Secret Storage in Rust: Encrypting, Scoping, and Rotating Sensitive Data.

Frequently Asked Questions (FAQ)

Does the 2026-09-22 nightly fix make caching target/ safe?

No. The Rust Blog reported that this nightly’s Miri no longer stored all environment variables, retaining only selected CARGO_ variables (excluding CARGO__TOKEN) and OUT_DIR. Other tools, including build scripts, may still write sensitive data into build artifacts. Keep secrets out of cache-producing jobs whenever possible.

Can a pull request read a GitHub Actions cache written by main?

It may be able to restore caches available within GitHub Actions’ cache scope, depending on the event, branch, and workflow configuration. Preventing a PR from writing to a base-branch cache does not make that cache unreadable. Check the actual cache action and event permissions used by your repository.

What should I do if a secret was available to a cached Miri run?

Remove the secret from the workflow, delete caches produced by affected runs, and rotate or revoke credentials that could have been exposed. Review provider audit logs for suspicious use. Cache deletion prevents future restoration of that entry but cannot recover data already copied from it.

Learn more with useful resources