Skip to content
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

✨ Check for imposter commits when verifying Scorecard Action results #389

Merged

Conversation

spencerschrock
Copy link
Contributor

Added logic to ensure a commit belongs to the main branch of the repository. Thanks to Chainguard for their imposter commit blog post and @wlynch for their CompareCommits implementation, which uses 1 REST call to get the default branch of the action step, and 1 call to check if it belongs to the branch.

There were a few alternatives considered:

  • The https://github.com/<org>/<repo>/branch_commits/<hash> endpoint, which isn't a documented/supported API endpoint and would involve parsing HTML and hoping it doesn't change.
  • A search based implementation which has its own API quota (30/min). I'd be open to submitting this format if people prefer it, but the search endpoint has randomly broke on us in the past.
func (g *githubVerifier) contains(owner, repo, hash string) (bool, error) {
	opts := &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 1}}
	queryString := fmt.Sprintf("repo:%s/%s hash:%s", owner, repo, hash)
	res, _, err := g.client.Search.Commits(g.ctx, queryString, opts)
	if err != nil {
		return false, fmt.Errorf("searching for commit: %w", err)
	}
	if res == nil || res.Total == nil {
		return false, errInvalidSearchResponse
	}
	return *res.Total > 0, nil
}

Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
Signed-off-by: Spencer Schrock <sschrock@google.com>
@netlify
Copy link

netlify bot commented May 8, 2023

Deploy Preview for ossf-scorecard canceled.

Name Link
🔨 Latest commit 84fdd1b
🔍 Latest deploy log https://app.netlify.com/sites/ossf-scorecard/deploys/64a8610256639800094fe86b

@aibaars
Copy link

aibaars commented Dec 15, 2023

@spencerschrock The problem seems to have come back for the v2.22.11 release: github/codeql-action#2040 . The codeql-action just bumped their mayor version to v3. Could that be the cause the problem?

@spencerschrock
Copy link
Contributor Author

Resolved in #518

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.

None yet

3 participants