Skip to content

Commit 60afb21

Browse files
committed
Update based on feedback
Signed-off-by: Ben Cotton <[email protected]>
1 parent 2f0c156 commit 60afb21

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

Diff for: src/audit/unpinned_uses.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ use crate::finding::{Confidence, Severity};
22

33
use super::{audit_meta, AuditState, Finding, Step, WorkflowAudit};
44

5-
pub(crate) struct UnpinnedUses {
6-
pub(crate) state: AuditState,
7-
}
5+
pub(crate) struct UnpinnedUses;
86

97
audit_meta!(UnpinnedUses, "unpinned-uses", "unpinned action reference");
108

119
impl WorkflowAudit for UnpinnedUses {
12-
fn new(state: AuditState) -> anyhow::Result<Self>
10+
fn new(_state: AuditState) -> anyhow::Result<Self>
1311
where
1412
Self: Sized,
1513
{
16-
Ok(Self { state })
14+
Ok(Self)
1715
}
1816

1917
fn audit_step<'w>(&self, step: &Step<'w>) -> anyhow::Result<Vec<Finding<'w>>> {
@@ -23,27 +21,22 @@ impl WorkflowAudit for UnpinnedUses {
2321
return Ok(vec![]);
2422
};
2523

26-
// Check twice, complain once
27-
let mut found_unpinned = false;
28-
let mut annotation = "";
29-
if self.state.pedantic {
30-
if uses.unpinned_sha() {
31-
found_unpinned = true;
32-
annotation = "action is not pinned to a hash ref";
33-
}
24+
let (annotation, severity) = if uses.unpinned() {
25+
(
26+
"action is not pinned to a tag, branch, or hash ref",
27+
Severity::Medium,
28+
)
29+
} else if uses.unhashed() {
30+
("action is not pinned to a hash ref", Severity::Low)
3431
} else {
35-
if uses.unpinned() {
36-
found_unpinned = true;
37-
annotation = "action is not pinned to a tag, branch, or hash ref";
38-
}
39-
}
32+
("", Severity::Informational)
33+
};
4034

41-
// If one of the checks failed, add a finding
42-
if found_unpinned {
35+
if !annotation.is_empty() {
4336
findings.push(
4437
Self::finding()
4538
.confidence(Confidence::High)
46-
.severity(Severity::Informational)
39+
.severity(severity)
4740
.add_location(
4841
step.location()
4942
.with_keys(&["uses".into()])

Diff for: src/models.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use github_actions_models::workflow::{
1111
job::{NormalJob, StepBody},
1212
Trigger,
1313
};
14-
use regex::Regex;
1514

1615
/// Represents an entire GitHub Actions workflow.
1716
///
@@ -435,11 +434,10 @@ impl<'a> Uses<'a> {
435434
}
436435
}
437436

438-
pub(crate) fn unpinned_sha(&self) -> bool {
439-
let regex = Regex::new("^[a-fA-F0-9]{40}$").unwrap();
437+
pub(crate) fn unhashed(&self) -> bool {
440438
match self {
441-
Uses::Docker(docker) => ! docker.hash.is_none(),
442-
Uses::Repository(repo) => repo.git_ref.is_none() || ! regex.is_match(repo.git_ref.unwrap()),
439+
Uses::Docker(docker) => docker.hash.is_some(),
440+
Uses::Repository(repo) => !repo.ref_is_commit(),
443441
}
444442
}
445443
}

0 commit comments

Comments
 (0)