Skip to content

Commit

Permalink
feat: bot-conditions: check github.triggering_actor (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodruffw authored Feb 24, 2025
1 parent 976879f commit 02d4bac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ of `zizmor`.
expectations (#528)
* `# zizmor: ignore[rule]` comments can now have trailing explanations,
e.g. `# zizmor: ignore[rule] because reasons` (#531)
* The [bot-conditions] audit now detects `github.triggering_actor`
as another spoofable actor check (#559)

### Upcoming Changes 🚧

Expand Down
14 changes: 12 additions & 2 deletions src/audit/bot_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub(crate) struct BotConditions;

audit_meta!(BotConditions, "bot-conditions", "spoofable bot actor check");

const SPOOFABLE_ACTOR_CONTEXTS: &[&str] = &["github.actor", "github.triggering_actor"];

impl Audit for BotConditions {
fn new(_state: super::AuditState) -> anyhow::Result<Self>
where
Expand Down Expand Up @@ -52,7 +54,7 @@ impl Audit for BotConditions {
.add_location(
loc.with_keys(&["if".into()])
.primary()
.annotated("github.actor may be spoofable"),
.annotated("actor context may be spoofable"),
)
.build(job.parent())?,
);
Expand Down Expand Up @@ -94,7 +96,11 @@ impl BotConditions {
expr::BinOp::Eq => match (lhs.as_ref(), rhs.as_ref()) {
(Expr::Context(ctx), Expr::String(s))
| (Expr::String(s), Expr::Context(ctx)) => {
if ctx == "github.actor" && s.ends_with("[bot]") {
// NOTE: Can't use `contains` here because we need
// Context's `PartialEq` for case insensitive matching.
if SPOOFABLE_ACTOR_CONTEXTS.iter().any(|x| ctx == *x)
&& s.ends_with("[bot]")
{
(true, true)
} else {
(false, true)
Expand Down Expand Up @@ -171,6 +177,10 @@ mod tests {
("'dependabot[bot]' == github.actor", Confidence::High),
("'dependabot[bot]' == GitHub.actor", Confidence::High),
("'dependabot[bot]' == GitHub.ACTOR", Confidence::High),
(
"'dependabot[bot]' == GitHub.triggering_actor",
Confidence::High,
),
// Dominating cases with OR.
(
"'dependabot[bot]' == github.actor || true",
Expand Down
8 changes: 4 additions & 4 deletions tests/snapshots/snapshot__bot_conditions.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ error[bot-conditions]: spoofable bot actor check
--> @@INPUT@@:8:5
|
8 | if: github.actor == 'dependabot[bot]'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ github.actor may be spoofable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ actor context may be spoofable
|
= note: audit confidenceHigh

error[bot-conditions]: spoofable bot actor check
--> @@INPUT@@:12:9
|
12 | if: ${{ github.actor == 'dependabot[bot]' }}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ github.actor may be spoofable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ actor context may be spoofable
|
= note: audit confidenceHigh

error[bot-conditions]: spoofable bot actor check
--> @@INPUT@@:16:9
|
16 | if: ${{ github.actor == 'dependabot[bot]' && github.repository == 'example/example' }}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ github.actor may be spoofable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ actor context may be spoofable
|
= note: audit confidenceMedium

error[bot-conditions]: spoofable bot actor check
--> @@INPUT@@:20:9
|
20 | if: github.actor == 'renovate[bot]'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ github.actor may be spoofable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ actor context may be spoofable
|
= note: audit confidenceHigh

Expand Down

0 comments on commit 02d4bac

Please sign in to comment.