@hardkeel/benthic 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -0
- package/LICENSE +92 -0
- package/NOTICE +16 -0
- package/README.md +424 -2
- package/action.yml +54 -0
- package/dist/agility.js +80 -0
- package/dist/badge.js +62 -0
- package/dist/baseline.js +81 -0
- package/dist/cbom-diff.js +273 -0
- package/dist/cbom.js +418 -0
- package/dist/cli.js +834 -0
- package/dist/cloud-aws-services.js +375 -0
- package/dist/cloud-aws.js +354 -0
- package/dist/cloud-azure-services.js +73 -0
- package/dist/cloud-azure.js +144 -0
- package/dist/cloud-common.js +242 -0
- package/dist/cloud-gcp-services.js +90 -0
- package/dist/cloud-gcp.js +150 -0
- package/dist/comments.js +138 -0
- package/dist/community-rules.js +37 -0
- package/dist/community.js +30 -0
- package/dist/deps.js +406 -0
- package/dist/der.js +571 -0
- package/dist/evidence-cli.js +235 -0
- package/dist/evidence-live.js +109 -0
- package/dist/evidence.js +512 -0
- package/dist/ignore.js +90 -0
- package/dist/image.js +1224 -0
- package/dist/infra.js +635 -0
- package/dist/inventory.js +277 -0
- package/dist/map-activity.js +24 -0
- package/dist/map-areas.js +60 -0
- package/dist/map-cloud-keys.js +110 -0
- package/dist/map-cloud.js +34 -0
- package/dist/map-ct.js +107 -0
- package/dist/map-host.js +335 -0
- package/dist/map-network.js +520 -0
- package/dist/map-people.js +79 -0
- package/dist/map-rank.js +70 -0
- package/dist/map-report.js +304 -0
- package/dist/map-run.js +327 -0
- package/dist/map-sarif.js +61 -0
- package/dist/map-signin.js +247 -0
- package/dist/map-types.js +19 -0
- package/dist/map-web.js +666 -0
- package/dist/native.js +168 -0
- package/dist/policy.js +221 -0
- package/dist/pqc.js +46 -0
- package/dist/profile.js +65 -0
- package/dist/project.js +928 -0
- package/dist/prose.js +159 -0
- package/dist/protocols.js +207 -0
- package/dist/registry.js +326 -0
- package/dist/report.js +190 -0
- package/dist/rules.js +230 -0
- package/dist/sarif-common.js +30 -0
- package/dist/sarif.js +114 -0
- package/dist/scan.js +601 -0
- package/dist/score.js +124 -0
- package/dist/secrets.js +192 -0
- package/dist/share-config.js +129 -0
- package/dist/share-lists.js +19 -0
- package/dist/share.js +125 -0
- package/dist/sonar.js +83 -0
- package/dist/structure.js +218 -0
- package/dist/suites.js +402 -0
- package/dist/tls-check.js +122 -0
- package/dist/types.js +4 -0
- package/dist/walk.js +78 -0
- package/dist/yaml.js +173 -0
- package/package.json +73 -4
package/dist/evidence.js
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// The evidence pack: a cryptographic inventory written for a compliance review (PCI DSS 12.3.3 and
|
|
4
|
+
// the like). Every protocol, cipher suite and algorithm in use, strong ones included, with its purpose,
|
|
5
|
+
// the system it belongs to, whether it is still viable and on whose word, plus a review record, a plan
|
|
6
|
+
// for when an algorithm breaks, and enough provenance to run it again and get the same answer.
|
|
7
|
+
// No grade: a document someone hands an assessor shouldn't argue against them on its cover.
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { execFileSync } from "node:child_process";
|
|
10
|
+
import { CRYPTO_RULES } from "./rules.js";
|
|
11
|
+
import { SECRET_RULES } from "./secrets.js";
|
|
12
|
+
import { INVENTORY_RULES } from "./inventory.js";
|
|
13
|
+
import { COMMUNITY_RULES } from "./community-rules.js";
|
|
14
|
+
import { parseYaml } from "./yaml.js";
|
|
15
|
+
import { namedPolicy, SUITES } from "./suites.js";
|
|
16
|
+
import { protocolUse } from "./protocols.js";
|
|
17
|
+
/** The day the rule tables and viability notes were last checked against current guidance. Bump it with them. */
|
|
18
|
+
export const RULES_UPDATED = "2026-12-03";
|
|
19
|
+
export const DISCLAIMER = "This is input to your own review. It is not an assessment by a QSA or a Report on Compliance.";
|
|
20
|
+
export class ScopeError extends Error {
|
|
21
|
+
}
|
|
22
|
+
const strList = (v, field, sys) => {
|
|
23
|
+
if (v === undefined || v === null)
|
|
24
|
+
return [];
|
|
25
|
+
if (typeof v === "string")
|
|
26
|
+
return [v];
|
|
27
|
+
if (!Array.isArray(v) || v.some((x) => typeof x !== "string" && typeof x !== "number"))
|
|
28
|
+
throw new ScopeError(`System "${sys}": ${field} must be a list of text.`);
|
|
29
|
+
return v.map(String);
|
|
30
|
+
};
|
|
31
|
+
/** Reads a scope file, JSON or YAML. */
|
|
32
|
+
export function parseScope(text, file = "scope") {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
raw = /\.json$/i.test(file) || /^\s*[{[]/.test(text) ? JSON.parse(text) : parseYaml(text);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw new ScopeError(`Can't read ${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
39
|
+
}
|
|
40
|
+
const o = (raw ?? {});
|
|
41
|
+
const list = Array.isArray(raw) ? raw : o.systems;
|
|
42
|
+
if (!Array.isArray(list) || !list.length)
|
|
43
|
+
throw new ScopeError(`${file} needs a "systems" list, each with a name and the paths or hosts that belong to it.`);
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
const systems = list.map((s, i) => {
|
|
46
|
+
const r = (s ?? {});
|
|
47
|
+
const name = typeof r.name === "string" && r.name.trim() ? r.name.trim() : null;
|
|
48
|
+
if (!name)
|
|
49
|
+
throw new ScopeError(`System ${i + 1} in ${file} has no name.`);
|
|
50
|
+
if (seen.has(name.toLowerCase()))
|
|
51
|
+
throw new ScopeError(`Two systems in ${file} are named "${name}".`);
|
|
52
|
+
seen.add(name.toLowerCase());
|
|
53
|
+
const chd = r.cardholderData ?? r.cardholder_data ?? r.chd;
|
|
54
|
+
if (chd !== undefined && typeof chd !== "boolean")
|
|
55
|
+
throw new ScopeError(`System "${name}": cardholderData must be true or false.`);
|
|
56
|
+
const sys = { name, ...(chd !== undefined ? { cardholderData: chd } : {}), paths: strList(r.paths, "paths", name), hosts: strList(r.hosts, "hosts", name), cloud: strList(r.cloud, "cloud", name) };
|
|
57
|
+
if (!sys.paths.length && !sys.hosts.length && !sys.cloud.length)
|
|
58
|
+
throw new ScopeError(`System "${name}" names no paths, hosts or cloud targets.`);
|
|
59
|
+
return sys;
|
|
60
|
+
});
|
|
61
|
+
return { ...(typeof o.name === "string" ? { name: o.name } : {}), systems };
|
|
62
|
+
}
|
|
63
|
+
/** Whether a path in the scanned tree matches a scope entry: a folder ("web/"), a file, or a glob. */
|
|
64
|
+
export function globMatch(pattern, path) {
|
|
65
|
+
const p = pattern.trim().replace(/\\/g, "/").replace(/^\.\//, "");
|
|
66
|
+
if (!p)
|
|
67
|
+
return false;
|
|
68
|
+
if (!/[*?]/.test(p))
|
|
69
|
+
return path === p.replace(/\/$/, "") || path.startsWith(p.endsWith("/") ? p : `${p}/`);
|
|
70
|
+
let re = "";
|
|
71
|
+
for (let i = 0; i < p.length; i++) {
|
|
72
|
+
const c = p[i];
|
|
73
|
+
if (c === "*" && p[i + 1] === "*") {
|
|
74
|
+
re += ".*";
|
|
75
|
+
i++;
|
|
76
|
+
if (p[i + 1] === "/")
|
|
77
|
+
i++;
|
|
78
|
+
}
|
|
79
|
+
else if (c === "*")
|
|
80
|
+
re += "[^/]*";
|
|
81
|
+
else if (c === "?")
|
|
82
|
+
re += "[^/]";
|
|
83
|
+
else
|
|
84
|
+
re += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
85
|
+
}
|
|
86
|
+
return new RegExp(`^${re}$`).test(path);
|
|
87
|
+
}
|
|
88
|
+
const SP800_131 = "NIST SP 800-131A Rev. 2";
|
|
89
|
+
const IR8547 = "NIST IR 8547";
|
|
90
|
+
/** What an algorithm protects, from the rule that found it and where. A first guess for the reviewer to confirm. */
|
|
91
|
+
export function purposeOf(o) {
|
|
92
|
+
if (o.protocol === "tls")
|
|
93
|
+
return "Data in transit (TLS)";
|
|
94
|
+
if (o.protocol === "ssh")
|
|
95
|
+
return "Remote administration (SSH)";
|
|
96
|
+
if (o.certificate)
|
|
97
|
+
return "Server or client identity (certificate)";
|
|
98
|
+
const name = `${o.algorithm} ${o.ruleId ?? ""}`;
|
|
99
|
+
if (/bcrypt|scrypt|argon2|pbkdf2|password|passwd|crypt\b/i.test(name))
|
|
100
|
+
return "Password storage";
|
|
101
|
+
if (/\b(jwt|jws|jose|jwk|token)\b|\b[HRE]S(256|384|512)\b|-jwt-|jwt-/i.test(name))
|
|
102
|
+
return "Token signing";
|
|
103
|
+
switch (o.primitive) {
|
|
104
|
+
case "key-agreement":
|
|
105
|
+
case "kem":
|
|
106
|
+
return "Key exchange";
|
|
107
|
+
case "signature":
|
|
108
|
+
return "Signing";
|
|
109
|
+
case "public-key-encryption":
|
|
110
|
+
return "Key wrapping or encryption";
|
|
111
|
+
case "hash":
|
|
112
|
+
return "Hashing and integrity checks";
|
|
113
|
+
case "mac":
|
|
114
|
+
return "Integrity (MAC)";
|
|
115
|
+
case "kdf":
|
|
116
|
+
return "Key derivation";
|
|
117
|
+
case "block-cipher":
|
|
118
|
+
case "stream-cipher":
|
|
119
|
+
case "ae":
|
|
120
|
+
return /(^|[/_.-])(db|database|storage|s3|bucket|blob|disk|volume|kms|vault|backup|rds|sql)([/_.-]|$)/i.test(o.path ?? "") || /^infra-/.test(o.ruleId ?? "") ? "Data at rest" : "Data encryption";
|
|
121
|
+
case "setting":
|
|
122
|
+
return "Encryption setting";
|
|
123
|
+
default:
|
|
124
|
+
return "Other";
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const CATEGORY = { "tls-version": "Protocol", "tls-suite": "Cipher suite", "tls-policy": "Cloud TLS policy", "ssh-kex": "SSH", "ssh-cipher": "SSH", "ssh-mac": "SSH", "ssh-hostkey": "SSH" };
|
|
128
|
+
const SSH_PART = { "ssh-kex": "key exchange", "ssh-cipher": "cipher", "ssh-mac": "MAC", "ssh-hostkey": "host key" };
|
|
129
|
+
const OUTSIDE = { system: "Outside the scope", cardholderData: "unknown", inScope: false };
|
|
130
|
+
export function placer(scope) {
|
|
131
|
+
const of = (s) => ({ system: s.name, cardholderData: s.cardholderData === undefined ? "unknown" : s.cardholderData ? "yes" : "no", inScope: true });
|
|
132
|
+
const everything = { system: "Everything scanned", cardholderData: "unknown", inScope: true };
|
|
133
|
+
return {
|
|
134
|
+
file: (path) => {
|
|
135
|
+
if (!scope)
|
|
136
|
+
return everything;
|
|
137
|
+
const s = scope.systems.find((x) => x.paths.some((p) => globMatch(p, path)));
|
|
138
|
+
return s ? of(s) : OUTSIDE;
|
|
139
|
+
},
|
|
140
|
+
host: (where) => {
|
|
141
|
+
if (!scope)
|
|
142
|
+
return everything;
|
|
143
|
+
const [h, port] = [where.replace(/:\d+$/, ""), where.match(/:(\d+)$/)?.[1]];
|
|
144
|
+
const s = scope.systems.find((x) => x.hosts.some((raw) => {
|
|
145
|
+
const t = raw.replace(/^(https?|ssh):\/\//i, "").replace(/\/.*$/, "");
|
|
146
|
+
const [th, tp] = [t.replace(/:\d+$/, ""), t.match(/:(\d+)$/)?.[1]];
|
|
147
|
+
return th.toLowerCase() === h.toLowerCase() && (!tp || tp === port);
|
|
148
|
+
}));
|
|
149
|
+
return s ? of(s) : OUTSIDE;
|
|
150
|
+
},
|
|
151
|
+
cloud: (target) => {
|
|
152
|
+
if (!scope)
|
|
153
|
+
return everything;
|
|
154
|
+
const s = scope.systems.find((x) => x.cloud.some((c) => target.toLowerCase().includes(c.toLowerCase())));
|
|
155
|
+
return s ? of(s) : OUTSIDE;
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function protocolRow(p, at) {
|
|
160
|
+
return {
|
|
161
|
+
...at,
|
|
162
|
+
category: CATEGORY[p.kind],
|
|
163
|
+
item: p.kind.startsWith("ssh-") ? `${p.name} (${SSH_PART[p.kind]})` : p.name,
|
|
164
|
+
detail: [p.alias, p.code].filter(Boolean).join(" "),
|
|
165
|
+
purpose: purposeOf({ protocol: p.protocol, algorithm: p.name }),
|
|
166
|
+
where: p.host ?? p.file,
|
|
167
|
+
line: p.line,
|
|
168
|
+
setting: p.setting,
|
|
169
|
+
seen: p.seen,
|
|
170
|
+
strength: p.strength,
|
|
171
|
+
quantum: p.quantum,
|
|
172
|
+
why: p.why,
|
|
173
|
+
source: p.source,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function inventoryRow(i, at, seen = "code") {
|
|
177
|
+
const symmetric = ["block-cipher", "ae", "hash", "mac", "kdf"].includes(i.primitive);
|
|
178
|
+
return {
|
|
179
|
+
...at,
|
|
180
|
+
category: "Algorithm",
|
|
181
|
+
item: i.algorithm,
|
|
182
|
+
detail: [i.keySize ? `${i.keySize}-bit` : "", i.mode ?? ""].filter(Boolean).join(" "),
|
|
183
|
+
purpose: purposeOf({ primitive: i.primitive, algorithm: i.algorithm, path: i.file }),
|
|
184
|
+
where: i.file,
|
|
185
|
+
line: i.line,
|
|
186
|
+
setting: "",
|
|
187
|
+
seen,
|
|
188
|
+
strength: i.caution ? "legacy" : "strong",
|
|
189
|
+
quantum: i.risk === "quantum-vulnerable" ? "breakable" : i.risk === "quantum-safe" || symmetric ? "safe" : "depends",
|
|
190
|
+
why: i.caution ?? i.note ?? (symmetric ? "Approved; key or digest length holds against quantum search." : "Approved post-quantum algorithm."),
|
|
191
|
+
source: i.family.startsWith("ML-KEM") ? "FIPS 203" : i.family.startsWith("ML-DSA") ? "FIPS 204" : i.family.startsWith("SLH-DSA") ? "FIPS 205" : /XMSS|LMS|HSS/.test(i.family) ? "NIST SP 800-208" : SP800_131,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function findingRow(f, at, seen = "code") {
|
|
195
|
+
const weak = f.risk === "weak-now";
|
|
196
|
+
return {
|
|
197
|
+
...at,
|
|
198
|
+
category: f.primitive === "protocol" ? "Protocol" : "Algorithm",
|
|
199
|
+
item: f.algorithm,
|
|
200
|
+
detail: [f.keySize ? `${f.keySize}-bit` : "", f.curve ?? ""].filter(Boolean).join(" "),
|
|
201
|
+
purpose: purposeOf({ primitive: f.primitive, algorithm: f.algorithm, ruleId: f.ruleId, path: f.file, certificate: f.material?.type === "certificate", protocol: f.primitive === "protocol" ? (/ssh/i.test(f.algorithm) ? "ssh" : "tls") : undefined }),
|
|
202
|
+
where: f.file,
|
|
203
|
+
line: f.line,
|
|
204
|
+
setting: "",
|
|
205
|
+
seen,
|
|
206
|
+
strength: weak ? "weak" : "strong",
|
|
207
|
+
quantum: "breakable",
|
|
208
|
+
why: weak ? `${f.title}. ${f.fix}` : `Strong today; ${f.title.charAt(0).toLowerCase()}${f.title.slice(1)}. ${f.fix}`,
|
|
209
|
+
source: weak ? SP800_131 : IR8547,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** Rows from a saved "benthic cloud --format json" result. Named TLS policies are expanded to their suites. */
|
|
213
|
+
export function cloudRows(json, place) {
|
|
214
|
+
const o = (json ?? {});
|
|
215
|
+
if (!Array.isArray(o.findings) && !Array.isArray(o.inventory))
|
|
216
|
+
throw new ScopeError('The cloud file isn\'t a "benthic cloud --format json" result.');
|
|
217
|
+
const rows = [];
|
|
218
|
+
for (const f of [...(o.findings ?? []), ...(o.strengths ?? []).map((s) => ({ ...s, risk: "ok" }))]) {
|
|
219
|
+
const target = String(f.target ?? "cloud");
|
|
220
|
+
const at = place(target);
|
|
221
|
+
const policy = `${f.title ?? ""} ${target}`.match(/\b((?:ELBSecurityPolicy-|AppGwSslPolicy)[A-Za-z0-9-]+)/)?.[1];
|
|
222
|
+
if (policy && namedPolicy(policy)) {
|
|
223
|
+
const p = namedPolicy(policy);
|
|
224
|
+
const where = { file: target, line: 0, setting: `${p.provider} policy ${policy}` };
|
|
225
|
+
for (const v of p.protocols)
|
|
226
|
+
rows.push(protocolRow({ ...protocolUse("tls-version", v, where), seen: "cloud" }, at));
|
|
227
|
+
for (const s of p.suites) {
|
|
228
|
+
const u = protocolUse("tls-suite", s, where);
|
|
229
|
+
if (u)
|
|
230
|
+
rows.push(protocolRow({ ...u, seen: "cloud" }, at));
|
|
231
|
+
}
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (f.risk === "secret")
|
|
235
|
+
continue;
|
|
236
|
+
rows.push({
|
|
237
|
+
...findingRow({ kind: "crypto", ruleId: String(f.ruleId ?? "cloud"), title: String(f.title ?? f.algorithm ?? ""), algorithm: String(f.algorithm ?? "unknown"), primitive: (f.primitive ?? "setting"), risk: (f.risk === "ok" ? "quantum-vulnerable" : f.risk ?? "quantum-vulnerable"), severity: "low", file: target, line: 0, snippet: "", fix: String(f.fix ?? ""), ...(f.keySize ? { keySize: f.keySize } : {}) }, at, "cloud"),
|
|
238
|
+
...(f.risk === "ok" ? { strength: "strong", quantum: "safe", why: "Already quantum-safe.", source: IR8547 } : {}),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
for (const i of o.inventory ?? [])
|
|
242
|
+
rows.push(inventoryRow(i, place(i.file), "cloud"));
|
|
243
|
+
return rows;
|
|
244
|
+
}
|
|
245
|
+
export const sha256 = (s) => createHash("sha256").update(s).digest("hex");
|
|
246
|
+
/** A digest of every rule and table that decides what the pack says, so two runs can be shown to use the same rules. */
|
|
247
|
+
export function rulesDigest() {
|
|
248
|
+
const src = (r) => `${r.source}/${r.flags}`;
|
|
249
|
+
return sha256(JSON.stringify([
|
|
250
|
+
CRYPTO_RULES.map((r) => [r.id, src(r.pattern), String(r.algorithm)]),
|
|
251
|
+
SECRET_RULES.map((r) => [r.id, src(r.pattern)]),
|
|
252
|
+
INVENTORY_RULES.map((r) => [r.id, src(r.pattern)]),
|
|
253
|
+
COMMUNITY_RULES,
|
|
254
|
+
SUITES,
|
|
255
|
+
RULES_UPDATED,
|
|
256
|
+
]));
|
|
257
|
+
}
|
|
258
|
+
/** The commit a folder is at and whether it has changes not yet committed. Empty when it isn't a git checkout. */
|
|
259
|
+
export function gitState(dir) {
|
|
260
|
+
try {
|
|
261
|
+
const opts = { cwd: dir, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 15000 };
|
|
262
|
+
const commit = execFileSync("git", ["rev-parse", "HEAD"], opts).trim();
|
|
263
|
+
if (!/^[0-9a-f]{40,64}$/.test(commit))
|
|
264
|
+
return {};
|
|
265
|
+
const status = execFileSync("git", ["status", "--porcelain", "--untracked-files=no"], opts);
|
|
266
|
+
return { commit, uncommittedChanges: status.trim().length > 0 };
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
return {};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const rowKey = (r) => `${r.system}|${r.category}|${r.item}|${r.where}`;
|
|
273
|
+
/** What is new and what is gone since an earlier pack. */
|
|
274
|
+
export function compareEvidence(previous, rows) {
|
|
275
|
+
const prev = previous ?? {};
|
|
276
|
+
if (prev.kind !== "crypto-inventory" || !Array.isArray(prev.rows))
|
|
277
|
+
throw new ScopeError("The baseline isn't a crypto-inventory.json from an earlier evidence run.");
|
|
278
|
+
const before = new Map(prev.rows.map((r) => [rowKey(r), r]));
|
|
279
|
+
const now = new Map(rows.map((r) => [rowKey(r), r]));
|
|
280
|
+
return { added: [...now.entries()].filter(([k]) => !before.has(k)).map(([, r]) => r), removed: [...before.entries()].filter(([k]) => !now.has(k)).map(([, r]) => r) };
|
|
281
|
+
}
|
|
282
|
+
export function buildEvidence(input) {
|
|
283
|
+
const place = placer(input.scope);
|
|
284
|
+
const rows = [];
|
|
285
|
+
const protocols = input.scanned.protocols ?? [];
|
|
286
|
+
const covered = new Set(protocols.map((p) => `${p.file}:${p.line}`));
|
|
287
|
+
for (const p of protocols)
|
|
288
|
+
rows.push(protocolRow(p, place.file(p.file)));
|
|
289
|
+
for (const p of input.live.uses)
|
|
290
|
+
rows.push(protocolRow(p, place.host(p.host ?? p.file)));
|
|
291
|
+
for (const i of input.scanned.inventory)
|
|
292
|
+
rows.push(inventoryRow(i, place.file(i.file)));
|
|
293
|
+
for (const f of input.findings) {
|
|
294
|
+
if (f.kind !== "crypto")
|
|
295
|
+
continue;
|
|
296
|
+
// The protocol reader already listed what this line turns on, good and bad.
|
|
297
|
+
if (f.primitive === "protocol" && covered.has(`${f.file}:${f.line}`))
|
|
298
|
+
continue;
|
|
299
|
+
rows.push(findingRow(f, place.file(f.file)));
|
|
300
|
+
}
|
|
301
|
+
if (input.cloud !== undefined)
|
|
302
|
+
rows.push(...cloudRows(input.cloud, place.cloud));
|
|
303
|
+
// One row per thing per place: an expanded cipher string and a policy can name the same suite twice on a line.
|
|
304
|
+
const seen = new Set();
|
|
305
|
+
const unique = rows.filter((r) => {
|
|
306
|
+
const k = `${rowKey(r)}|${r.line}`;
|
|
307
|
+
if (seen.has(k))
|
|
308
|
+
return false;
|
|
309
|
+
seen.add(k);
|
|
310
|
+
return true;
|
|
311
|
+
});
|
|
312
|
+
const order = { weak: 0, legacy: 1, strong: 2 };
|
|
313
|
+
const catOrder = ["Cloud TLS policy", "Protocol", "Cipher suite", "SSH", "Algorithm"];
|
|
314
|
+
unique.sort((a, b) => Number(b.inScope) - Number(a.inScope) || a.system.localeCompare(b.system) || catOrder.indexOf(a.category) - catOrder.indexOf(b.category) || order[a.strength] - order[b.strength] || a.item.localeCompare(b.item) || a.where.localeCompare(b.where) || a.line - b.line);
|
|
315
|
+
const certificates = [];
|
|
316
|
+
for (const f of input.findings) {
|
|
317
|
+
const m = f.material;
|
|
318
|
+
if (m?.type !== "certificate")
|
|
319
|
+
continue;
|
|
320
|
+
certificates.push({ system: place.file(f.file).system, subject: m.subject ?? "", issuer: m.issuer ?? "", expires: m.notAfter?.slice(0, 10) ?? "", key: `${f.algorithm}${f.keySize ? `-${f.keySize}` : f.curve ? ` ${f.curve}` : ""}`, where: `${f.file}:${f.line}`, seen: "code" });
|
|
321
|
+
}
|
|
322
|
+
for (const c of input.live.certs)
|
|
323
|
+
certificates.push({ system: place.host(c.host).system, subject: c.subject, issuer: c.issuer, expires: c.notAfter, key: c.key, where: c.host, seen: "live" });
|
|
324
|
+
const pack = {
|
|
325
|
+
tool: "hard-keel-benthic",
|
|
326
|
+
kind: "crypto-inventory",
|
|
327
|
+
version: input.provenance.version,
|
|
328
|
+
title: input.title,
|
|
329
|
+
disclaimer: DISCLAIMER,
|
|
330
|
+
provenance: input.provenance,
|
|
331
|
+
systems: input.scope ? input.scope.systems.map((s) => ({ name: s.name, cardholderData: s.cardholderData === undefined ? "unknown" : s.cardholderData ? "yes" : "no" })) : [{ name: "Everything scanned", cardholderData: "unknown" }],
|
|
332
|
+
rows: unique,
|
|
333
|
+
certificates,
|
|
334
|
+
secrets: input.findings.filter((f) => f.kind === "secret").map((f) => ({ system: place.file(f.file).system, rule: f.ruleId, title: f.title, file: f.file, line: f.line })),
|
|
335
|
+
otherSettings: input.findings.filter((f) => f.kind === "config").map((f) => ({ system: place.file(f.file).system, title: f.title, file: f.file, line: f.line, fix: f.fix })),
|
|
336
|
+
liveErrors: input.live.errors,
|
|
337
|
+
};
|
|
338
|
+
if (input.previous !== undefined)
|
|
339
|
+
pack.changes = compareEvidence(input.previous, unique);
|
|
340
|
+
return pack;
|
|
341
|
+
}
|
|
342
|
+
// ---------- writing it out ----------
|
|
343
|
+
const cell = (s) => String(s).replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\|/g, "\\|").replace(/([\\`*_[\]<>#])/g, "\\$1").trim();
|
|
344
|
+
const where = (r) => (r.line > 0 ? `${r.where}:${r.line}` : r.where);
|
|
345
|
+
const SEEN = { config: "Config", live: "Live", cloud: "Cloud account", code: "Code" };
|
|
346
|
+
const STRENGTH = { strong: "Strong", legacy: "Legacy", weak: "Weak" };
|
|
347
|
+
const QUANTUM = { breakable: "Breakable", safe: "Safe", depends: "Depends on key exchange" };
|
|
348
|
+
export function evidenceCsv(pack) {
|
|
349
|
+
const head = ["System", "Cardholder data", "In scope", "Category", "Item", "Other name or size", "Purpose (confirm)", "Where", "Line", "Setting", "Seen", "Strength", "Quantum computer", "Why", "Source", "Rules updated"];
|
|
350
|
+
const q = (v) => {
|
|
351
|
+
const s = String(v);
|
|
352
|
+
// A cell starting with = + - @ would run as a formula in a spreadsheet.
|
|
353
|
+
const safe = /^[=+\-@\t\r]/.test(s) ? `'${s}` : s;
|
|
354
|
+
return /[",\n]/.test(safe) ? `"${safe.replace(/"/g, '""')}"` : safe;
|
|
355
|
+
};
|
|
356
|
+
const lines = [head.map(q).join(",")];
|
|
357
|
+
for (const r of pack.rows)
|
|
358
|
+
lines.push([r.system, r.cardholderData, r.inScope ? "yes" : "no", r.category, r.item, r.detail, r.purpose, r.where, r.line || "", r.setting, SEEN[r.seen], STRENGTH[r.strength], QUANTUM[r.quantum], r.why, r.source, pack.provenance.rulesUpdated].map(q).join(","));
|
|
359
|
+
return lines.join("\n") + "\n";
|
|
360
|
+
}
|
|
361
|
+
function rowTable(rows) {
|
|
362
|
+
const out = ["| Item | Kind | Purpose | Where | Seen | Strength | Why, and on whose word |", "|---|---|---|---|---|---|---|"];
|
|
363
|
+
for (const r of rows)
|
|
364
|
+
out.push(`| ${cell(r.item)}${r.detail ? ` (${cell(r.detail)})` : ""} | ${cell(r.category)} | ${cell(r.purpose)} | ${cell(where(r))} | ${SEEN[r.seen]} | ${STRENGTH[r.strength]}${r.quantum === "breakable" ? ", quantum-breakable" : ""} | ${cell(r.why)} (${cell(r.source)}) |`);
|
|
365
|
+
return out;
|
|
366
|
+
}
|
|
367
|
+
export function evidenceMarkdown(pack) {
|
|
368
|
+
const p = pack.provenance;
|
|
369
|
+
const inScope = pack.rows.filter((r) => r.inScope);
|
|
370
|
+
const out = pack.rows.filter((r) => !r.inScope);
|
|
371
|
+
const count = (rs, s) => rs.filter((r) => r.strength === s).length;
|
|
372
|
+
const date = p.createdAt.slice(0, 10);
|
|
373
|
+
const L = [];
|
|
374
|
+
L.push(`# Cryptographic inventory: ${cell(pack.title)}`, "");
|
|
375
|
+
L.push(`Prepared ${date} with Hard Keel Benthic ${p.version}. Rules last checked against current guidance on ${p.rulesUpdated}.`, "");
|
|
376
|
+
L.push(`**${DISCLAIMER}**`, "");
|
|
377
|
+
L.push("## Summary", "");
|
|
378
|
+
const chd = pack.systems.filter((s) => s.cardholderData === "yes").length;
|
|
379
|
+
L.push(`- ${pack.systems.length} system${pack.systems.length === 1 ? "" : "s"} in scope${pack.systems.some((s) => s.cardholderData !== "unknown") ? `, ${chd} of them handling cardholder data` : ""}.`);
|
|
380
|
+
const cats = (c) => inScope.filter((r) => c.includes(r.category)).length;
|
|
381
|
+
L.push(`- ${cats(["Protocol", "Cipher suite", "Cloud TLS policy"])} TLS protocol versions, cipher suites and policies, ${cats(["SSH"])} SSH algorithms and ${cats(["Algorithm"])} other algorithms in use, plus ${pack.certificates.length} certificate${pack.certificates.length === 1 ? "" : "s"}.`);
|
|
382
|
+
L.push(`- ${count(inScope, "weak")} weak and ${count(inScope, "legacy")} legacy, listed first in each system. The rest are rated strong.`);
|
|
383
|
+
if (out.length)
|
|
384
|
+
L.push(`- ${out.length} more found outside the scope, in Appendix A.`);
|
|
385
|
+
if (pack.secrets.length)
|
|
386
|
+
L.push(`- ${pack.secrets.length} leaked secret${pack.secrets.length === 1 ? "" : "s"}, kept apart in Appendix B.`);
|
|
387
|
+
if (pack.liveErrors.length)
|
|
388
|
+
L.push(`- ${pack.liveErrors.length} host${pack.liveErrors.length === 1 ? "" : "s"} couldn't be reached for the live check: ${pack.liveErrors.map((e) => cell(e.target)).join(", ")}.`);
|
|
389
|
+
L.push("");
|
|
390
|
+
L.push("## How this pack maps to PCI DSS 12.3.3", "");
|
|
391
|
+
L.push("Requirement text paraphrased; read it against the standard itself.", "");
|
|
392
|
+
L.push("| What the requirement asks for | Where this pack answers it |", "|---|---|");
|
|
393
|
+
L.push("| An up-to-date inventory of all cipher suites and protocols in use | Inventory, and crypto-inventory.csv. Strong items are listed, not only the ones to fix. |");
|
|
394
|
+
L.push("| The purpose of each, and where it is used | Purpose and Where columns, grouped by system from the scope file. Purpose is inferred; confirm it in the review. |");
|
|
395
|
+
L.push("| Active monitoring of industry trends on whether each is still viable | Strength column with its source per row, and the date the rules were last checked. Run the pack again and compare: Changes since the last review. |");
|
|
396
|
+
L.push("| A documented strategy to respond to anticipated changes in cryptographic vulnerabilities | When an algorithm breaks. For the slow, scheduled change to post-quantum encryption, the migration plan. |");
|
|
397
|
+
L.push("| Reviewed at least once every 12 months | Review record. |");
|
|
398
|
+
L.push("");
|
|
399
|
+
L.push("Nearby requirements:", "");
|
|
400
|
+
L.push("- **4.2.1** (strong cryptography for cardholder data in transit): the TLS rows of systems marked as handling cardholder data, and the Certificates section.");
|
|
401
|
+
L.push("- **4.2.1.1** (inventory of trusted keys and certificates): the Certificates section lists the certificates found in files and on the servers checked. It is not a full key inventory.");
|
|
402
|
+
L.push("- **3.6 and 3.7** (key management procedures): not covered by this pack.");
|
|
403
|
+
L.push("");
|
|
404
|
+
L.push("## Inventory", "");
|
|
405
|
+
if (!inScope.length)
|
|
406
|
+
L.push("Nothing in scope was found.", "");
|
|
407
|
+
for (const sys of [...new Set(inScope.map((r) => r.system))]) {
|
|
408
|
+
const rs = inScope.filter((r) => r.system === sys);
|
|
409
|
+
const c = rs[0].cardholderData;
|
|
410
|
+
L.push(`### ${cell(sys)}`, "");
|
|
411
|
+
L.push(`Cardholder data: ${c === "yes" ? "yes" : c === "no" ? "no" : "not stated in the scope file"}. ${rs.length} item${rs.length === 1 ? "" : "s"}: ${count(rs, "weak")} weak, ${count(rs, "legacy")} legacy, ${count(rs, "strong")} strong.`, "");
|
|
412
|
+
L.push(...rowTable(rs), "");
|
|
413
|
+
}
|
|
414
|
+
L.push("## Certificates", "");
|
|
415
|
+
if (!pack.certificates.length)
|
|
416
|
+
L.push("No certificates were found in the files scanned or on the servers checked.", "");
|
|
417
|
+
else {
|
|
418
|
+
L.push("| Subject | Issuer | Expires | Key | Where | System |", "|---|---|---|---|---|---|");
|
|
419
|
+
for (const c of [...pack.certificates].sort((a, b) => a.expires.localeCompare(b.expires)))
|
|
420
|
+
L.push(`| ${cell(c.subject)} | ${cell(c.issuer)} | ${cell(c.expires)} | ${cell(c.key)} | ${cell(c.where)} | ${cell(c.system)} |`);
|
|
421
|
+
L.push("");
|
|
422
|
+
}
|
|
423
|
+
if (pack.changes) {
|
|
424
|
+
L.push("## Changes since the last review", "");
|
|
425
|
+
L.push(`Compared with ${cell(p.baselineFile ?? "the earlier pack")}: ${pack.changes.added.length} new, ${pack.changes.removed.length} gone.`, "");
|
|
426
|
+
for (const [label, rs] of [["New", pack.changes.added], ["Gone", pack.changes.removed]]) {
|
|
427
|
+
if (!rs.length)
|
|
428
|
+
continue;
|
|
429
|
+
L.push(`**${label}**`, "");
|
|
430
|
+
for (const r of rs.slice(0, 200))
|
|
431
|
+
L.push(`- ${cell(r.item)} (${cell(r.category)}, ${STRENGTH[r.strength].toLowerCase()}) in ${cell(r.system)}, ${cell(where(r))}`);
|
|
432
|
+
if (rs.length > 200)
|
|
433
|
+
L.push(`- and ${rs.length - 200} more, in crypto-inventory.json`);
|
|
434
|
+
L.push("");
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
L.push("## When an algorithm breaks", "");
|
|
438
|
+
L.push("The plan for sudden change: a cipher, protocol or key size found broken or deprecated between reviews. Fill in the blanks and keep it with this pack.", "");
|
|
439
|
+
L.push("1. **What starts it.** A deprecation or new guidance from NIST, the IETF or PCI SSC; a published practical attack; a vendor or CVE advisory for a library or device listed here; or a weak item found in a review.");
|
|
440
|
+
L.push("2. **Who decides.** Owner: ____________________ (role: ______________). Backup: ____________________. They decide whether it applies, how urgent it is, and sign off the change.");
|
|
441
|
+
L.push("3. **How fast.** A practical attack on something protecting cardholder data: turn it off within ______ days. A deprecation with no practical attack: within ______ days. Record the dates in the review record.");
|
|
442
|
+
L.push("4. **How to turn it off.** The Where and Setting columns name the file, policy or server for each item. Make the change there, then block it from coming back with a rule in the scanner's policy file (.benthic.yml) checked in CI.");
|
|
443
|
+
L.push("5. **Test and roll back.** Check the change with this pack's live check before and after. Keep the previous setting ready to restore if clients fail, and note any exception with a reason and an end date.");
|
|
444
|
+
L.push("6. **Incident response.** If keys or traffic may already have been exposed, hand over to your incident response plan (PCI DSS 12.10): rotate keys, reissue certificates, and assess what was protected.");
|
|
445
|
+
L.push("7. **Record it.** Run this pack again, compare it with this one, and add the result to the review record.");
|
|
446
|
+
L.push("");
|
|
447
|
+
L.push("## Review record", "");
|
|
448
|
+
L.push("A decision for each weak or legacy item, and one for the strong items as a group.", "");
|
|
449
|
+
const toDecide = new Map();
|
|
450
|
+
for (const r of inScope)
|
|
451
|
+
if (r.strength !== "strong")
|
|
452
|
+
toDecide.set(`${r.system}|${r.item}`, r);
|
|
453
|
+
if (toDecide.size) {
|
|
454
|
+
L.push("| System | Item | Strength | Decision (accept, fix or exception) | Reason, owner and date |", "|---|---|---|---|---|");
|
|
455
|
+
for (const r of toDecide.values())
|
|
456
|
+
L.push(`| ${cell(r.system)} | ${cell(r.item)} | ${STRENGTH[r.strength]} | | |`);
|
|
457
|
+
L.push("");
|
|
458
|
+
}
|
|
459
|
+
L.push(`All ${count(inScope, "strong")} items rated strong: accepted / not accepted (circle one). Notes: ______________________________`, "");
|
|
460
|
+
L.push("Reviewed by: ____________________ Role: ____________________", "");
|
|
461
|
+
L.push("Date of review: ____________ Next review due: ____________ (12 months at most)", "");
|
|
462
|
+
L.push("Signature: ______________________________", "");
|
|
463
|
+
L.push("## Appendix A: found outside the scope", "");
|
|
464
|
+
if (!out.length)
|
|
465
|
+
L.push(pack.title && p.scopeFile ? "Everything found fell inside the scope." : "No scope file was given, so everything scanned is in the inventory above.", "");
|
|
466
|
+
else {
|
|
467
|
+
L.push("These are in the scanned files but not in any system the scope file names: test data, training material, tools. Listed so nothing is hidden; move a path into a system in the scope file if it belongs there.", "");
|
|
468
|
+
L.push(...rowTable(out), "");
|
|
469
|
+
}
|
|
470
|
+
L.push("## Appendix B: leaked secrets", "");
|
|
471
|
+
if (!pack.secrets.length)
|
|
472
|
+
L.push("None found.", "");
|
|
473
|
+
else {
|
|
474
|
+
L.push("Passwords, tokens and private keys written into files. They are not cipher suites or protocols, so they stay out of the inventory, but each one needs revoking and rotating (key management, and your secrets process).", "");
|
|
475
|
+
L.push("| Kind | Where | System |", "|---|---|---|");
|
|
476
|
+
for (const s of pack.secrets)
|
|
477
|
+
L.push(`| ${cell(s.title)} | ${cell(`${s.file}:${s.line}`)} | ${cell(s.system)} |`);
|
|
478
|
+
L.push("");
|
|
479
|
+
}
|
|
480
|
+
L.push("## Appendix C: other encryption settings to fix", "");
|
|
481
|
+
if (!pack.otherSettings.length)
|
|
482
|
+
L.push("None found.", "");
|
|
483
|
+
else {
|
|
484
|
+
L.push("| Setting | Where | System | Fix |", "|---|---|---|---|");
|
|
485
|
+
for (const s of pack.otherSettings)
|
|
486
|
+
L.push(`| ${cell(s.title)} | ${cell(`${s.file}:${s.line}`)} | ${cell(s.system)} | ${cell(s.fix)} |`);
|
|
487
|
+
L.push("");
|
|
488
|
+
}
|
|
489
|
+
L.push("## Appendix D: how this pack was made", "");
|
|
490
|
+
L.push(`- Scanner: Hard Keel Benthic ${p.version}`);
|
|
491
|
+
L.push(`- Rules last checked: ${p.rulesUpdated}; rules digest (SHA-256): ${p.rulesDigest}`);
|
|
492
|
+
L.push(`- Folder: ${cell(p.folder)}${p.commit ? `, at commit ${p.commit}${p.uncommittedChanges ? ", with changes not yet committed" : ", no uncommitted changes"}` : " (not a git checkout)"}`);
|
|
493
|
+
if (p.scopeFile)
|
|
494
|
+
L.push(`- Scope file: ${cell(p.scopeFile)} (SHA-256 ${p.scopeSha256})`);
|
|
495
|
+
else
|
|
496
|
+
L.push("- Scope file: none; everything scanned counts as in scope");
|
|
497
|
+
if (p.cloudFile)
|
|
498
|
+
L.push(`- Cloud result: ${cell(p.cloudFile)} (SHA-256 ${p.cloudSha256})`);
|
|
499
|
+
if (p.baselineFile)
|
|
500
|
+
L.push(`- Compared with: ${cell(p.baselineFile)} (SHA-256 ${p.baselineSha256})`);
|
|
501
|
+
L.push(`- Live checks: ${p.liveHosts.length ? `${p.liveHosts.map(cell).join(", ")}; ${p.handshakes} read-only handshake${p.handshakes === 1 ? "" : "s"}` : "none"}`);
|
|
502
|
+
L.push(`- Made: ${p.createdAt}`);
|
|
503
|
+
L.push(`- To run it again: \`${p.command.replace(/`/g, "'")}\``);
|
|
504
|
+
L.push("- manifest.sha256 holds the SHA-256 of this file, the CSV and the JSON, so later changes to any of them show.");
|
|
505
|
+
L.push("");
|
|
506
|
+
L.push("Live results depend on the servers at the time of the run; the same commit, rules and scope give the same file-based results.", "");
|
|
507
|
+
return L.join("\n");
|
|
508
|
+
}
|
|
509
|
+
/** The manifest of output hashes, in the format sha256sum reads. */
|
|
510
|
+
export function manifest(files) {
|
|
511
|
+
return files.map((f) => `${sha256(f.body)} ${f.name}`).join("\n") + "\n";
|
|
512
|
+
}
|
package/dist/ignore.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// .benthic-ignore: findings a team has looked at and marked not an issue.
|
|
4
|
+
//
|
|
5
|
+
// # comments start with #
|
|
6
|
+
// rule:py-weak-hash a rule, everywhere
|
|
7
|
+
// legacy/ every finding under a folder
|
|
8
|
+
// src/old.py every finding in one file
|
|
9
|
+
// src/old.py:py-weak-hash one rule in one file
|
|
10
|
+
// example.com:443:web-tls-static-rsa a known leftover on a website (benthic map)
|
|
11
|
+
// example.com every finding on a website, any port (benthic map)
|
|
12
|
+
//
|
|
13
|
+
// Windows-style paths (legacy\old.py) work too.
|
|
14
|
+
// Leaked keys and passwords can't be ignored by rule or by folder, only file by file, so one line can't hide
|
|
15
|
+
// every secret. Whatever the file hides is counted in the output.
|
|
16
|
+
export const IGNORE_FILE = ".benthic-ignore";
|
|
17
|
+
/** The ignore file's name before the scanner was called Benthic. Still read when there's no .benthic-ignore. */
|
|
18
|
+
export const OLD_IGNORE_FILE = ".quantum-scan-ignore";
|
|
19
|
+
/** The ignore file in a folder: .benthic-ignore, or the older name when only that one is there. */
|
|
20
|
+
export function ignoreFileIn(dir, exists) {
|
|
21
|
+
const path = `${dir.replace(/[\\/]+$/, "")}/${IGNORE_FILE}`;
|
|
22
|
+
const old = `${dir.replace(/[\\/]+$/, "")}/${OLD_IGNORE_FILE}`;
|
|
23
|
+
return !exists(path) && exists(old) ? old : path;
|
|
24
|
+
}
|
|
25
|
+
export function parseIgnore(text) {
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
28
|
+
const line = raw.replace(/\s+#.*$/, "").trim();
|
|
29
|
+
if (!line || line.startsWith("#"))
|
|
30
|
+
continue;
|
|
31
|
+
if (line.startsWith("rule:")) {
|
|
32
|
+
const rule = line.slice(5).trim();
|
|
33
|
+
if (rule)
|
|
34
|
+
out.push({ rule });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const norm = (p) => p.split("\\").join("/").replace(/^\.\//, "");
|
|
38
|
+
// A rule id always has a letter, so "example.com:443" stays a place, not a rule called 443.
|
|
39
|
+
const m = line.match(/^(.+?):([a-z0-9-]*[a-z][a-z0-9-]*)$/);
|
|
40
|
+
if (m && !/^[a-zA-Z]$/.test(m[1]))
|
|
41
|
+
out.push({ path: norm(m[1]), rule: m[2] });
|
|
42
|
+
else
|
|
43
|
+
out.push({ path: norm(line) });
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
function pathMatches(entry, file) {
|
|
48
|
+
if (entry.endsWith("/"))
|
|
49
|
+
return file.startsWith(entry);
|
|
50
|
+
// "example.com" covers "example.com:443"; "src/a.py" covers "src/a.py:12" in the encryption map.
|
|
51
|
+
return file === entry || file.startsWith(`${entry}/`) || file.startsWith(`${entry}:`);
|
|
52
|
+
}
|
|
53
|
+
/** The same matching, for encryption map findings (websites, this machine), where the place is a target. */
|
|
54
|
+
export function applyIgnoreTargets(findings, entries) {
|
|
55
|
+
const kept = [];
|
|
56
|
+
const accepted = [];
|
|
57
|
+
for (const f of findings) {
|
|
58
|
+
const hit = entries.some((e) => {
|
|
59
|
+
if (e.rule && e.path)
|
|
60
|
+
return e.rule === f.ruleId && pathMatches(e.path, f.target);
|
|
61
|
+
if (e.rule)
|
|
62
|
+
return e.rule === f.ruleId && f.risk !== "secret";
|
|
63
|
+
return e.path ? pathMatches(e.path, f.target) : false;
|
|
64
|
+
});
|
|
65
|
+
(hit ? accepted : kept).push(f);
|
|
66
|
+
}
|
|
67
|
+
return { kept, accepted };
|
|
68
|
+
}
|
|
69
|
+
export function applyIgnore(findings, entries) {
|
|
70
|
+
const kept = [];
|
|
71
|
+
const ignored = {};
|
|
72
|
+
for (const f of findings) {
|
|
73
|
+
const hit = entries.some((e) => {
|
|
74
|
+
if (e.rule && e.path)
|
|
75
|
+
return e.rule === f.ruleId && pathMatches(e.path, f.file);
|
|
76
|
+
if (e.rule)
|
|
77
|
+
return e.rule === f.ruleId && f.kind !== "secret";
|
|
78
|
+
if (!e.path)
|
|
79
|
+
return false;
|
|
80
|
+
if (f.kind === "secret")
|
|
81
|
+
return e.path === f.file.split("\\").join("/");
|
|
82
|
+
return pathMatches(e.path, f.file);
|
|
83
|
+
});
|
|
84
|
+
if (hit)
|
|
85
|
+
ignored[f.ruleId] = (ignored[f.ruleId] ?? 0) + 1;
|
|
86
|
+
else
|
|
87
|
+
kept.push(f);
|
|
88
|
+
}
|
|
89
|
+
return { kept, ignored };
|
|
90
|
+
}
|