You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cache/save should not run automatically from a pull_request_trigger #1756
The current behavior of actions/cache is to always do both a restore and a save step. Even though its documented to never run save from an untrusted source.
Cache poisoning attacks were used against an nom package yesterday, the attack used a pull_request_target workflow to accomplish it.
In order to be secure by default, I propose to update actions/cache to take its own recommended practices in account and to make the save step conditional on the trigger not being prt.
I understand there are probably still other ways to accomplish cache poinsening, but this would go a long way in reducing yet another angle of the pull_request_target triggers dangers.
Alternatively, cache/save or cache could use pick another branch to cache against, not the target branch, main in this case, but the source branch, pulls/123.
Reacted by Corbin Crutchley, Zbigniew Zagórski, Damien Retzinger, Juan Pablo Jiménez , Matthew Gamble, rzzf, Sébastien Lorber, Arthur Rousseau and H. Z. Sababa
I believe that this should go even farther - pull_request_target jobs shouldn't be even allowed to write cache.
This shouldn't be negotiable or configurable. They are basically unsafe so they shouldn't have any means to have effect on anything in system.
Would be even better. But this would plug the default hole at least without such a breaking change. For internal and private repos (enterprise scenarios), having pull_request_target doing caching might be acceptable.
But this PR would at least make the cache write explicit by having to call actions/cache/save. technically that action could check against the repo visibility and refuse to work on public repos.
Not directly related to pull_request_target, but still related to the same cache poisoning problem and worth mentioning here.
setup-node automatic caching behavior
Actions such as setup-node should rather reconsider the automatic usage of a shared cache by default (introduced in v5), and eventually make it always opt-in.
Although the problem is known and partially documented, it's better to have secure but slower workflows by default, rather than insecure but faster workflows by default.
People will just copy/paste that example and will never be aware of the potential cache poisoning problem if conditions are met to automatically enable the npm cache.
IMHO, if this kind of action really wants to keep automatic caching, it should have smarter defaults. For example, always disable automatic caching if sensitive env variables or OIDC tokens are in that workflow.
I believe that this should go even farther - pull_request_target jobs shouldn't be even allowed to write cache.
This shouldn't be negotiable or configurable. They are basically unsafe so they shouldn't have any means to have effect on anything in system.
I disagree here. We have pull_request_target jobs that only maintainers can run, being able to write to master caches is very useful in that case. Not against an option to control that behavior though.
inputs:
...allow_unsafe_save:
description: 'Allows unsafe saves to the cache. E.g. on `pull_request_target`. Otherwise, this action is `restore` only on these events'required: false
actions/cache/save should probably be something like
inputs:
...allow_unsafe_save:
description: 'Allows unsafe saves to the cache. E.g. on `pull_request_target`. Otherwise, this will exit 1 on unsafe event types'required: false
Activity
zbigg commentedon May 12, 2026
I believe that this should go even farther -
pull_request_targetjobs shouldn't be even allowed to write cache.This shouldn't be negotiable or configurable. They are basically unsafe so they shouldn't have any means to have effect on anything in system.
jessehouwing commentedon May 12, 2026
Would be even better. But this would plug the default hole at least without such a breaking change. For internal and private repos (enterprise scenarios), having
pull_request_targetdoing caching might be acceptable.But this PR would at least make the cache write explicit by having to call actions/cache/save. technically that action could check against the repo visibility and refuse to work on public repos.
Vinfall commentedon May 14, 2026
A better default is surely appreciated, but to prevent TanStack cache poisoning, you only need to create a cache key and separate test/release caches.
slorber commentedon May 14, 2026
Disclaimer
Not directly related to
pull_request_target, but still related to the same cache poisoning problem and worth mentioning here.setup-nodeautomatic caching behaviorActions such as
setup-nodeshould rather reconsider the automatic usage of a shared cache by default (introduced in v5), and eventually make it always opt-in.Although the problem is known and partially documented, it's better to have secure but slower workflows by default, rather than insecure but faster workflows by default.
The setup-node README.md briefly mentions the security issue and recommends
package-manager-cache: false; however, it's not easy to find: https://github.com/actions/setup-node#breaking-changes-in-v5Even the official
setup-nodedocs examples do not follow that recommendation for a very sensitive Trusted Publisher workflow.People will just copy/paste that example and will never be aware of the potential cache poisoning problem if conditions are met to automatically enable the npm cache.
I've opened a PR to discuss that in a dedicated place:
actions/setup-node#1549
IMHO, if this kind of action really wants to keep automatic caching, it should have smarter defaults. For example, always disable automatic caching if sensitive env variables or OIDC tokens are in that workflow.
mwestphal commentedon May 14, 2026
I disagree here. We have pull_request_target jobs that only maintainers can run, being able to write to master caches is very useful in that case. Not against an option to control that behavior though.
damienwebdev commentedon Jun 4, 2026
actions/cacheshould have a new input called:actions/cache/saveshould probably be something likeactions/cache/restorehas no changes.