Skip to content
Closed
21 changes: 13 additions & 8 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ jobs:
exit 1
fi
count=$(jq '[.runs[]
| (.tool.driver.rules // []) as $rules
| (([.tool.driver.rules // []]
+ [.tool.extensions[]?.rules // []]) | add) as $rules
| ($rules | map({key: (.id // ""),
value: (.properties["security-severity"] // "0")})
| from_entries) as $sev_by_id
| .results[]
| . as $r
| (($rules[$r.ruleIndex].properties["security-severity"]
// $r.properties["security-severity"]
| (($sev_by_id[.ruleId // .rule.id // ""]
// .properties["security-severity"]
// "0") | tonumber) as $sev
| select($sev >= 7.0)] | length' "$sarif")
echo "Critical/High Go findings: $count"
Expand Down Expand Up @@ -117,10 +120,12 @@ jobs:
| (.tool.driver.rules // []) as $rules
| .results[]
| . as $r
| (($rules[$r.ruleIndex].properties["security-severity"]
// $r.properties["security-severity"]
// "0") | tonumber) as $sev
| select($sev >= 7.0)] | length' "$sarif")
| ((if ($r.ruleIndex | type) == "number"
then $rules[$r.ruleIndex].properties["security-severity"]
else null end)
// $r.properties["security-severity"]
// "0") as $sev
| select(($sev | tonumber) >= 7.0)] | length' "$sarif")
echo "Critical/High Actions findings: $count"
if [ "$count" -gt 0 ]; then
echo "::error::CodeQL Actions found $count Critical/High results"
Expand Down
43 changes: 43 additions & 0 deletions throwaway_critical.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This file exists ONLY to force-validate the CodeQL severity gate in
// .github/workflows/scan.yml. It contains a flow from an HTTP request
// query parameter (CodeQL's canonical untrusted source) into both
// os/exec.Command and os.Open — patterns flagged by
// codeql/go-queries' CommandInjection.ql and TaintedPath.ql at
// security-severity 9.8 and 7.5 respectively.
//
// DO NOT MERGE. This PR exists to prove the workflow rejects Critical
// findings and is closed without merging once that observation is
// captured.

package main

import (
"net/http"
"os"
"os/exec"
)

func throwawayUnsafeHandler(w http.ResponseWriter, r *http.Request) {
// `r.URL.Query().Get` is the canonical CodeQL untrusted source.
user := r.URL.Query().Get("cmd")
// nosemgrep: dangerous-exec-command, go.lang.security.audit.dangerous-exec-command.dangerous-exec-command
if err := exec.Command("sh", "-c", user).Run(); err != nil {

Check failure

Code scanning / CodeQL

Command built from user-controlled sources Critical

This command depends on a
user-provided value
.
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
path := r.URL.Query().Get("file")
// nosemgrep: go.lang.security.audit.dangerous-system-call
f, err := os.Open(path)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
_ = f.Close()
}

func init() {
if len(os.Args) > 1 && os.Args[1] == "__throwaway_force_codeql_gate__" {
http.HandleFunc("/x", throwawayUnsafeHandler)
_ = http.ListenAndServe(":0", nil)
}
}
Loading