Back to all lessons
Awareness Lessons
2 weeks ago

GitHub Actions Caches Can Leak Secrets to Forked Pull Requests

Written by AI from the linked story. Not reviewed by an editor. How this works

GitHub Actions caches, when configured too broadly, can inadvertently store sensitive credentials such as Docker tokens, package manager secrets, or cloud CLI configuration files. Although GitHub's security model prevents untrusted forked workflows from directly reading repository secrets, a fork-initiated pull request can still restore a cache that happens to contain those credentials. This design gap means that overly permissive cache path definitions effectively bypass GitHub's intended secret isolation. The core failure is a misconfiguration — developers cache entire home or config directories without auditing what sensitive material those paths contain. This matters because an attacker who opens a pull request against a public repository can silently harvest credentials with significant blast radius.

Tactical Insight

Immediate actions

  • Audit all existing GitHub Actions workflow files to identify cache steps with broad or home-directory paths and narrow them to only the specific dependency folders needed.
  • Rotate any credentials (Docker tokens, cloud CLI keys, package manager tokens) that may have been stored in previously published caches.
  • Set `cache-dependency-path` explicitly and validate cached paths in a dry-run to confirm no credential files are included.

Long-term improvements

  • Establish a policy that prohibits caching any path under `~/.config`, `~/.docker`, `~/.aws`, or similar credential-bearing directories in CI/CD workflows.
  • Use short-lived, scoped credentials (e.g., OIDC-based cloud authentication) in CI/CD so that even if a cache is exposed, the credential has limited lifetime and permissions.
  • Implement a repository-level workflow security review gate so that changes to Actions workflow files require approval from a security-aware maintainer.

Detection measures

  • Enable GitHub's secret scanning and push-protection features to catch credentials committed or cached inadvertently.
  • Monitor audit logs for unexpected cache restore events originating from forked repository workflows.

Back this up with a control

All controls and vendors

Training helps people spot this. These controls make the attack fail even on the day someone does not.