Security Advisory: Persistent Secret Exposure in Miri’s Build Caching Mechanism

The Rust Security Response Team has issued a critical advisory regarding a potential security vulnerability discovered within Miri, the Rust interpreter used for detecting undefined behavior in Rust programs. The issue concerns how Miri handles environment variables during the build process, specifically regarding their persistence within the target/ directory. When combined with common continuous integration (CI) workflows—particularly those leveraging GitHub Actions caching—this behavior creates a mechanism through which sensitive secrets could be exposed to unauthorized parties via pull requests (PRs).
While the Rust team has moved quickly to implement a targeted fix, the incident serves as a significant wake-up call for the broader developer community regarding the intersection of build-system artifacts, CI/CD caching strategies, and secret management.
Main Facts: The Intersection of Miri and CI Caching
The core of the issue lies in how Miri facilitates its execution. To ensure consistency between build sessions, Miri has historically retained environment variables by serializing and writing them directly into the target/ directory. This design choice, intended to maintain build-relevant state, effectively embeds the entire environment of the CI runner into the project’s build artifacts.
The GitHub Actions Connection
Modern CI/CD pipelines, particularly those hosted on GitHub Actions, rely heavily on caching to reduce build times. A standard configuration involves caching the target/ directory across multiple workflow runs. In a typical secure setup, branches like main or develop are granted write access to the cache, while PRs are restricted to read-only access. This architecture is designed to prevent "cache poisoning," where an untrusted contributor could theoretically manipulate build artifacts.
However, the vulnerability arises because the cache is persistent. If a CI job that has access to sensitive environment variables (such as API keys, deployment tokens, or signing secrets) writes to the target/ directory, those secrets are effectively "baked" into the cache. Because Miri stores the entire environment, those secrets remain embedded in the cached files.
The Attack Vector
An attacker with the ability to open a PR against a repository can trigger a CI run. Because the runner may pull the cache created by a trusted branch, the environment variables stored by Miri during that trusted build become accessible to the untrusted PR. By executing a simple malicious script within the PR’s CI job, an attacker can extract the contents of the target/ directory and, by extension, the secrets persisted therein. The attacker can then overwrite their commits to hide the evidence of the extraction, exploiting the fact that GitHub’s interface occasionally obscures overwritten commit histories.
Chronology of Discovery and Remediation
The vulnerability was brought to the attention of the Rust Security Response Team by Predrag Gruevski, a security researcher at OpenAI. Following the initial disclosure, the team launched a comprehensive investigation to assess the scope of the risk.
- Initial Discovery: Upon notification, the Rust team initiated an internal audit of the Miri codebase to determine the extent of the environment variable persistence.
- Ecosystem Scan: Utilizing resources and computing credits provided by OpenAI, the team performed a large-scale scan of GitHub repositories to identify how many projects were potentially impacted by this specific configuration.
- The Fix: On September 22, 2026, the team finalized a patch for the Miri nightly build. The fix restricts the environment variables stored by Miri to only essential
CARGO_*prefixes (explicitly excluding sensitive*_TOKENvariables) andOUT_DIR. - Outreach: The team identified eight repositories in the wild that were potentially vulnerable and initiated direct contact with the maintainers to ensure they were aware of the risk and could take corrective action.
Supporting Data: Ecosystem Vulnerability Analysis
The ecosystem scan conducted by the Rust team highlights a nuanced reality: while the specific Miri behavior was the trigger, the underlying architectural risks are widespread.
Out of the repositories analyzed, the scan identified:
- Directly Impacted: One repository was found to be actively storing secrets in a way that was accessible through the cache.
- Cautious Cases: Seven repositories were identified as having configurations that, while not immediately leaking secrets, were architecturally unsound and could easily become vulnerable if project configurations changed.
The team emphasizes that the scan was inherently imperfect due to the diversity of CI configurations. Consequently, they urge all Rust developers who use Miri to treat their current cache as potentially compromised.
Official Responses and Remediation
The Rust Security Response Team, led by experts including Manish Goregaokar, Ralf Jung, and others, has provided clear, actionable guidance for the community.
Immediate Mitigation Steps
For developers who use Miri in their CI pipelines, the recommended course of action is two-fold:
- Clear the Cache: It is imperative to invalidate and purge existing GitHub Actions caches to remove any artifacts containing leaked environment variables.
- Rotate Secrets: If there is any suspicion that a secret was available in an environment where Miri was running, that secret must be considered compromised and should be rotated immediately.
Long-Term Architectural Changes
The current fix is considered a "short-term" solution. The Rust team is actively exploring more robust mechanisms for passing build-relevant environment variables to Miri without requiring them to be written to disk. This involves tighter integration with Cargo to ensure that only the variables strictly necessary for compilation are persisted, rather than the entire shell environment.
Implications: The Broader Security Context
Perhaps the most significant takeaway from this incident is the warning issued to the entire development community—not just those using Miri.
The "Hidden" Danger of CI Caching
Many developers assume that build artifacts are "safe" or "ephemeral." This incident highlights that in a modern CI/CD environment, the cache is a long-lived repository of metadata. If any tool—whether it is a compiler, a linter, or a test runner—blindly dumps the environment into a file that gets cached, you have effectively created a backdoor for anyone who can influence the CI process.
Best Practices for Secrets in CI
The Rust team’s response includes a stern reminder regarding the "principle of least privilege" in CI:
- Isolate Secrets: Never expose secrets to CI jobs that do not strictly require them. If a job is only running tests or builds, it should not have access to deployment tokens or production database credentials.
- Assume Taint: Treat the entire
target/directory as potentially tainted. If your CI system caches this directory, assume that any process with write access to the CI environment can read what is inside it. - Tooling Awareness: Developers must recognize that most build tools do not have built-in "secret scrubbing." They are designed for performance and reliability, not necessarily for security in a multi-tenant or untrusted PR environment.
A Call to Vigilance
The fact that this issue was caught by a third-party researcher using advanced scanning techniques demonstrates the difficulty of identifying such "silent" vulnerabilities. As the Rust ecosystem continues to grow, the complexity of build systems will only increase. Maintaining a secure supply chain requires more than just patched software; it requires a proactive, defensive posture regarding how we handle environment state in automated environments.
The team concluded their report by expressing gratitude to those involved in the triage, specifically acknowledging the contribution of OpenAI for the resources provided for the ecosystem scan. As of the nightly release on September 22, 2026, the vulnerability is addressed, but the lesson remains: the cache is not a sandbox, and your environment variables are only as safe as the most insecure tool that touches them.
For those looking to secure their pipelines, the Rust team recommends a comprehensive review of all GitHub Actions workflows to ensure that secrets are scoped only to the specific jobs that absolutely require them, and that caching is not inadvertently enabling horizontal movement for attackers within the CI/CD pipeline.
