Skip to content

Commit bb463f7

Browse files
feat: detects push to release branches in cache-poisoning (#352)
1 parent a9d571c commit bb463f7

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

Diff for: src/audit/cache_poisoning.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::models::{Job, Step, Steps, Uses};
44
use crate::state::AuditState;
55
use github_actions_models::common::expr::ExplicitExpr;
66
use github_actions_models::common::Env;
7-
use github_actions_models::workflow::event::{BareEvent, OptionalBody};
7+
use github_actions_models::workflow::event::{BareEvent, BranchFilters, OptionalBody};
88
use github_actions_models::workflow::job::StepBody;
99
use github_actions_models::workflow::Trigger;
1010
use std::ops::Deref;
@@ -317,7 +317,19 @@ impl CachePoisoning {
317317
Trigger::BareEvent(event) => *event == BareEvent::Release,
318318
Trigger::BareEvents(events) => events.contains(&BareEvent::Release),
319319
Trigger::Events(events) => match &events.push {
320-
OptionalBody::Body(body) => body.tag_filters.is_some(),
320+
OptionalBody::Body(body) => {
321+
let pushing_new_tag = &body.tag_filters.is_some();
322+
let pushing_to_release_branch =
323+
if let Some(BranchFilters::Branches(branches)) = &body.branch_filters {
324+
branches
325+
.iter()
326+
.any(|branch| branch.to_lowercase().contains("release"))
327+
} else {
328+
false
329+
};
330+
331+
*pushing_new_tag || pushing_to_release_branch
332+
}
321333
_ => false,
322334
},
323335
}

Diff for: tests/snapshot.rs

+6
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ fn cache_poisoning() -> Result<()> {
334334
))
335335
.run()?);
336336

337+
insta::assert_snapshot!(zizmor()
338+
.workflow(workflow_under_test(
339+
"cache-poisoning/workflow-release-branch-trigger.yml"
340+
))
341+
.run()?);
342+
337343
Ok(())
338344
}
339345

Diff for: tests/snapshots/snapshot__cache_poisoning-13.snap

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: tests/snapshot.rs
3+
expression: "zizmor().workflow(workflow_under_test(\"cache-poisoning/workflow-release-branch-trigger.yml\")).run()?"
4+
snapshot_kind: text
5+
---
6+
error[cache-poisoning]: runtime artifacts potentially vulnerable to a cache poisoning attack
7+
--> @@INPUT@@:1:1
8+
|
9+
1 | / on:
10+
2 | | push:
11+
3 | | branches:
12+
4 | | - 'release-v2.0.0'
13+
| |________________________^ generally used when publishing artifacts generated at runtime
14+
5 |
15+
...
16+
15 | - name: Setup CI caching
17+
16 | uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cache enabled by default here
19+
|
20+
= note: audit confidenceLow
21+
22+
1 finding: 0 unknown, 0 informational, 0 low, 0 medium, 1 high
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
push:
3+
branches:
4+
- 'release-v2.0.0'
5+
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Project Checkout
11+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
12+
with:
13+
persist-credentials: false
14+
15+
- name: Setup CI caching
16+
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab
17+
18+
- name: Publish on crates.io
19+
run: cargo publish --token ${{ secrets.CRATESIO_PUBLISH_TOKEN }}

0 commit comments

Comments
 (0)