What Miri stored and why it mattered
The Rust Security Response Team was notified that Miri stores all environment variables to target/, allowing secrets to persist in caches. [1]
While not necessary a vulnerability in and of itself, when paired with GitHub Actions caching behavior, it is possible for this to expose secrets to PRs. [2]
The current code to do so achieves this by storing all environment variables to target/. [3]
How the cache could be read
PR CI can be triggered by anyone who can open PRs on your repository. [4]
GitHub requires maintainer approval for the first PR, but future PRs will rerun CI on every push. [5]
Anyone who has previously landed a change can trigger a CI run extracting information from cached target/ and then cover their tracks by pushing a second commit to the PR. [6]
The fix and the guidance
Our short term fix for this is to make Miri only preserve CARGO_ environment variables (excepting CARGO__TOKEN) and OUT_DIR. [7]
In the longer term, Miri and cargo may figure out better ways to inform Miri of the relevant list of environment variables. [8]
Even if you do not run Miri, ensure jobs that can write to public caches do not have access to secrets. [9]
If caching target/, it is worth making sure that the inputs to processes that create target/ (anything invoking cargo) do not have secrets available. [10]
Sources
- The Rust Security Response Team source says: The Rust Security Response Team was notified that Miri stores all environment variables to target/, allowing secrets to persist in caches. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: While not necessary a vulnerability in and of itself, when paired with GitHub Actions caching behavior, it is possible for this to expose secrets to PRs. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: The current code to do so achieves this by storing all environment variables to target/. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: PR CI can be triggered by anyone who can open PRs on your repository. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: GitHub requires maintainer approval for the first PR, but future PRs will rerun CI on every push. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: Anyone who has previously landed a change can trigger a CI run extracting information from cached target/ and then cover their tracks by pushing a second commit to the PR. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: Our short term fix for this is to make Miri only preserve CARGO_* environment variables (excepting CARGO_*_TOKEN) and OUT_DIR. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: In the longer term, Miri and cargo may figure out better ways to inform Miri of the relevant list of environment variables. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: Even if you do not run Miri, ensure jobs that can write to public caches do not have access to secrets. GitHub Actions leaking secrets when Miri output is cached
- The Rust Security Response Team source says: If caching target/, it is worth making sure that the inputs to processes that create target/ (anything invoking cargo) do not have secrets available. GitHub Actions leaking secrets when Miri output is cached