Interview Prep/CI/CD/GitHub Actions and GitLab CI in Production

How do you share a cache safely between workflows without cache poisoning?

AdvancedProductionGitHub Actions and GitLab CI in Production
Answer

Caches are readable by workflows on the same branch and by child branches/PRs from the default branch, so a PR can read but not overwrite main's cache entries. The risk is a trusted workflow restoring a cache that an untrusted workflow created (for example via pull_request_target, or a workflow_run that restores from a cache written by an untrusted run). Do not restore caches in privileged workflows that executed untrusted code, include the lockfile hash in keys, avoid caching executables you will run, and don't cache in release/publish jobs at all.

All CI/CD questions Roadmap: GitLab CI/CD

More on GitHub Actions and GitLab CI in Production