Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a4675e

Browse files
authored
fix: don't flag local workflows in unpinned-uses (#439)
1 parent ec37d0a commit 1a4675e

5 files changed

Lines changed: 68 additions & 33 deletions

File tree

docs/release-notes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ of `zizmor`.
99

1010
## Next (UNRELEASED)
1111

12-
Nothing to see here (yet!)
12+
### Improved
13+
14+
* The [unpinned-uses] audit no longer flags local reusable workflows or actions
15+
as unpinned/unhashed (#439)
1316

1417
## v1.1.1
1518

@@ -429,3 +432,4 @@ This is one of `zizmor`'s bigger recent releases! Key enhancements include:
429432
[github-env]: ./audits.md#github-env
430433
[template-injection]: ./audits.md#template-injection
431434
[secrets-inherit]: ./audits.md#secrets-inherit
435+
[unpinned-uses]: ./audits.md#unpinned-uses

src/audit/unpinned_uses.rs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ audit_meta!(UnpinnedUses, "unpinned-uses", "unpinned action reference");
1010

1111
impl UnpinnedUses {
1212
pub fn evaluate_pinning<'u>(&self, uses: &Uses) -> Option<(&'u str, Severity, Persona)> {
13+
// Don't evaluate pinning for local `uses:`, since unpinned references
14+
// are fully controlled by the repository anyways.
15+
// TODO: auditor-level findings instead, perhaps?
16+
if matches!(uses, Uses::Local(_)) {
17+
return None;
18+
}
19+
1320
if uses.unpinned() {
1421
Some((
1522
"action is not pinned to a tag, branch, or hash ref",
@@ -43,24 +50,22 @@ impl Audit for UnpinnedUses {
4350
return Ok(vec![]);
4451
};
4552

46-
let Some((annotation, severity, persona)) = self.evaluate_pinning(uses) else {
47-
return Ok(vec![]);
53+
if let Some((annotation, severity, persona)) = self.evaluate_pinning(uses) {
54+
findings.push(
55+
Self::finding()
56+
.confidence(Confidence::High)
57+
.severity(severity)
58+
.persona(persona)
59+
.add_location(
60+
step.location()
61+
.primary()
62+
.with_keys(&["uses".into()])
63+
.annotated(annotation),
64+
)
65+
.build(step.workflow())?,
66+
);
4867
};
4968

50-
findings.push(
51-
Self::finding()
52-
.confidence(Confidence::High)
53-
.severity(severity)
54-
.persona(persona)
55-
.add_location(
56-
step.location()
57-
.primary()
58-
.with_keys(&["uses".into()])
59-
.annotated(annotation),
60-
)
61-
.build(step.workflow())?,
62-
);
63-
6469
Ok(findings)
6570
}
6671

@@ -74,24 +79,22 @@ impl Audit for UnpinnedUses {
7479
return Ok(vec![]);
7580
};
7681

77-
let Some((annotation, severity, persona)) = self.evaluate_pinning(uses) else {
78-
return Ok(vec![]);
82+
if let Some((annotation, severity, persona)) = self.evaluate_pinning(uses) {
83+
findings.push(
84+
Self::finding()
85+
.confidence(Confidence::High)
86+
.severity(severity)
87+
.persona(persona)
88+
.add_location(
89+
step.location()
90+
.primary()
91+
.with_keys(&["uses".into()])
92+
.annotated(annotation),
93+
)
94+
.build(step.action())?,
95+
);
7996
};
8097

81-
findings.push(
82-
Self::finding()
83-
.confidence(Confidence::High)
84-
.severity(severity)
85-
.persona(persona)
86-
.add_location(
87-
step.location()
88-
.primary()
89-
.with_keys(&["uses".into()])
90-
.annotated(annotation),
91-
)
92-
.build(step.action())?,
93-
);
94-
9598
Ok(findings)
9699
}
97100
}

tests/snapshot.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ fn unpinned_uses() -> Result<()> {
217217
.args(["--pedantic"])
218218
.run()?);
219219

220+
insta::assert_snapshot!(zizmor()
221+
.workflow(workflow_under_test("unpinned-uses/issue-433-repro.yml"))
222+
.args(["--pedantic"])
223+
.run()?);
224+
220225
Ok(())
221226
}
222227

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: tests/snapshot.rs
3+
expression: "zizmor().workflow(workflow_under_test(\"unpinned-uses/issue-433-repro.yml\")).args([\"--pedantic\"]).run()?"
4+
snapshot_kind: text
5+
---
6+
No findings to report. Good job!
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# repro case for https://github.com/woodruffw/zizmor/issues/433
2+
3+
name: issue-433-repro
4+
5+
on: push
6+
7+
jobs:
8+
issue-433-repro:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: no-finding-1
12+
# workflow is local, so tagging is superfluous
13+
uses: ./.github/workflows/reusable.yml
14+
15+
- name: no-finding-2
16+
# no pedantic finding for tag-pinned local workflows
17+
uses: ./.github/workflows/reusable.yml@tag

0 commit comments

Comments
 (0)