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.
More on GitHub Actions and GitLab CI in Production
How do you organise reusable workflows for an organisation on GitHub?IntermediateHow do you reduce GitHub Actions minutes cost on private repos?IntermediateHow do you secure self-hosted runners?AdvancedHow do you design the GitHub Actions OIDC trust policy for AWS safely?AdvancedHow do you handle approvals and deployments across environments in GitHub Actions?IntermediateHow do you handle required checks when workflows use path filters or matrices?Advanced