October 12, 2026

Security Advisory: Rust Miri Environment Variable Leakage and CI Caching Risks

security-advisory-rust-miri-environment-variable-leakage-and-ci-caching-risks

security-advisory-rust-miri-environment-variable-leakage-and-ci-caching-risks

The Rust Security Response Team has issued a critical advisory regarding a potential security vulnerability involving the Rust Miri tool. Under specific configurations within GitHub Actions, Miri’s practice of persisting environment variables to the target/ directory could inadvertently expose sensitive secrets to untrusted pull requests. While this behavior does not constitute a traditional software exploit, it creates a significant risk vector when integrated into modern continuous integration (CI) workflows that utilize persistent caching.

Main Facts: The Intersection of Miri and CI Caches

At the heart of the issue lies the way Miri handles environment variables. To function correctly, cargo miri requires certain build-relevant environment variables to persist across multiple execution runs. Historically, the implementation achieved this by writing these variables directly into the target/ directory.

The vulnerability arises when developers implement standard GitHub Actions caching practices. Many Rust projects cache the target/ directory—the location where compiled artifacts are stored—to accelerate CI build times. Because the cache is often configured to allow writes from runs on the main branch, these cached artifacts become accessible to subsequent jobs, including those triggered by pull requests (PRs).

If a project’s CI environment includes sensitive information, such as API tokens, cryptographic keys, or credentials stored as environment variables, Miri effectively "packages" these secrets into the cache. An attacker capable of submitting a PR can trigger a CI run that extracts these variables from the cached target/ directory. By then pushing a follow-up commit to "clean up" or overwrite their activity, a malicious actor could exfiltrate these secrets while evading standard auditing logs.

Chronology of Discovery and Remediation

The issue was brought to light by security researcher Predrag Gruevski of OpenAI, who identified the risk during an audit of build-time behaviors. Upon notification, the Rust Security Response Team initiated a comprehensive investigation and ecosystem analysis.

  • Initial Notification: The team was alerted to the potential for secret leakage through cached build artifacts.
  • Verification: Internal testing confirmed that Miri was indeed serializing environment variables into the target/ folder, which, when cached, allowed read-access to the environment state of previous, privileged builds.
  • Ecosystem Scan: The team utilized resources provided by OpenAI to scan GitHub repositories. This scan identified one repository actively exhibiting the vulnerability and seven additional repositories that, while not currently vulnerable, were operating under risky configurations.
  • Remediation Development: The team developed a patch to restrict the environment variables saved by Miri to only those necessary for its operation—specifically CARGO_* variables (excluding tokens) and OUT_DIR.
  • Disclosure and Future Release: A formal advisory was prepared, and the fix was slated for the September 22, 2026, nightly release of Rust.

Supporting Data: Understanding the Attack Vector

To understand why this is a significant issue, one must look at how CI environments interact with untrusted contributions.

The Trust Boundary in CI

GitHub Actions provides a "read-only" cache model for PRs to prevent cache poisoning. However, this safety mechanism is a double-edged sword. While it prevents a PR from modifying the cache, it allows the PR to read whatever data was previously stored by a more privileged build (such as a merge to main). If that cache contains secrets written by Miri, the PR essentially gains access to the CI environment’s secrets.

Detection Challenges

The Rust Security Response Team notes that detecting such an attack is difficult. GitHub’s UI sometimes obscures overwritten commits, and CI logs are ephemeral, typically deleted after a few months. This "vanishing" evidence trail makes it difficult for security teams to perform post-incident forensics if they suspect that a repository’s secrets were exfiltrated via the CI cache.

Scope of the Ecosystem Scan

The automated audit of the Rust ecosystem was a proactive measure. By identifying repositories that were likely to be affected, the team was able to provide direct outreach. The fact that only a small number of repositories were flagged suggests that while the vulnerability is systemic to the tool’s design, it requires a specific, "noisy" configuration to be exploitable.

Official Responses and Remediation Guidelines

The Rust Security Response Team has been clear: this is a case of "abundance of caution." The team emphasizes that developers should not rely on build tools to keep their environment variables isolated from build artifacts.

The Short-Term Fix

The immediate solution is the aforementioned patch in Miri, which restricts the scope of what is persisted to target/. Users are advised to update their nightly toolchains as soon as the September 22, 2026, release becomes available.

Recommendations for Repository Maintainers

For those concerned they may be affected, the team suggests the following steps:

  1. Review Workflow Configurations: Examine all GitHub Actions workflows that cache the target/ directory.
  2. Audit Secret Exposure: Ensure that secrets are not exposed to the entire job environment if they are not explicitly required for every build step.
  3. Clear the Cache: After applying the patch, maintainers should manually trigger a cache invalidation or deletion via the GitHub Actions dashboard to ensure that any "tainted" artifacts are removed.
  4. Rotate Secrets: Out of an abundance of caution, any project that suspects its secrets may have been exposed should perform a full rotation of API tokens and credentials that were present in the CI environment.

Broader Implications: The "Secret-in-Cache" Problem

The Miri vulnerability serves as a broader warning for the software engineering community. It highlights a common but often overlooked danger: assuming that CI build processes are "sandbox-safe."

The Myth of Build-Time Security

Many developers assume that because a build process is running inside a container or a virtual machine, the environment is isolated. However, persistent caches—which are essential for modern, high-speed development—act as a bridge across that isolation boundary.

Best Practices for Modern CI

The Rust team suggests that, regardless of whether one uses Miri, the following principles should be treated as standard practice:

  • Principle of Least Privilege: Secrets should only be injected into the specific job steps that absolutely require them. Avoid setting secrets as global environment variables for an entire workflow.
  • Cache Hygiene: Assume that any file written to a cached directory is potentially public. Never store configuration files or environment state that contains sensitive data in these directories.
  • Tooling Awareness: Understand the "side effects" of your build tools. Build systems like Cargo, Miri, and others are optimized for performance, not necessarily for security. If a tool writes to the target/ directory, that data is part of the cache and should be treated as non-confidential.

Acknowledgements

The resolution of this issue was a collaborative effort. The Rust Security Response Team extended their gratitude to Predrag Gruevski of OpenAI for the initial disclosure. Furthermore, the team acknowledged the contribution of OpenAI for providing the computational resources and credits required to perform the extensive ecosystem scan.

The remediation process—spanning triage, technical analysis, and patch implementation—was led by a group of key contributors including Manish Goregaokar, Ralf Jung, Ben Kimock, Weihang Lo, Jacob Finkelman, Walter Pearce, Josh Stone, and Mark Rousskov. Their work ensures that the Rust ecosystem remains resilient against this class of configuration-based vulnerabilities, reinforcing the language’s commitment to security and reliability in modern development environments.