Skip to content

Commit

Permalink
Improve SAST check.
Browse files Browse the repository at this point in the history
github-code-scanning slug does not work in custom QL definitions.
And "use: github/codeql-action" can't be detected from runtime
workflow job, but just search in .github/workflows.

Fixes result for envoyproxy/envoy and fixes
#93
  • Loading branch information
inferno-chromium committed Dec 15, 2020
1 parent c5abb92 commit 7a10bed
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 7a10bed

Please sign in to comment.