Repository navigation
Description
Describe the bug
Since PR #500, releaseWorkflowsMustNotRestoreUntrustedCache (ISSUE-705) resolves the release context per trigger: it fires only when a cache restore and a publish can share an event, and a step if: of the bare shape github.event_name == '<event>' narrows that step to the event.
The narrowing is lost as soon as the if: is a conjunction. A release step gated by github.event_name == 'workflow_dispatch' && <anything else> is treated as able to run on every trigger of the job, so a job that disables its cache on workflow_dispatch (the remediation the finding recommends) still gets the High.
A conjunction can only narrow further: whatever the second operand evaluates to, the step cannot run on any event other than the one the first operand names. Workflows with workflow_dispatch inputs almost always write their release conditions this way ("on dispatch, and only when the chosen input is X").
To Reproduce
name: plugin
on:
workflow_dispatch:
inputs:
version:
type: choice
default: patch
options: [patch, current]
pull_request:
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-java@v4
with:
java-version: "17"
distribution: temurin
cache: ${{ github.event_name != 'workflow_dispatch' && 'maven' || '' }}
- run: mvn -B package
- name: Create release
if: github.event_name == 'workflow_dispatch' && inputs.version != 'current'
run: gh release create "v$VERSION" target/plugin.zip
env:
GH_TOKEN: ${{ github.token }}plumber analyze reports:
HIGH [ISSUE-705] job "plugin/build-and-release" restores a cache via "actions/setup-java@v4" on a release-type trigger
Three variants of the same file, all on 0.5.20:
cache: input |
if: on the release step |
Result |
|---|---|---|
maven |
github.event_name == 'workflow_dispatch' |
ISSUE-705 (correct, the control case) |
| conditional, as above | github.event_name == 'workflow_dispatch' |
no finding (correct, the #497 fix) |
| conditional, as above | github.event_name == 'workflow_dispatch' && inputs.version != 'current' |
ISSUE-705 (false positive) |
The github.event.inputs.version spelling of the second operand gives the same result.
Expected behavior
A top-level && in a step or job if: should narrow by every operand that is a resolvable event comparison and ignore the operands it cannot resolve, since an unresolved conjunct can only remove runs, never add events. A && (B || C) with A an event comparison narrows to A's events in the same way.
|| is the case that must stay conservative: github.event_name == 'x' || <unresolved> can run on any event, so it should keep narrowing nothing, as today.
Relevant versions and configuration files
- OS: Windows 11 (binary
plumber-windows-amd64) - Platform: GitHub (github.com)
- Plumber version: 0.5.20
.plumber.yaml: none, built-in default configuration
Relevant logs
None beyond the finding line above. The run was limited to the one control with --controls releaseWorkflowsMustNotRestoreUntrustedCache.
Additional context
This is the shape real dispatch-driven release workflows use: a choice input picks the target or the kind of release, and each publish step tests the event and the input together. With the bare shape resolved and the conjunction not, a maintainer who applies the recommended fix sees the finding stay, and the only edit that clears it is dropping the input test from the release step, which changes what the workflow does.
Note: If you submit a PR for this bug, please keep "Allow edits from maintainers" enabled so we can collaborate on the fix more easily.
Activity