Skip to content

[BUG]: cache-poisoning false positive for Swatinem/rust-cache with save-if #2051

Description

@wpfleger96

Pre-submission checks

  • I am not filing a feature request. These should be filed via the feature request form instead.
  • I have checked the Troubleshooting Guide for my problem.
  • I have looked through both the open and closed issues for a duplicate report.

zizmor version

1.23.1

Expected behavior

Swatinem/rust-cache with save-if: ${{ github.event_name != 'pull_request' }} should not trigger cache-poisoning, since save-if: false prevents cache writes entirely — the same mitigation as lookup-only: true but less restrictive (cache restoration still works on PRs for build speed).

Actual behavior

zizmor flags the step as cache-poisoning regardless of the save-if value. Looking at cache_poisoning.rs, the Swatinem/rust-cache ActionCoordinate only registers lookup-only as the control field:

ActionCoordinate::Configurable {
    uses_pattern: "Swatinem/rust-cache".parse().unwrap(),
    control: ControlExpr::single(
        Toggle::OptOut,
        "lookup-only",
        ControlFieldType::Boolean,
        true,
    ),
},

save-if is not recognized at all, even though it directly controls whether cache writes happen.

Reproduction steps

on:
  push:
    branches: [main]
    tags: ['v*']
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
        with:
          save-if: ${{ github.event_name != 'pull_request' }}
      - run: cargo build

Running zizmor on this workflow reports a cache-poisoning finding on the Swatinem/rust-cache step, despite save-if preventing cache writes on PR events.

Suggested fix

Add save-if as a second recognized control field for Swatinem/rust-cache in cache_poisoning.rs, as an OptOut boolean toggle (when save-if: false, no cache is written — same effect as lookup-only: true for the poisoning vector).

Additional context

Related issues:

save-if documentation in Swatinem/rust-cache

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions