Skip to content

feat: new audit: ref-version-mismatch #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

segiddins
Copy link

Adds a new audit that detects when commit SHAs don't match their corresponding version comment tags in GitHub Actions workflows.

This addresses a case where Dependabot will not pick up on potential updates when the ref and version comment does not match.

Fixes #643

Ok(Self { client })
}

fn audit_step<'doc>(&self, step: &Step<'doc>) -> anyhow::Result<Vec<Finding<'doc>>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: We'll probably also need audit_composite_step (for uses: in composite actions) and audit_reusable_job (for reusable workflows) here.

The process_step pattern (e.g. in forbidden-uses) might be a good reference for deduping these 🙂

@@ -627,6 +627,7 @@ fn run() -> Result<ExitCode> {
register_audit!(audit::dangerous_triggers::DangerousTriggers);
register_audit!(audit::impostor_commit::ImpostorCommit);
register_audit!(audit::ref_confusion::RefConfusion);
register_audit!(audit::ref_version_mismatch::RefVersionMismatch);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: new audits are added at the bottom!

(Elsewhere it's alphabetic, here the registry records them in order of addition.)

Comment on lines 87 to 88
// For now, we'll search the entire document source for version patterns
// that might correspond to this uses line. This is a simplified approach.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: is this comment accurate still? It looks like the implementation below doesn't scan the whole doc source, only the comment next to the uses: clause (which is the right way to do it!)

}
findings.push(
Self::finding()
.severity(Severity::Low)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see an argument for this being medium -- it breaks tools like Dependabot and makes people think they're up to date/using a specific version, but actually aren't. OTOH I don't feel super strong about it; thoughts?

Comment on lines +522 to +526
impl AsRef<str> for Comment<'_> {
fn as_ref(&self) -> &str {
self.0
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagging: not something that needs doing in this PR, but I'd be nice to avoid puncturing the newtype here and instead add the VERSION_COMMENT_PATTERNS matching within Comment's own interface. But that can be a follow-on refactor.

@funnelfiasco funnelfiasco added the new-audit New audits label Jun 25, 2025
Adds a new audit that detects when commit SHAs don't match their
corresponding version comment tags in GitHub Actions workflows.

This addresses a case where Dependabot will not pick up on potential
updates when the ref and version comment does not match.

Fixes zizmorcore#643

Signed-off-by: Samuel Giddins <[email protected]>
@segiddins segiddins force-pushed the segiddins/feat-new-audit-ref-version-mismatch branch from ef76d1d to 270314a Compare June 25, 2025 21:33
return Ok(None);
};

while !matches!(tag_ref.object.r#type, Some(ObjectType::Commit)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt git fun...
should this maybe have a limit to avoid tag cycles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think we could maybe avoid this loop entirely by switching endpoints here -- instead of using the "get a reference" endpoint we could use the "get a commit" endpoint, which should always produce a commit object.

This specifically: https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#get-a-commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The docs don't say it super clearly, but gh api /repos/Swatinem/rust-cache/commits/refs/tags/v2.7.8 works and similar for refs/heads/...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the issue with that endpoint is it doesn't return 404 when the ref doesnt exist, and instead it returns a 422, which is indistinguishable from e.g. running out of rate limit usage

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that seems 100% wrong from GitHub. Let me see if I can get some attention from them on that.

(I'd definitely prefer to have this use a single request without a loop if possible, for similar rate limit reasons. So maybe they can fix this somewhat quickly.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this issue been raised to GitHub? If not, I'm happy to file and raise awareness.

(Also, than you so much for working on this new feature!!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I’ve flagged it with some people I know, who confirmed that it’s an issue. But certainly having more people raise awareness of it would probably increase its relative priority internally 🙂

@woodruffw
Copy link
Member

(Marking as blocked until GitHub fixes the REST API bug here.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: detect mismatches between pinned full-length commit SHA and version tag
4 participants