Skip to content

Commit

Permalink
Merge pull request #94 from ossf/b3
Browse files Browse the repository at this point in the history
Improve SAST check.
  • Loading branch information
kimsterv committed Dec 15, 2020
2 parents c5abb92 + 7a10bed commit 1991617
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions checks/sast.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
var sastTools map[string]bool = map[string]bool{"github-code-scanning": true, "sonarcloud": true}

func init() {
registerCheck("SAST", checker.MultiCheck(CodeQLActionRuns))
registerCheck("SAST", checker.MultiCheck(CodeQLInCheckDefinitions, SASTToolInCheckRuns))
}

func CodeQLActionRuns(c checker.Checker) checker.CheckResult {
func SASTToolInCheckRuns(c checker.Checker) checker.CheckResult {
prs, _, err := c.Client.PullRequests.List(c.Ctx, c.Owner, c.Repo, &github.PullRequestListOptions{
State: "closed",
})
Expand Down Expand Up @@ -63,3 +63,20 @@ func CodeQLActionRuns(c checker.Checker) checker.CheckResult {
}
return checker.ProportionalResult(totalTested, totalMerged, .75)
}

func CodeQLInCheckDefinitions(c checker.Checker) checker.CheckResult {
searchQuery := ("github/codeql-action path:/.github/workflows repo:" + c.Owner + "/" + c.Repo)
results, _, err := c.Client.Search.Code(c.Ctx, searchQuery, &github.SearchOptions{})
if err != nil {
return checker.RetryResult(err)
}

for _, result := range results.CodeResults {
c.Logf("found CodeQL definition: %s", result.GetPath())
}

return checker.CheckResult{
Pass: *results.Total > 0,
Confidence: 10,
}
}

0 comments on commit 1991617

Please sign in to comment.