Skip to content

Commit 0ffa386

Browse files
committed
chore: report simplification
1 parent 0ab445b commit 0ffa386

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

.github/scripts/security-scan/security-scan-report.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,21 @@ jq_lib() {
5252
else "UNKNOWN" end;
5353
def sevrank: {"CRITICAL": 0, "HIGH": 1, "MEDIUM": 2, "LOW": 3, "UNKNOWN": 4}[.] // 9;
5454
def counts_line: . as $c |
55-
(["CRITICAL","HIGH","MEDIUM","LOW","UNKNOWN"]
55+
(["CRITICAL","HIGH","MEDIUM","LOW"]
5656
| map(. as $s | select(($c[$s] // 0) > 0) | "\($c[$s]) \($s)")
5757
| join(", ")) as $by_sev |
5858
"\($c.total // 0) total" + (if $by_sev != "" then " (\($by_sev))" else "" end);
59+
def loc: .target + (if (.line // 0) > 0 then ":\(.line)" else "" end);
5960
def finding_line:
60-
"[\(.severity)] \(.class) \(.id)"
61-
+ (if .pkg != "" then " \(.pkg)" else "" end)
62-
+ (if .installed != "" then " \(.installed)" else "" end)
63-
+ (if .fixed != "" then " -> \(.fixed)" else "" end)
64-
+ " (\(.target))";
61+
(if .severity != "UNKNOWN" then "[\(.severity)] " else "" end)
62+
+ (if .class == "vuln" then
63+
"\(.pkg) \(.installed)"
64+
+ (if .fixed != "" then " -> \(.fixed)" else "" end)
65+
+ " \(.id)"
66+
else
67+
.id + (if .title != "" then " \(.title)" else "" end)
68+
end)
69+
+ " (\(loc))";
6570
JQ
6671
}
6772

@@ -122,6 +127,7 @@ cmd_summary() {
122127
id: (.VulnerabilityID // ""),
123128
severity: (.Severity | sev),
124129
target: ($r.Target // ""),
130+
line: 0,
125131
pkg: (.PkgName // ""),
126132
installed: (.InstalledVersion // ""),
127133
fixed: (.FixedVersion // ""),
@@ -132,6 +138,7 @@ cmd_summary() {
132138
id: (.AVDID // .ID // ""),
133139
severity: (.Severity | sev),
134140
target: ($r.Target // ""),
141+
line: (.CauseMetadata.StartLine // 0),
135142
pkg: "",
136143
installed: "",
137144
fixed: "",
@@ -142,6 +149,7 @@ cmd_summary() {
142149
id: (.RuleID // ""),
143150
severity: (.Severity | sev),
144151
target: ($r.Target // ""),
152+
line: (.StartLine // 0),
145153
pkg: "",
146154
installed: "",
147155
fixed: "",
@@ -222,9 +230,9 @@ cmd_render() {
222230
write() { echo "$@" >>"$summary_file"; }
223231

224232
table() {
225-
echo "| Severity | Class | ID | Target | Package | Installed | Fixed |"
226-
echo "|----------|-------|----|--------|---------|-----------|-------|"
227-
jq -r '.[] | "| \(.severity) | \(.class) | \(.id) | \(.target) | \(.pkg) | \(.installed) | \(.fixed) |"'
233+
echo "| Severity | Class | ID | Location | Package | Installed | Fixed |"
234+
echo "|----------|-------|----|----------|---------|-----------|-------|"
235+
jq -r "$(jq_lib)"'.[] | "| \(.severity) | \(.class) | \(.id) | \(loc) | \(.pkg) | \(.installed) | \(.fixed) |"'
228236
}
229237

230238
write "## Weekly Security Scan"

.github/scripts/security-scan/tests/security-scan-report.bats

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ setup() {
2929
"Class": "config",
3030
"Type": "dockerfile",
3131
"Misconfigurations": [
32-
{"ID": "DS002", "AVDID": "AVD-DS-0002", "Title": "Image user should not be root", "Severity": "MEDIUM", "Status": "FAIL"},
32+
{"ID": "DS002", "AVDID": "AVD-DS-0002", "Title": "Image user should not be root", "Severity": "MEDIUM", "Status": "FAIL", "CauseMetadata": {"StartLine": 5}},
3333
{"ID": "DS999", "AVDID": "AVD-DS-0999", "Title": "Passing check", "Severity": "LOW", "Status": "PASS"}
3434
]
3535
},
3636
{
3737
"Target": "config/creds.txt",
3838
"Class": "secret",
3939
"Secrets": [
40-
{"RuleID": "github-pat", "Category": "GitHub", "Severity": "CRITICAL", "Title": "GitHub Personal Access Token"}
40+
{"RuleID": "github-pat", "Category": "GitHub", "Severity": "CRITICAL", "Title": "GitHub Personal Access Token", "StartLine": 10}
4141
]
4242
}
4343
]
@@ -179,14 +179,20 @@ EOF
179179
[ "$status" -eq 0 ]
180180
[[ "$output" == *"New this week (2)"* ]]
181181
[[ "$output" == *"Fixed this week (1)"* ]]
182-
[[ "$output" == *"github-pat"* ]]
182+
[[ "$output" == *"[CRITICAL] github-pat GitHub Personal Access Token (config/creds.txt:10)"* ]]
183+
[[ "$output" == *"[LOW] example.com/old 2.0.0 -> 2.0.1 CVE-2020-0001 (go.mod)"* ]]
183184
}
184185

185186
@test "payload lists the current findings" {
186187
run "$SCRIPT" payload "$REPORT"
187188
[ "$status" -eq 0 ]
188189
[[ "$output" == *"Current findings (4)"* ]]
189-
[[ "$output" == *"[UNKNOWN] vuln GO-2026-9999 golang.org/x/bar 0.2.0 (go.mod)"* ]]
190+
[[ "$output" == *"golang.org/x/bar 0.2.0 GO-2026-9999 (go.mod)"* ]]
191+
}
192+
193+
@test "payload omits the UNKNOWN severity tag" {
194+
run "$SCRIPT" payload "$REPORT"
195+
[[ "$output" != *"[UNKNOWN]"* ]]
190196
}
191197

192198
@test "payload caps the listed findings" {

0 commit comments

Comments
 (0)