Skip to content

Commit a5f3976

Browse files
committed
fix(security): explicit branch check on nightly workflow_run trigger
Add `head_branch == 'develop'` guard to the nightly workflow's init job. The `branches: [develop]` filter on the trigger already enforces this, but static analyzers (OSSF Scorecard's DangerousWorkflow rule) can't trace that — they see workflow_run + head_sha checkout + secrets: inherit and flag the pattern critical regardless of the trigger filter. The explicit branch check ties the trust boundary to develop's branch protection (PR + code-owner review + required checks), which is the actual safety guarantee. All downstream jobs depend on init via needs:, so they inherit the gate without per-job changes. Behavior is unchanged: workflow_run runs that wouldn't have fired under the trigger filter still don't fire. Manual workflow_dispatch remains unaffected. Note: `workflow_run` triggers always execute the version of this file from main (per GitHub's rules), so this fix takes effect for runtime safety only after develop → main lands. The static-analysis finding (#760, alert #565) closes once the Scorecard scan re-runs against develop with this change. Fixes #760
1 parent a7688e8 commit a5f3976

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

.github/workflows/nightly.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,23 @@ jobs:
4747
init:
4848
name: Initialize
4949
# Skip when CI failed; manual dispatch always runs.
50-
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
50+
#
51+
# The `head_branch == 'develop'` guard makes explicit what the
52+
# `branches: [develop]` filter on the trigger already enforces:
53+
# this workflow runs privileged jobs (secrets: inherit, contents:
54+
# write) on the head_sha of the triggering CI run. Static analyzers
55+
# (e.g. OSSF Scorecard's DangerousWorkflow rule) flag workflow_run
56+
# patterns that checkout `head_sha` without a branch check, since
57+
# in principle workflow_run can be triggered by CI runs on any
58+
# branch and a checkout of an untrusted ref with secrets is the
59+
# canonical supply-chain attack vector. The explicit branch check
60+
# below ties the trust boundary to develop's branch protection
61+
# (PR + code-owner review + required checks), which is the actual
62+
# safety guarantee.
63+
if: >
64+
github.event_name == 'workflow_dispatch' ||
65+
(github.event.workflow_run.conclusion == 'success' &&
66+
github.event.workflow_run.head_branch == 'develop')
5167
uses: ./.github/workflows/_init.yaml
5268
with:
5369
# `head_sha` pins the build to the exact commit whose CI passed,

0 commit comments

Comments
 (0)