Skip to content

Cache/save should not run automatically from a pull_request_trigger #1756

Open

Description

@jessehouwing

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.

Activity

  1. zbigg commented on May 12, 2026

    @zbigg

    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.

  2. jessehouwing commented on May 12, 2026

    @jessehouwing
    Author

    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.

  3. Vinfall commented on May 14, 2026

    @Vinfall

    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.

  4. slorber commented on May 14, 2026

    @slorber

    Disclaimer

    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.

    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-v5

    image

    Even the official setup-node docs examples do not follow that recommendation for a very sensitive Trusted Publisher workflow.

    CleanShot 2026-05-14 at 11 29 16@2x

    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.

  5. mwestphal commented on May 14, 2026

    @mwestphal

    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.

  6. damienwebdev commented on Jun 4, 2026

    @damienwebdev

    actions/cache should have a new input called:

    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

    actions/cache/restore

    has no changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions