@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/rules.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// Detection rules for quantum-vulnerable and already-weak cryptography.
|
|
4
|
+
// Each rule is a line-level regex scoped to a set of file languages.
|
|
5
|
+
import { sshKeyDetail } from "./der.js";
|
|
6
|
+
import { groupsLackMlkem } from "./infra.js";
|
|
7
|
+
const KEM_FIX = "Move key exchange to ML-KEM (FIPS 203), or hybrid X25519 + ML-KEM-768 for TLS.";
|
|
8
|
+
const SIG_FIX = "Move to ML-DSA (FIPS 204) or SLH-DSA (FIPS 205) signatures.";
|
|
9
|
+
const HASH_FIX = "Switch to SHA-256 or SHA-3, unless it is only a non-security checksum.";
|
|
10
|
+
const CIPHER_FIX = "Switch to AES-256-GCM.";
|
|
11
|
+
const TLS_FIX = "Require TLS 1.2 or later, ideally TLS 1.3.";
|
|
12
|
+
// Classification of every algorithm the rules can emit.
|
|
13
|
+
export const ALGORITHMS = {
|
|
14
|
+
RSA: { primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: `${KEM_FIX} For signatures, use ML-DSA (FIPS 204).` },
|
|
15
|
+
"RSA signature": { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
16
|
+
"RSA encryption": { primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
17
|
+
ECDSA: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
18
|
+
EC: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: `${SIG_FIX} For key exchange, use ML-KEM (FIPS 203).` },
|
|
19
|
+
ECDH: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
20
|
+
DH: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
21
|
+
X25519: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
22
|
+
X448: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
23
|
+
Ed25519: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
24
|
+
Ed448: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
25
|
+
DSA: { primitive: "signature", risk: "weak-now", severity: "high", fix: `DSA is no longer approved. ${SIG_FIX}` },
|
|
26
|
+
MD5: { primitive: "hash", risk: "weak-now", severity: "medium", fix: HASH_FIX },
|
|
27
|
+
"SHA-1": { primitive: "hash", risk: "weak-now", severity: "medium", fix: HASH_FIX },
|
|
28
|
+
DES: { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
29
|
+
"3DES": { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
30
|
+
RC4: { primitive: "stream-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
31
|
+
"ECB mode": { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
32
|
+
"TLS 1.0/1.1": { primitive: "protocol", risk: "weak-now", severity: "high", fix: TLS_FIX },
|
|
33
|
+
"Weak TLS ciphers": { primitive: "protocol", risk: "weak-now", severity: "high", fix: "Allow only AES-GCM and ChaCha20 cipher suites." },
|
|
34
|
+
"SSH key exchange": { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: "Offer mlkem768x25519-sha256 first (OpenSSH 9.9+, Go x/crypto 0.31+), or sntrup761x25519-sha512, keeping the classical methods after it." },
|
|
35
|
+
"TLS key exchange": { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: "Put the hybrid group X25519MLKEM768 first in the list (OpenSSL 3.5+, BoringSSL, Go 1.24+), keeping the classical groups after it for older clients." },
|
|
36
|
+
};
|
|
37
|
+
// Maps a key-type word used by many APIs to an algorithm name.
|
|
38
|
+
function keyType(word) {
|
|
39
|
+
const w = word.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
40
|
+
if (w.startsWith("rsa"))
|
|
41
|
+
return "RSA";
|
|
42
|
+
if (w === "ec" || w === "ecdsa")
|
|
43
|
+
return "ECDSA";
|
|
44
|
+
if (w === "ecdh")
|
|
45
|
+
return "ECDH";
|
|
46
|
+
if (w === "dsa")
|
|
47
|
+
return "DSA";
|
|
48
|
+
if (w === "dh" || w === "diffiehellman")
|
|
49
|
+
return "DH";
|
|
50
|
+
if (w === "ed25519")
|
|
51
|
+
return "Ed25519";
|
|
52
|
+
if (w === "ed448")
|
|
53
|
+
return "Ed448";
|
|
54
|
+
if (w === "x25519")
|
|
55
|
+
return "X25519";
|
|
56
|
+
if (w === "x448")
|
|
57
|
+
return "X448";
|
|
58
|
+
if (w === "xdh")
|
|
59
|
+
return "X25519";
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function hashOrCipher(word) {
|
|
63
|
+
const w = word.toLowerCase();
|
|
64
|
+
if (w === "md5")
|
|
65
|
+
return "MD5";
|
|
66
|
+
if (w === "sha1" || w === "sha-1")
|
|
67
|
+
return "SHA-1";
|
|
68
|
+
if (w.startsWith("des-ede") || w === "desede" || w.startsWith("des3") || w === "3des")
|
|
69
|
+
return "3DES";
|
|
70
|
+
if (w.startsWith("des"))
|
|
71
|
+
return "DES";
|
|
72
|
+
if (w.startsWith("rc4") || w === "arc4" || w === "arcfour")
|
|
73
|
+
return "RC4";
|
|
74
|
+
if (/ecb/.test(w))
|
|
75
|
+
return "ECB mode";
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
/** The named curve a line mentions, in its standard name: ec.SECP256R1(), "prime256v1", elliptic.P384(). */
|
|
79
|
+
export function curveIn(line) {
|
|
80
|
+
const m = line.match(/(?<![A-Za-z0-9])(?:secp256k1|SECP256K1|(?:secp|SECP|prime|nistp|P|p|Curve|curve)[-_]?(192|224|256|384|521)(?:r1|R1|v1|r2)?|brainpool[Pp](256|384|512)r1)(?![A-Za-z0-9])/);
|
|
81
|
+
if (!m)
|
|
82
|
+
return undefined;
|
|
83
|
+
if (/^secp256k1$/i.test(m[0]))
|
|
84
|
+
return "secp256k1";
|
|
85
|
+
if (m[2])
|
|
86
|
+
return `brainpoolP${m[2]}r1`;
|
|
87
|
+
return `P-${m[1]}`;
|
|
88
|
+
}
|
|
89
|
+
/** A JSON Web Key by its kty, using its crv, use and alg on the same line where present. */
|
|
90
|
+
function jwkAlgorithm(kty, line) {
|
|
91
|
+
const crv = line.match(/["']?crv["']?\s*:\s*["'](Ed25519|Ed448|X25519|X448)["']/)?.[1];
|
|
92
|
+
const enc = /["']?use["']?\s*:\s*["']enc["']|["']?alg["']?\s*:\s*["'](?:RSA-OAEP|RSA1_5|ECDH-ES)/.test(line);
|
|
93
|
+
if (kty === "RSA")
|
|
94
|
+
return enc ? "RSA encryption" : "RSA signature";
|
|
95
|
+
if (kty === "EC")
|
|
96
|
+
return enc ? "ECDH" : "EC";
|
|
97
|
+
if (kty === "OKP")
|
|
98
|
+
return crv ?? (enc ? "X25519" : "Ed25519");
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const ETH = { curve: "secp256k1" };
|
|
102
|
+
const CODE_AND_CONFIG = ["js", "python", "go", "java", "config"];
|
|
103
|
+
/** The hash and curve a JOSE signature name fixes: ES256 signs over SHA-256 on P-256, and so on. */
|
|
104
|
+
function joseHash(alg) {
|
|
105
|
+
const m = alg.toUpperCase().match(/^ES(256|384|512)(K?)$/);
|
|
106
|
+
if (!m)
|
|
107
|
+
return {};
|
|
108
|
+
// RFC 7518 and RFC 8812 tie each ES name to one curve: ES256 is P-256, ES384 P-384, ES512 P-521, ES256K secp256k1.
|
|
109
|
+
const curve = m[2] ? "secp256k1" : { "256": "P-256", "384": "P-384", "512": "P-521" }[m[1]];
|
|
110
|
+
return { hash: `SHA-${m[1]}`, curve };
|
|
111
|
+
}
|
|
112
|
+
/** The hash a signature name like SHA256withECDSA fixes. */
|
|
113
|
+
function hashIn(text) {
|
|
114
|
+
const m = text.match(/\bSHA-?(1|224|256|384|512)with/i);
|
|
115
|
+
return m ? { hash: m[1] === "1" ? "SHA-1" : `SHA-${m[1]}` } : {};
|
|
116
|
+
}
|
|
117
|
+
export const CRYPTO_RULES = [
|
|
118
|
+
// ---------- Python ----------
|
|
119
|
+
{ id: "py-rsa-generate", langs: ["python"], pattern: /\brsa\.generate_private_key\s*\(|\bRSA\.generate\s*\(/, algorithm: "RSA", keySize: /(?:key_size\s*=\s*|RSA\.generate\s*\(\s*)(\d{3,5})/ },
|
|
120
|
+
{ id: "py-rsa-padding", langs: ["python"], pattern: /\bPKCS1_OAEP\b|\bpadding\.OAEP\s*\(/, algorithm: "RSA encryption" },
|
|
121
|
+
{ id: "py-rsa-sign", langs: ["python"], pattern: /\bpadding\.PSS\s*\(|\bpadding\.PKCS1v15\s*\(|\bpkcs1_15\.new\s*\(/, algorithm: "RSA signature" },
|
|
122
|
+
{ id: "py-ec-generate", langs: ["python"], pattern: /\bec\.generate_private_key\s*\(|\bECC\.generate\s*\(|\bSigningKey\.generate\s*\(/, algorithm: "ECDSA" },
|
|
123
|
+
{ id: "py-ecdh", langs: ["python"], pattern: /\bec\.ECDH\s*\(/, algorithm: "ECDH" },
|
|
124
|
+
{ id: "py-dsa", langs: ["python"], pattern: /\bdsa\.generate_private_key\s*\(|\bDSA\.generate\s*\(/, algorithm: "DSA" },
|
|
125
|
+
{ id: "py-dh", langs: ["python"], pattern: /\bdh\.generate_parameters\s*\(/, algorithm: "DH" },
|
|
126
|
+
{ id: "py-ed25519", langs: ["python"], pattern: /\bEd25519PrivateKey\b/, algorithm: "Ed25519" },
|
|
127
|
+
{ id: "py-x25519", langs: ["python"], pattern: /\bX25519PrivateKey\b/, algorithm: "X25519" },
|
|
128
|
+
{ id: "py-ecdsa-sign", langs: ["python"], pattern: /\bec\.ECDSA\s*\(/, algorithm: "ECDSA" },
|
|
129
|
+
{ id: "py-rsa-lib", langs: ["python"], pattern: /\brsa\.newkeys\s*\(|\bRSAKey\.generate\s*\(/, algorithm: "RSA", keySize: /(?:newkeys\s*\(\s*|RSAKey\.generate\s*\(\s*(?:bits\s*=\s*)?)(\d{3,5})/ },
|
|
130
|
+
// pyOpenSSL: key.generate_key(crypto.TYPE_RSA, 2048).
|
|
131
|
+
{ id: "py-openssl-key", langs: ["python"], pattern: /\.generate_key\s*\(\s*(?:\w+\.)?TYPE_(RSA|DSA)\b/, algorithm: (m) => m[1], keySize: /TYPE_RSA\s*,\s*(\d{3,5})/ },
|
|
132
|
+
{ id: "py-weak-hash", langs: ["python"], pattern: /\bhashlib\.(md5|sha1)\s*\(|\bhashes\.(MD5|SHA1)\s*\(|hashlib\.new\s*\(\s*['"](md5|sha1)['"]/, algorithm: (m) => hashOrCipher(m[1] ?? m[2] ?? m[3] ?? "") },
|
|
133
|
+
{ id: "py-weak-cipher", langs: ["python"], pattern: /\balgorithms\.(TripleDES|ARC4)\s*\(|\b(DES3|DES|ARC4)\.new\s*\(/, algorithm: (m) => hashOrCipher((m[1] ?? m[2] ?? "").replace("TripleDES", "3des")) },
|
|
134
|
+
{ id: "py-ecb", langs: ["python"], pattern: /\bmodes\.ECB\s*\(|\bMODE_ECB\b/, algorithm: "ECB mode" },
|
|
135
|
+
// ---------- JavaScript / TypeScript ----------
|
|
136
|
+
{ id: "js-generate-keypair", langs: ["js"], pattern: /\bgenerateKeyPair(?:Sync)?\s*\(\s*['"`]([a-z0-9-]+)['"`]/i, algorithm: (m) => keyType(m[1]), keySize: /modulusLength\s*:\s*(\d{3,5})/ },
|
|
137
|
+
{ id: "js-ecdh", langs: ["js"], pattern: /\bcreateECDH\s*\(/, algorithm: "ECDH" },
|
|
138
|
+
{ id: "js-dh", langs: ["js"], pattern: /\bcreateDiffieHellman(?:Group)?\s*\(/, algorithm: "DH" },
|
|
139
|
+
{ id: "js-webcrypto", langs: ["js"], pattern: /name\s*:\s*['"`](RSA-OAEP|RSASSA-PKCS1-v1_5|RSA-PSS|ECDSA|ECDH|Ed25519|X25519)['"`]/, algorithm: (m) => ({ "RSA-OAEP": "RSA encryption", "RSASSA-PKCS1-v1_5": "RSA signature", "RSA-PSS": "RSA signature" }[m[1]] ?? keyType(m[1])), keySize: /modulusLength\s*:\s*(\d{3,5})/ },
|
|
140
|
+
{ id: "js-jwt-alg", langs: ["js"], pattern: /\balgorithms?\s*:\s*\[?\s*['"`]((?:RS|PS|ES)(?:256|384|512)|EdDSA)['"`]/, algorithm: (m) => (m[1].startsWith("ES") ? "ECDSA" : m[1] === "EdDSA" ? "Ed25519" : "RSA signature"), detail: (m) => joseHash(m[1]) },
|
|
141
|
+
// Signing and key encryption by name, as JWT, JOSE and signing libraries spell them.
|
|
142
|
+
{ id: "js-sign-rsa", langs: ["js"], pattern: /\b(?:createSign|createVerify)\s*\(\s*['"`](?:RSA-SHA|sha\d+WithRSAEncryption)/i, algorithm: "RSA signature" },
|
|
143
|
+
{ id: "js-sign-ecdsa", langs: ["js"], pattern: /\b(?:createSign|createVerify)\s*\(\s*['"`]ecdsa-with-SHA/i, algorithm: "ECDSA" },
|
|
144
|
+
{ id: "js-rsa-encrypt", langs: ["js"], pattern: /\b(?:publicEncrypt|privateDecrypt)\s*\(|\bRSA_PKCS1_OAEP_PADDING\b/, algorithm: "RSA encryption" },
|
|
145
|
+
{ id: "js-jwk-kty", langs: ["js"], pattern: /\bkty\s*:\s*['"`](RSA|EC|OKP)['"`]/, algorithm: (m) => jwkAlgorithm(m[1], m.input ?? ""), detail: (m) => ({ curve: curveIn(m.input ?? "") }) },
|
|
146
|
+
{ id: "js-jwk-crv", langs: ["js"], pattern: /\bcrv\s*:\s*['"`](P-256|P-384|P-521|secp256k1|Ed25519|Ed448|X25519|X448)['"`]/, algorithm: (m) => (/^(Ed|X)/.test(m[1]) ? m[1] : "EC"), detail: (m) => ({ curve: curveIn(m[1]) }) },
|
|
147
|
+
{ id: "js-elliptic", langs: ["js"], pattern: /\bnew\s+(?:elliptic\.)?(?:EC|ec|eddsa)\s*\(\s*['"`](secp256k1|p256|p384|p521|curve25519|ed25519)['"`]/, algorithm: (m) => (m[1] === "ed25519" ? "Ed25519" : m[1] === "curve25519" ? "X25519" : "ECDSA") },
|
|
148
|
+
{ id: "js-noble-curves", langs: ["js"], pattern: /['"`]@noble\/curves\/(secp256k1|p256|p384|p521|nist|ed25519|ed448)(?:\.js)?['"`]/, algorithm: (m) => (m[1] === "ed25519" ? "Ed25519" : m[1] === "ed448" ? "Ed448" : "ECDSA") },
|
|
149
|
+
{ id: "js-tweetnacl", langs: ["js"], pattern: /\bnacl\.(sign|box)(?:\.keyPair)?\s*\(/, algorithm: (m) => (m[1] === "sign" ? "Ed25519" : "X25519") },
|
|
150
|
+
{ id: "jwt-alg-name", langs: ["js", "python", "java", "go"], pattern: /['"`]((?:RS|PS|ES)(?:256|384|512)|ES256K|EdDSA)['"`]/, algorithm: (m) => (m[1].startsWith("ES") ? "ECDSA" : m[1] === "EdDSA" ? "Ed25519" : "RSA signature"), detail: (m) => joseHash(m[1]) },
|
|
151
|
+
{ id: "jose-key-encryption", langs: ["js", "python", "java", "go"], pattern: /['"`](RSA-OAEP(?:-256|-384|-512)?|RSA1_5|ECDH-ES(?:\+A(?:128|192|256)KW)?)['"`]/, algorithm: (m) => (m[1].startsWith("ECDH") ? "ECDH" : "RSA encryption") },
|
|
152
|
+
// A TLS group list in code replaces the library default, which in current Node.js includes hybrid ML-KEM.
|
|
153
|
+
{ id: "js-tls-ecdh-curve", langs: ["js"], pattern: /\becdhCurve\s*:\s*['"`]([^'"`]+)['"`]/, algorithm: (m) => (groupsLackMlkem(m[1]) ? "TLS key exchange" : null) },
|
|
154
|
+
{ id: "js-forge-rsa", langs: ["js"], pattern: /\bpki\.rsa\.(?:generateKeyPair|createKeyPairAsync)\s*\(/, algorithm: "RSA", keySize: /generateKeyPair\s*\(\s*(?:\{\s*bits\s*:\s*)?(\d{3,5})/ },
|
|
155
|
+
{ id: "js-node-rsa", langs: ["js"], pattern: /\bnew\s+NodeRSA\s*\(/, algorithm: "RSA", keySize: /\bb\s*:\s*(\d{3,5})/ },
|
|
156
|
+
{ id: "js-weak-hash", langs: ["js"], pattern: /\bcreateHash\s*\(\s*['"`](md5|sha1)['"`]|\bcreateHmac\s*\(\s*['"`](md5|sha1)['"`]|\bsubtle\.digest\s*\(\s*['"`](SHA-1)['"`]/i, algorithm: (m) => hashOrCipher(m[1] ?? m[2] ?? m[3]) },
|
|
157
|
+
{ id: "js-weak-cipher", langs: ["js"], pattern: /\bcreateCipheriv\s*\(\s*['"`]((?:des[a-z0-9-]*)|(?:rc4[a-z0-9-]*)|(?:aes-\d+-ecb))['"`]/i, algorithm: (m) => hashOrCipher(m[1]) },
|
|
158
|
+
// ---------- Go ----------
|
|
159
|
+
{ id: "go-rsa", langs: ["go"], pattern: /\brsa\.GenerateKey\s*\(/, algorithm: "RSA", keySize: /GenerateKey\s*\([^,]+,\s*(\d{3,5})/ },
|
|
160
|
+
{ id: "go-rsa-encrypt", langs: ["go"], pattern: /\brsa\.(?:En|De)crypt(?:OAEP|PKCS1v15)\s*\(/, algorithm: "RSA encryption" },
|
|
161
|
+
{ id: "go-rsa-sign", langs: ["go"], pattern: /\brsa\.(?:Sign|Verify)(?:PSS|PKCS1v15)\s*\(/, algorithm: "RSA signature" },
|
|
162
|
+
// Reading or writing a key in a fixed format says which algorithm it is.
|
|
163
|
+
{ id: "go-x509-key", langs: ["go"], pattern: /\bx509\.(?:Parse|Marshal)(PKCS1|EC)(?:Private|Public)Key\s*\(/, algorithm: (m) => (m[1] === "EC" ? "ECDSA" : "RSA") },
|
|
164
|
+
{ id: "go-x509-sigalg", langs: ["go"], pattern: /\bx509\.(?:(?:MD5|SHA1|SHA256|SHA384|SHA512)With(RSA)(?:PSS)?|(ECDSA)WithSHA\d+|Pure(Ed25519)|(DSA)WithSHA\d+)\b/, algorithm: (m) => (m[1] ? "RSA signature" : m[2] ? "ECDSA" : m[3] ? "Ed25519" : "DSA") },
|
|
165
|
+
{ id: "go-ssh-hostkey", langs: ["go"], pattern: /\bssh\.(?:KeyAlgo|SigAlgo)(RSA|DSA|ED25519|SKED25519|ECDSA\d+|SKECDSA\d+)\w*\b/, algorithm: (m) => (m[1] === "RSA" ? "RSA signature" : m[1] === "DSA" ? "DSA" : /ED25519/.test(m[1]) ? "Ed25519" : "ECDSA") },
|
|
166
|
+
// An SSH key exchange list in code replaces the library default; without a hybrid method it has no quantum-safe option.
|
|
167
|
+
{ id: "go-ssh-kex", langs: ["go"], pattern: /\bKeyExchanges\s*:\s*\[\]string\s*\{([^}]*)\}/, algorithm: (m) => (/mlkem|sntrup/i.test(m[1]) || !m[1].trim() ? null : "SSH key exchange") },
|
|
168
|
+
{ id: "go-ecdsa", langs: ["go"], pattern: /\becdsa\.(?:GenerateKey|Sign|SignASN1)\s*\(/, algorithm: "ECDSA" },
|
|
169
|
+
{ id: "go-ecdh", langs: ["go"], pattern: /\becdh\.(P256|P384|P521|X25519)\s*\(/, algorithm: (m) => (m[1] === "X25519" ? "X25519" : "ECDH") },
|
|
170
|
+
{ id: "go-ed25519", langs: ["go"], pattern: /\bed25519\.(?:GenerateKey|Sign|NewKeyFromSeed)\s*\(/, algorithm: "Ed25519" },
|
|
171
|
+
{ id: "go-jwt-method", langs: ["go"], pattern: /\bjwt\.SigningMethod(RS|PS|ES)(?:256|384|512)\b|\bjwt\.SigningMethod(EdDSA|Ed25519)\b/, algorithm: (m) => (m[2] ? "Ed25519" : m[1] === "ES" ? "ECDSA" : "RSA signature") },
|
|
172
|
+
{ id: "go-dsa", langs: ["go"], pattern: /\bdsa\.GenerateKey\s*\(/, algorithm: "DSA" },
|
|
173
|
+
{ id: "go-weak-hash", langs: ["go"], pattern: /\b(md5|sha1)\.(?:New|Sum)\s*\(/, algorithm: (m) => hashOrCipher(m[1]) },
|
|
174
|
+
{ id: "go-weak-cipher", langs: ["go"], pattern: /\bdes\.(NewCipher|NewTripleDESCipher)\s*\(|\brc4\.NewCipher\s*\(/, algorithm: (m) => (m[1] === "NewTripleDESCipher" ? "3DES" : m[1] ? "DES" : "RC4") },
|
|
175
|
+
// A TLS curve list that leaves out the hybrid ML-KEM group turns off Go's post-quantum default (Go 1.24+).
|
|
176
|
+
{ id: "go-tls-curves", langs: ["go"], pattern: /(?<!MLKEM.*)\btls\.(X25519|CurveP256|CurveP384|CurveP521)\b(?!.*MLKEM)/, algorithm: "TLS key exchange" },
|
|
177
|
+
{ id: "go-tls-weak-cipher", langs: ["go"], pattern: /\btls\.TLS_\w*?_WITH_(?:RC4|3DES|DES|NULL)_\w*/, algorithm: "Weak TLS ciphers" },
|
|
178
|
+
{ id: "go-tls-old", langs: ["go"], pattern: /\bMinVersion\s*:\s*tls\.VersionTLS1[01]\b/, algorithm: "TLS 1.0/1.1" },
|
|
179
|
+
// ---------- Java / Kotlin ----------
|
|
180
|
+
{ id: "java-keypairgen", langs: ["java"], pattern: /KeyPairGenerator\.getInstance\s*\(\s*"([A-Za-z0-9]+)"/, algorithm: (m) => keyType(m[1]) },
|
|
181
|
+
// KeyFactory turns encoded bytes into a key of that type (SecretKeyFactory is symmetric and stays out).
|
|
182
|
+
{ id: "java-keyfactory", langs: ["java"], pattern: /(?<![A-Za-z])KeyFactory\.getInstance\s*\(\s*"([A-Za-z0-9]+)"/, algorithm: (m) => keyType(m[1]) },
|
|
183
|
+
// A signature or key name handed back or stored for later, like return "SHA256withECDSA"; getInstance lines have their own rules.
|
|
184
|
+
{ id: "java-signature-name", langs: ["java"], pattern: /(?<!getInstance\s*\(\s*)"[A-Za-z0-9]*with(RSA|ECDSA|DSA)(?:andMGF1)?"/, algorithm: (m) => (m[1] === "RSA" ? "RSA signature" : m[1]), detail: (m) => hashIn(m[0]) },
|
|
185
|
+
{ id: "java-eddsa-name", langs: ["java"], pattern: /(?<!getInstance\s*\(\s*)"(Ed25519|Ed448)"/, algorithm: (m) => m[1] },
|
|
186
|
+
{ id: "java-keyagreement", langs: ["java"], pattern: /KeyAgreement\.getInstance\s*\(\s*"([A-Za-z0-9]+)"/, algorithm: (m) => (keyType(m[1]) === "ECDSA" ? "ECDH" : keyType(m[1])) },
|
|
187
|
+
{ id: "java-signature", langs: ["java"], pattern: /Signature\.getInstance\s*\(\s*"[A-Za-z0-9]*with(RSA|ECDSA|DSA)[A-Za-z0-9/]*"/, algorithm: (m) => (m[1] === "RSA" ? "RSA signature" : m[1]), detail: (m) => hashIn(m[0]) },
|
|
188
|
+
{ id: "java-signature-ed", langs: ["java"], pattern: /Signature\.getInstance\s*\(\s*"(Ed25519|Ed448|EdDSA)"/, algorithm: (m) => (m[1] === "Ed448" ? "Ed448" : "Ed25519") },
|
|
189
|
+
{ id: "java-cipher-rsa", langs: ["java"], pattern: /Cipher\.getInstance\s*\(\s*"RSA[^"]*"/, algorithm: "RSA encryption" },
|
|
190
|
+
{ id: "java-weak-cipher", langs: ["java"], pattern: /Cipher\.getInstance\s*\(\s*"((?:DESede|DES|RC4|ARCFOUR)[^"]*|AES\/ECB[^"]*|AES")/, algorithm: (m) => (m[1] === 'AES"' || m[1] === "AES" ? "ECB mode" : hashOrCipher(m[1].split("/")[0]) ?? hashOrCipher(m[1])) },
|
|
191
|
+
{ id: "java-jwt-alg", langs: ["java"], pattern: /\b(?:SignatureAlgorithm|JWSAlgorithm|Jwts\.SIG)\.(RS|PS|ES)(?:256|384|512)\b|\bAlgorithm\.(RSA|ECDSA)(?:256|384|512)\s*\(/, algorithm: (m) => (m[1] === "ES" || m[2] === "ECDSA" ? "ECDSA" : "RSA signature") },
|
|
192
|
+
{ id: "java-tls-old", langs: ["java"], pattern: /\bSSLContext\.getInstance\s*\(\s*"(?:SSLv3|TLSv1|TLSv1\.1)"|\bsetEnabledProtocols\s*\(.*"(?:SSLv3|TLSv1|TLSv1\.1)"/, algorithm: "TLS 1.0/1.1" },
|
|
193
|
+
{ id: "java-tls-groups", langs: ["java"], pattern: /["']jdk\.tls\.namedGroups["']\s*,\s*["']([^"']+)["']/, algorithm: (m) => (groupsLackMlkem(m[1]) ? "TLS key exchange" : null) },
|
|
194
|
+
{ id: "java-weak-hash", langs: ["java"], pattern: /MessageDigest\.getInstance\s*\(\s*"(MD5|SHA-?1)"/, algorithm: (m) => hashOrCipher(m[1]) },
|
|
195
|
+
{ id: "java-keysize", langs: ["java"], pattern: /\.initialize\s*\(\s*(\d{3,4})\s*(?:\)|,(?!\s*\d))/, algorithm: (m) => (Number(m[1]) < 2048 && Number(m[1]) >= 512 ? "RSA" : null), keySize: /\.initialize\s*\(\s*(\d{3,4})/ },
|
|
196
|
+
// ---------- JSON Web Keys, JOSE and JWT settings in data and config ----------
|
|
197
|
+
// A JWKS or a single JWK as JSON: in a .json file, a config file, or a string in code.
|
|
198
|
+
{ id: "jwk-kty", langs: CODE_AND_CONFIG, pattern: /["']kty["']\s*:\s*["'](RSA|EC|OKP)["']/, algorithm: (m) => jwkAlgorithm(m[1], m.input ?? ""), detail: (m) => ({ curve: curveIn(m.input?.match(/["']crv["']\s*:\s*["']([^"']+)["']/)?.[1] ?? "") }) },
|
|
199
|
+
{ id: "jwk-crv", langs: CODE_AND_CONFIG, pattern: /["']crv["']\s*:\s*["'](P-256|P-384|P-521|secp256k1|Ed25519|Ed448|X25519|X448)["']/, algorithm: (m) => (/^(Ed|X)/.test(m[1]) ? m[1] : "EC"), detail: (m) => ({ curve: curveIn(m[1]) }) },
|
|
200
|
+
// Signing algorithms named in settings: alg, algorithms, JWT_ALGORITHM, id_token_signing_alg_values_supported.
|
|
201
|
+
{ id: "config-jose-alg", langs: ["config"], pattern: /(?:^|[\s"'{,])(?:alg|algorithms?|[A-Za-z_]*(?:jwt|jws|token|signing)[_-]?alg(?:orithms?)?(?:_values_supported)?)["']?\s*[:=]\s*\[?\s*["']?((?:RS|PS|ES)(?:256|384|512)|ES256K|EdDSA)(?![A-Za-z0-9])/i, algorithm: (m) => (m[1].toUpperCase().startsWith("ES") ? "ECDSA" : m[1] === "EdDSA" ? "Ed25519" : "RSA signature"), detail: (m) => (/^ES/i.test(m[1]) ? { curve: { "256": "P-256", "384": "P-384", "512": "P-521", "256K": "secp256k1" }[m[1].slice(2).toUpperCase()], ...joseHash(m[1]) } : {}) },
|
|
202
|
+
{ id: "config-jose-enc", langs: ["config"], pattern: /(?:^|[\s"'{,])(?:alg|[A-Za-z_]*(?:key[_-]?management|encryption)[_-]?alg(?:orithms?)?(?:_values_supported)?)["']?\s*[:=]\s*\[?\s*["']?(RSA-OAEP(?:-256|-384|-512)?|RSA1_5|ECDH-ES(?:\+A(?:128|192|256)KW)?)(?![A-Za-z0-9-])/i, algorithm: (m) => (m[1].startsWith("ECDH") ? "ECDH" : "RSA encryption") },
|
|
203
|
+
// ---------- Ethereum-style signatures: EIP-712, EIP-3009, EIP-2612, eth_sign (all ECDSA over secp256k1) ----------
|
|
204
|
+
{ id: "eth-eip712", langs: CODE_AND_CONFIG, pattern: /\beth_signTypedData(?:_v[134])?\b|\b_?signTypedData(?:_v4)?\s*\(|\b(?:verify|recover)TypedData(?:Address)?\s*\(|\brecoverTypedSignature(?:_v4)?\s*\(|\bhashTypedData(?:V4)?\s*\(|\bEIP712Domain\b|\b(?:encode|sign)_typed_data\s*\(/, algorithm: "ECDSA", detail: () => ETH },
|
|
205
|
+
{ id: "eth-eip3009", langs: CODE_AND_CONFIG, pattern: /\b(?:[Tt]ransfer|[Rr]eceive)WithAuthorization\b/, algorithm: "ECDSA", detail: () => ETH },
|
|
206
|
+
{ id: "eth-eip2612", langs: CODE_AND_CONFIG, pattern: /\bPERMIT_TYPEHASH\b|\bsignERC2612Permit\s*\(|["']Permit\(address owner,address spender/, algorithm: "ECDSA", detail: () => ETH },
|
|
207
|
+
// eth_account (Python). Account.create alone is also how ORMs add a row, so only its own forms count.
|
|
208
|
+
{ id: "eth-account", langs: ["python"], pattern: /\bAccount\.(?:sign_message|recover_message|sign_transaction|from_key)\s*\(|\bAccount\.create\s*\(\s*(?:\)|['"]|extra_entropy\s*=)|\beth\.account\.(?:sign_message|sign_transaction|recover_message)\s*\(/, algorithm: "ECDSA", detail: () => ETH },
|
|
209
|
+
{ id: "eth-sign", langs: ["js", "python", "java"], pattern: /\beth_sign\b|\bpersonal_sign\b|\b(?:wallet|signer|account)\.sign(?:Message|Transaction)\s*\(|\b(?:ethers|utils)\.(?:verifyMessage|recoverAddress)\s*\(|\brecover(?:Message)?Address\s*\(|\becrecover\s*\(|\bSign\.(?:signMessage|signPrefixedMessage|signedMessageToKey|signedPrefixedMessageToKey)\s*\(|\bKeys\.createEcKeyPair\s*\(/, algorithm: "ECDSA", detail: () => ETH },
|
|
210
|
+
{ id: "eth-go", langs: ["go"], pattern: /\bcrypto\.(?:Sign|Ecrecover|SigToPub|VerifySignature|HexToECDSA|GenerateKey)\s*\(/, algorithm: (m) => (/crypto\.GenerateKey/.test(m[0]) && !/ethereum|secp256k1/i.test(m.input ?? "") ? null : "ECDSA"), detail: () => ETH },
|
|
211
|
+
{ id: "secp256k1-lib", langs: ["js", "python", "go", "java"], pattern: /\bsecp256k1\.(?:sign|verify|ecdsaSign|ecdsaVerify|ecdsaRecover|getPublicKey|recoverPublicKey|publicKeyCreate|schnorr)\b|\bec\.SECP256K1\s*\(|\bcoincurve\.PrivateKey\s*\(|\bSECP256k1\b|\bbtcec\.(?:NewPrivateKey|PrivKeyFromBytes|ParsePubKey)\s*\(/, algorithm: "ECDSA", detail: () => ETH },
|
|
212
|
+
// ---------- Config, keys, certificates (any file) ----------
|
|
213
|
+
{ id: "ssh-public-key", langs: ["any"], pattern: /\b(ssh-rsa|ssh-dss|ecdsa-sha2-nistp\d+|ssh-ed25519) (AAAA[0-9A-Za-z+/]{20,}={0,2})/, algorithm: (m) => ({ "ssh-rsa": "RSA signature", "ssh-dss": "DSA", "ssh-ed25519": "Ed25519" }[m[1]] ?? "ECDSA"), detail: (m) => sshKeyDetail(m[1], m[2]) },
|
|
214
|
+
];
|
|
215
|
+
export function langFor(path) {
|
|
216
|
+
const p = path.toLowerCase();
|
|
217
|
+
if (/\.(py|pyw)$/.test(p))
|
|
218
|
+
return "python";
|
|
219
|
+
if (/\.(js|mjs|cjs|jsx|ts|mts|cts|tsx)$/.test(p))
|
|
220
|
+
return "js";
|
|
221
|
+
if (/\.go$/.test(p))
|
|
222
|
+
return "go";
|
|
223
|
+
if (/\.(java|kt|kts|scala)$/.test(p))
|
|
224
|
+
return "java";
|
|
225
|
+
if (/(\.conf|\.cfg|\.ini|\.ya?ml|\.toml|\.tf|\.json|\.env|nginx[^/]*|httpd[^/]*|dockerfile[^/]*|containerfile[^/]*|\.hcl|\.tfvars|\.template|\.properties)$/.test(p))
|
|
226
|
+
return "config";
|
|
227
|
+
if (/\.(pem|key|crt|cer|pub|txt|sh|md)$/.test(p) || /(^|\/)(authorized_keys|known_hosts|id_[a-z0-9]+)$/.test(p))
|
|
228
|
+
return "any";
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// Pieces both SARIF outputs share, so GitHub code scanning and other tools rate and track findings the same way.
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
/** GitHub reads properties["security-severity"] (0-10) to show Critical, High, Medium or Low. */
|
|
6
|
+
export const SECURITY_SEVERITY = { critical: "9.5", high: "8.0", medium: "5.5", low: "3.0" };
|
|
7
|
+
/** Where each rule's help links to. */
|
|
8
|
+
export const HELP_URI = "https://hardkeel.com/quantum-scan/";
|
|
9
|
+
/**
|
|
10
|
+
* Encryption quantum computers will break is safe today, so on GitHub it stays at Medium or below:
|
|
11
|
+
* it belongs in the plan, not ahead of what is broken now.
|
|
12
|
+
*/
|
|
13
|
+
const QUANTUM_SEVERITY = { critical: "6.5", high: "6.0", medium: "5.0", low: "3.0" };
|
|
14
|
+
/** The 0-10 score for a finding: the usual scale, or the capped one for quantum-breakable encryption. */
|
|
15
|
+
export const securitySeverity = (risk, sev) => (risk === "quantum-vulnerable" ? QUANTUM_SEVERITY : SECURITY_SEVERITY)[sev];
|
|
16
|
+
const ORDER = ["critical", "high", "medium", "low"];
|
|
17
|
+
export const worstOf = (a, b) => (a && ORDER.indexOf(a) <= ORDER.indexOf(b) ? a : b);
|
|
18
|
+
/**
|
|
19
|
+
* A fingerprint that stays the same when lines move, so a finding isn't reported as new after an
|
|
20
|
+
* unrelated edit: rule, place, and which occurrence of that rule in that place it is. No code text goes in.
|
|
21
|
+
*/
|
|
22
|
+
export function fingerprints(items, key) {
|
|
23
|
+
const seen = new Map();
|
|
24
|
+
return items.map((t) => {
|
|
25
|
+
const k = key(t);
|
|
26
|
+
const n = (seen.get(k) ?? 0) + 1;
|
|
27
|
+
seen.set(k, n);
|
|
28
|
+
return { "hardkeel/v1": createHash("sha256").update(`${k}|${n}`).digest("hex").slice(0, 32) };
|
|
29
|
+
});
|
|
30
|
+
}
|
package/dist/sarif.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// SPDX-License-Identifier: PolyForm-Shield-1.0.0
|
|
2
|
+
// Copyright 2026 Hard Keel (https://hardkeel.com)
|
|
3
|
+
// SARIF 2.1.0 output, so GitHub code scanning (and other tools) can show findings.
|
|
4
|
+
import { violationLabel } from "./policy.js";
|
|
5
|
+
import { shortLabel } from "./report.js";
|
|
6
|
+
import { HELP_URI, fingerprints, securitySeverity, worstOf } from "./sarif-common.js";
|
|
7
|
+
const LEVEL = {
|
|
8
|
+
secret: "error",
|
|
9
|
+
"weak-now": "error",
|
|
10
|
+
"quantum-vulnerable": "warning",
|
|
11
|
+
exposed: "error",
|
|
12
|
+
};
|
|
13
|
+
const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
14
|
+
/**
|
|
15
|
+
* One SARIF rule per kind of problem, like "weak-now/md5-hash" or "secret/aws-access-key". A setting
|
|
16
|
+
* is named by the setting itself, not by a label that can carry its value (such as the ports open),
|
|
17
|
+
* so the id stays the same from run to run.
|
|
18
|
+
*/
|
|
19
|
+
export function ruleId(f) {
|
|
20
|
+
return `${f.risk}/${slug(f.kind === "config" ? f.algorithm : shortLabel(f))}`;
|
|
21
|
+
}
|
|
22
|
+
function tags(f) {
|
|
23
|
+
const kind = f.kind === "secret" ? "secret" : f.kind === "config" ? "configuration" : "encryption";
|
|
24
|
+
return ["security", kind, f.risk, ...(f.risk === "quantum-vulnerable" ? ["post-quantum"] : [])];
|
|
25
|
+
}
|
|
26
|
+
function whenText(f) {
|
|
27
|
+
if (f.risk === "quantum-vulnerable")
|
|
28
|
+
return "Safe today, but a large quantum computer will be able to break it. NIST plans to phase it out between 2030 and 2035.";
|
|
29
|
+
if (f.risk === "secret")
|
|
30
|
+
return "Anyone who can read the repository can use it.";
|
|
31
|
+
return "Fix this now. It doesn't take a quantum computer to break.";
|
|
32
|
+
}
|
|
33
|
+
/** A scanner path as a URI from the repository root, when the scan ran on a folder inside the repository. */
|
|
34
|
+
export function toUri(path, prefix = "") {
|
|
35
|
+
const clean = (s) => s.replace(/\\/g, "/").replace(/^(\.\/)+/, "").replace(/\/+$/, "");
|
|
36
|
+
const pre = clean(prefix);
|
|
37
|
+
const p = clean(path);
|
|
38
|
+
// encodeURI leaves # and ?, which would cut a name like notes#1.py short.
|
|
39
|
+
return encodeURI(pre && pre !== "." ? `${pre}/${p}` : p).replace(/[#?]/g, (c) => encodeURIComponent(c));
|
|
40
|
+
}
|
|
41
|
+
export function buildSarif(findings, toolVersion, opts = {}) {
|
|
42
|
+
const worst = new Map();
|
|
43
|
+
for (const f of findings)
|
|
44
|
+
worst.set(ruleId(f), worstOf(worst.get(ruleId(f)), f.severity));
|
|
45
|
+
const rules = new Map();
|
|
46
|
+
for (const f of findings) {
|
|
47
|
+
const id = ruleId(f);
|
|
48
|
+
if (rules.has(id))
|
|
49
|
+
continue;
|
|
50
|
+
const name = shortLabel(f);
|
|
51
|
+
const when = whenText(f);
|
|
52
|
+
rules.set(id, {
|
|
53
|
+
id,
|
|
54
|
+
name,
|
|
55
|
+
shortDescription: { text: f.title },
|
|
56
|
+
fullDescription: { text: `${f.title}. ${when}` },
|
|
57
|
+
help: { text: `${when} Fix: ${f.fix}`, markdown: `**${name}**\n\n${when}\n\n**Fix:** ${f.fix}\n\n[About Hard Keel Benthic](${HELP_URI})` },
|
|
58
|
+
helpUri: HELP_URI,
|
|
59
|
+
defaultConfiguration: { level: LEVEL[f.risk] },
|
|
60
|
+
properties: { tags: tags(f), "security-severity": securitySeverity(f.risk, worst.get(id)) },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const uri = (f) => toUri(f.file, opts.uriPrefix);
|
|
64
|
+
// Your policy: what it rules out that isn't a finding already, like AES-128 under a 256-bit rule.
|
|
65
|
+
const policyOnly = (opts.policy ?? []).filter((v) => !v.finding && !v.allowed);
|
|
66
|
+
const POLICY_RULE = "policy/inventory";
|
|
67
|
+
if (policyOnly.length) {
|
|
68
|
+
const text = "An algorithm or key size that your encryption policy (.benthic.yml) rules out. It doesn't change the grade.";
|
|
69
|
+
rules.set(POLICY_RULE, { id: POLICY_RULE, name: "Not allowed by your encryption policy", shortDescription: { text: "Not allowed by your encryption policy" }, fullDescription: { text }, help: { text, markdown: text }, helpUri: HELP_URI, defaultConfiguration: { level: "warning" }, properties: { tags: ["security", "encryption", "policy"], "security-severity": "5.0" } });
|
|
70
|
+
}
|
|
71
|
+
const ruleIndex = new Map([...rules.keys()].map((id, i) => [id, i]));
|
|
72
|
+
const prints = fingerprints(findings, (f) => `${ruleId(f)}|${uri(f)}`);
|
|
73
|
+
const policyPrints = fingerprints(policyOnly, (v) => `${POLICY_RULE}|${v.algorithm}|${toUri(v.file, opts.uriPrefix)}`);
|
|
74
|
+
return {
|
|
75
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
76
|
+
version: "2.1.0",
|
|
77
|
+
runs: [
|
|
78
|
+
{
|
|
79
|
+
tool: {
|
|
80
|
+
driver: {
|
|
81
|
+
name: "Hard Keel Benthic",
|
|
82
|
+
version: toolVersion,
|
|
83
|
+
informationUri: HELP_URI,
|
|
84
|
+
rules: [...rules.values()],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
...(opts.suppressed ? { properties: { suppressed: opts.suppressed } } : {}),
|
|
88
|
+
results: findings.map((f, i) => ({
|
|
89
|
+
ruleId: ruleId(f),
|
|
90
|
+
ruleIndex: ruleIndex.get(ruleId(f)),
|
|
91
|
+
level: LEVEL[f.risk],
|
|
92
|
+
message: { text: `${f.title}. ${f.fix}` },
|
|
93
|
+
// SARIF lines start at 1; a finding about a whole file (line 0) points at the file alone.
|
|
94
|
+
locations: [{ physicalLocation: { artifactLocation: { uri: uri(f), uriBaseId: "%SRCROOT%" }, ...(f.line > 0 ? { region: { startLine: f.line } } : {}) } }],
|
|
95
|
+
// Where the algorithm or key size was set, and each call that passed it here.
|
|
96
|
+
...(f.via?.length
|
|
97
|
+
? {
|
|
98
|
+
relatedLocations: f.via.map((v, n) => ({ id: n + 1, message: { text: v.note }, physicalLocation: { artifactLocation: { uri: uri({ ...f, file: v.file }), uriBaseId: "%SRCROOT%" }, region: { startLine: v.line } } })),
|
|
99
|
+
codeFlows: [{ threadFlows: [{ locations: [...f.via.map((v) => ({ location: { message: { text: v.note }, physicalLocation: { artifactLocation: { uri: uri({ ...f, file: v.file }), uriBaseId: "%SRCROOT%" }, region: { startLine: v.line } } } })), { location: { message: { text: f.title }, physicalLocation: { artifactLocation: { uri: uri(f), uriBaseId: "%SRCROOT%" }, region: { startLine: f.line } } } }] }] }],
|
|
100
|
+
}
|
|
101
|
+
: {}),
|
|
102
|
+
partialFingerprints: prints[i],
|
|
103
|
+
})).concat(policyOnly.map((v, i) => ({
|
|
104
|
+
ruleId: POLICY_RULE,
|
|
105
|
+
ruleIndex: ruleIndex.get(POLICY_RULE),
|
|
106
|
+
level: "warning",
|
|
107
|
+
message: { text: `${violationLabel(v)}: ${v.why}` },
|
|
108
|
+
locations: [{ physicalLocation: { artifactLocation: { uri: toUri(v.file, opts.uriPrefix), uriBaseId: "%SRCROOT%" }, ...(v.line > 0 ? { region: { startLine: v.line } } : {}) } }],
|
|
109
|
+
partialFingerprints: policyPrints[i],
|
|
110
|
+
}))),
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
}
|