security: add metadata-only Gitleaks finding triage without exposing secret values
davoodmehraban89 committed
Oct 14, 2026 at 22:48 UTC
bb7f6efd6ea71b793eec1b39dc41b0eead05dca0
1 file changed
+47
scripts/security/triage-gitleaks-report.mjs
new
+47
@@ -0,0 +1,47 @@
1
+/**
2
+ * CI-only helper: prints metadata about Gitleaks detections without revealing
3
+ * Secret, Match, Content, surrounding source text, or full fingerprints.
4
+ *
5
+ * NEVER upload the original JSON report as an artifact, print it to logs, or
6
+ * commit it. Logs are public on a public GitHub repository.
7
+ */
8
+import fs from "node:fs"
9
+
10
+const reportPath = process.argv[2]
11
+if (!reportPath || !fs.existsSync(reportPath)) {
12
+ console.log("No Gitleaks JSON findings report available.")
13
+ process.exit(0)
14
+}
15
+
16
+const raw = JSON.parse(fs.readFileSync(reportPath, "utf8"))
17
+if (!Array.isArray(raw)) {
18
+ throw new Error("Unexpected Gitleaks report format")
19
+}
20
+
21
+const isLikelyTestMaterial = (path) =>
22
+ /(^|\/)(?:__tests__|tests?|fixtures?|__fixtures__|examples?|samples?|mocks?|docs?)(\/|$)|\.(?:test|spec)\.[jt]sx?$|\.(?:example|sample|template)(?:\.|$)/i.test(path)
23
+
24
+const sanitize = (value, limit = 240) =>
25
+ JSON.stringify(String(value ?? "").slice(0, limit))
26
+
27
+const counts = new Map()
28
+console.log(`Gitleaks finding metadata (NO secret values): ${raw.length} detections`)
29
+for (const [index, item] of raw.entries()) {
30
+ // A filename alone does NOT establish false-positive status.
31
+ const path = String(item.File ?? "")
32
+ const rule = String(item.RuleID ?? "")
33
+ const kind = isLikelyTestMaterial(path) ? "test-or-documentation-path" : "other-path"
34
+ const group = `${kind} / ${rule}`
35
+ counts.set(group, (counts.get(group) ?? 0) + 1)
36
+
37
+ console.log(
38
+ `Finding ${index + 1}: kind=${kind} rule=${sanitize(rule, 100)} ` +
39
+ `path=${sanitize(path)} commit_prefix=${sanitize(String(item.Commit ?? "").slice(0, 12), 12)} ` +
40
+ `start_line=${Number.isFinite(Number(item.StartLine)) ? Number(item.StartLine) : "unknown"}`
41
+ )
42
+}
43
+console.log("Counts grouped by path category and rule:")
44
+for (const [name, count] of [...counts.entries()].sort()) {
45
+ console.log(` ${sanitize(name)}: ${count}`)
46
+}
47
+console.log("All detections require review. No allowlist or suppression was applied.")