@hardkeel/quantum-scan 0.2.0 → 0.3.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 +18 -0
- package/LICENSE +202 -202
- package/README.md +162 -151
- package/action.yml +44 -44
- package/dist/badge.js +60 -60
- package/dist/cbom.js +59 -59
- package/dist/cli.js +305 -305
- package/dist/community-rules.js +30 -30
- package/dist/community.js +28 -28
- package/dist/ignore.js +75 -75
- package/dist/infra.js +557 -557
- package/dist/map-activity.js +22 -22
- package/dist/map-areas.js +50 -41
- package/dist/map-cloud-keys.js +108 -0
- package/dist/map-host.js +333 -333
- package/dist/map-network.js +518 -0
- package/dist/map-people.js +77 -0
- package/dist/map-rank.js +48 -48
- package/dist/map-report.js +178 -138
- package/dist/map-run.js +271 -205
- package/dist/map-types.js +16 -16
- package/dist/map-web.js +640 -640
- package/dist/pqc.js +32 -32
- package/dist/report.js +179 -179
- package/dist/rules.js +135 -133
- package/dist/sarif.js +43 -43
- package/dist/scan.js +220 -214
- package/dist/score.js +122 -122
- package/dist/secrets.js +108 -97
- package/dist/share-config.js +111 -111
- package/dist/share.js +114 -112
- package/dist/types.js +2 -2
- package/dist/walk.js +63 -63
- package/package.json +53 -52
package/dist/rules.js
CHANGED
|
@@ -1,133 +1,135 @@
|
|
|
1
|
-
// Detection rules for quantum-vulnerable and already-weak cryptography.
|
|
2
|
-
// Each rule is a line-level regex scoped to a set of file languages.
|
|
3
|
-
const KEM_FIX = "Move key exchange to ML-KEM (FIPS 203), or hybrid X25519 + ML-KEM-768 for TLS.";
|
|
4
|
-
const SIG_FIX = "Move to ML-DSA (FIPS 204) or SLH-DSA (FIPS 205) signatures.";
|
|
5
|
-
const HASH_FIX = "Switch to SHA-256 or SHA-3, unless it is only a non-security checksum.";
|
|
6
|
-
const CIPHER_FIX = "Switch to AES-256-GCM.";
|
|
7
|
-
const TLS_FIX = "Require TLS 1.2 or later, ideally TLS 1.3.";
|
|
8
|
-
// Classification of every algorithm the rules can emit.
|
|
9
|
-
export const ALGORITHMS = {
|
|
10
|
-
RSA: { primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: `${KEM_FIX} For signatures, use ML-DSA (FIPS 204).` },
|
|
11
|
-
"RSA signature": { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
12
|
-
"RSA encryption": { primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
13
|
-
ECDSA: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
14
|
-
EC: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: `${SIG_FIX} For key exchange, use ML-KEM (FIPS 203).` },
|
|
15
|
-
ECDH: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
16
|
-
DH: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
17
|
-
X25519: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
18
|
-
X448: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
19
|
-
Ed25519: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
20
|
-
Ed448: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
21
|
-
DSA: { primitive: "signature", risk: "weak-now", severity: "high", fix: `DSA is no longer approved. ${SIG_FIX}` },
|
|
22
|
-
MD5: { primitive: "hash", risk: "weak-now", severity: "medium", fix: HASH_FIX },
|
|
23
|
-
"SHA-1": { primitive: "hash", risk: "weak-now", severity: "medium", fix: HASH_FIX },
|
|
24
|
-
DES: { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
25
|
-
"3DES": { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
26
|
-
RC4: { primitive: "stream-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
27
|
-
"ECB mode": { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
28
|
-
"TLS 1.0/1.1": { primitive: "protocol", risk: "weak-now", severity: "high", fix: TLS_FIX },
|
|
29
|
-
"Weak TLS ciphers": { primitive: "protocol", risk: "weak-now", severity: "high", fix: "Allow only AES-GCM and ChaCha20 cipher suites." },
|
|
30
|
-
};
|
|
31
|
-
// Maps a key-type word used by many APIs to an algorithm name.
|
|
32
|
-
function keyType(word) {
|
|
33
|
-
const w = word.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
34
|
-
if (w.startsWith("rsa"))
|
|
35
|
-
return "RSA";
|
|
36
|
-
if (w === "ec" || w === "ecdsa")
|
|
37
|
-
return "ECDSA";
|
|
38
|
-
if (w === "ecdh")
|
|
39
|
-
return "ECDH";
|
|
40
|
-
if (w === "dsa")
|
|
41
|
-
return "DSA";
|
|
42
|
-
if (w === "dh" || w === "diffiehellman")
|
|
43
|
-
return "DH";
|
|
44
|
-
if (w === "ed25519")
|
|
45
|
-
return "Ed25519";
|
|
46
|
-
if (w === "ed448")
|
|
47
|
-
return "Ed448";
|
|
48
|
-
if (w === "x25519")
|
|
49
|
-
return "X25519";
|
|
50
|
-
if (w === "x448")
|
|
51
|
-
return "X448";
|
|
52
|
-
if (w === "xdh")
|
|
53
|
-
return "X25519";
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
function hashOrCipher(word) {
|
|
57
|
-
const w = word.toLowerCase();
|
|
58
|
-
if (w === "md5")
|
|
59
|
-
return "MD5";
|
|
60
|
-
if (w === "sha1" || w === "sha-1")
|
|
61
|
-
return "SHA-1";
|
|
62
|
-
if (w.startsWith("des-ede") || w === "desede" || w.startsWith("des3") || w === "3des")
|
|
63
|
-
return "3DES";
|
|
64
|
-
if (w.startsWith("des"))
|
|
65
|
-
return "DES";
|
|
66
|
-
if (w.startsWith("rc4") || w === "arc4" || w === "arcfour")
|
|
67
|
-
return "RC4";
|
|
68
|
-
if (/ecb/.test(w))
|
|
69
|
-
return "ECB mode";
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
export const CRYPTO_RULES = [
|
|
73
|
-
// ---------- Python ----------
|
|
74
|
-
{ 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})/ },
|
|
75
|
-
{ id: "py-rsa-padding", langs: ["python"], pattern: /\bPKCS1_OAEP\b|\bpadding\.OAEP\s*\(/, algorithm: "RSA encryption" },
|
|
76
|
-
{ id: "py-rsa-sign", langs: ["python"], pattern: /\bpadding\.PSS\s*\(|\bpadding\.PKCS1v15\s*\(|\bpkcs1_15\.new\s*\(/, algorithm: "RSA signature" },
|
|
77
|
-
{ id: "py-ec-generate", langs: ["python"], pattern: /\bec\.generate_private_key\s*\(|\bECC\.generate\s*\(|\bSigningKey\.generate\s*\(/, algorithm: "ECDSA" },
|
|
78
|
-
{ id: "py-ecdh", langs: ["python"], pattern: /\bec\.ECDH\s*\(/, algorithm: "ECDH" },
|
|
79
|
-
{ id: "py-dsa", langs: ["python"], pattern: /\bdsa\.generate_private_key\s*\(|\bDSA\.generate\s*\(/, algorithm: "DSA" },
|
|
80
|
-
{ id: "py-dh", langs: ["python"], pattern: /\bdh\.generate_parameters\s*\(/, algorithm: "DH" },
|
|
81
|
-
{ id: "py-ed25519", langs: ["python"], pattern: /\bEd25519PrivateKey\b/, algorithm: "Ed25519" },
|
|
82
|
-
{ id: "py-x25519", langs: ["python"], pattern: /\bX25519PrivateKey\b/, algorithm: "X25519" },
|
|
83
|
-
{ 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] ?? "") },
|
|
84
|
-
{ 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")) },
|
|
85
|
-
{ id: "py-ecb", langs: ["python"], pattern: /\bmodes\.ECB\s*\(|\bMODE_ECB\b/, algorithm: "ECB mode" },
|
|
86
|
-
// ---------- JavaScript / TypeScript ----------
|
|
87
|
-
{ 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})/ },
|
|
88
|
-
{ id: "js-ecdh", langs: ["js"], pattern: /\bcreateECDH\s*\(/, algorithm: "ECDH" },
|
|
89
|
-
{ id: "js-dh", langs: ["js"], pattern: /\bcreateDiffieHellman(?:Group)?\s*\(/, algorithm: "DH" },
|
|
90
|
-
{ 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})/ },
|
|
91
|
-
{ 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") },
|
|
92
|
-
{ id: "js-forge-rsa", langs: ["js"], pattern: /\bpki\.rsa\.generateKeyPair\s*\(/, algorithm: "RSA", keySize: /generateKeyPair\s*\(\s*(?:\{\s*bits\s*:\s*)?(\d{3,5})/ },
|
|
93
|
-
{ id: "js-weak-hash", langs: ["js"], pattern: /\bcreateHash\s*\(\s*['"`](md5|sha1)['"`]|\bcreateHmac\s*\(\s*['"`](md5|sha1)['"`]/i, algorithm: (m) => hashOrCipher(m[1] ?? m[2]) },
|
|
94
|
-
{ 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]) },
|
|
95
|
-
// ---------- Go ----------
|
|
96
|
-
{ id: "go-rsa", langs: ["go"], pattern: /\brsa\.GenerateKey\s*\(/, algorithm: "RSA", keySize: /GenerateKey\s*\([^,]+,\s*(\d{3,5})/ },
|
|
97
|
-
{ id: "go-rsa-encrypt", langs: ["go"], pattern: /\brsa\.Encrypt(?:OAEP|PKCS1v15)\s*\(/, algorithm: "RSA encryption" },
|
|
98
|
-
{ id: "go-rsa-sign", langs: ["go"], pattern: /\brsa\.Sign(?:PSS|PKCS1v15)\s*\(/, algorithm: "RSA signature" },
|
|
99
|
-
{ id: "go-ecdsa", langs: ["go"], pattern: /\becdsa\.(?:GenerateKey|Sign|SignASN1)\s*\(/, algorithm: "ECDSA" },
|
|
100
|
-
{ id: "go-ecdh", langs: ["go"], pattern: /\becdh\.(P256|P384|P521|X25519)\s*\(/, algorithm: (m) => (m[1] === "X25519" ? "X25519" : "ECDH") },
|
|
101
|
-
{ id: "go-ed25519", langs: ["go"], pattern: /\bed25519\.(?:GenerateKey|Sign|NewKeyFromSeed)\s*\(/, algorithm: "Ed25519" },
|
|
102
|
-
{ id: "go-dsa", langs: ["go"], pattern: /\bdsa\.GenerateKey\s*\(/, algorithm: "DSA" },
|
|
103
|
-
{ id: "go-weak-hash", langs: ["go"], pattern: /\b(md5|sha1)\.(?:New|Sum)\s*\(/, algorithm: (m) => hashOrCipher(m[1]) },
|
|
104
|
-
{ id: "go-weak-cipher", langs: ["go"], pattern: /\bdes\.(NewCipher|NewTripleDESCipher)\s*\(|\brc4\.NewCipher\s*\(/, algorithm: (m) => (m[1] === "NewTripleDESCipher" ? "3DES" : m[1] ? "DES" : "RC4") },
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
{ id: "
|
|
108
|
-
|
|
109
|
-
{ id: "java-
|
|
110
|
-
{ id: "java-
|
|
111
|
-
{ id: "java-
|
|
112
|
-
{ id: "java-
|
|
113
|
-
{ id: "java-
|
|
114
|
-
{ id: "java-
|
|
115
|
-
|
|
116
|
-
{ id: "
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (/\.(
|
|
123
|
-
return "
|
|
124
|
-
if (/\.
|
|
125
|
-
return "
|
|
126
|
-
if (/\.
|
|
127
|
-
return "
|
|
128
|
-
if (
|
|
129
|
-
return "
|
|
130
|
-
if (
|
|
131
|
-
return "
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
// Detection rules for quantum-vulnerable and already-weak cryptography.
|
|
2
|
+
// Each rule is a line-level regex scoped to a set of file languages.
|
|
3
|
+
const KEM_FIX = "Move key exchange to ML-KEM (FIPS 203), or hybrid X25519 + ML-KEM-768 for TLS.";
|
|
4
|
+
const SIG_FIX = "Move to ML-DSA (FIPS 204) or SLH-DSA (FIPS 205) signatures.";
|
|
5
|
+
const HASH_FIX = "Switch to SHA-256 or SHA-3, unless it is only a non-security checksum.";
|
|
6
|
+
const CIPHER_FIX = "Switch to AES-256-GCM.";
|
|
7
|
+
const TLS_FIX = "Require TLS 1.2 or later, ideally TLS 1.3.";
|
|
8
|
+
// Classification of every algorithm the rules can emit.
|
|
9
|
+
export const ALGORITHMS = {
|
|
10
|
+
RSA: { primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: `${KEM_FIX} For signatures, use ML-DSA (FIPS 204).` },
|
|
11
|
+
"RSA signature": { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
12
|
+
"RSA encryption": { primitive: "public-key-encryption", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
13
|
+
ECDSA: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
14
|
+
EC: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: `${SIG_FIX} For key exchange, use ML-KEM (FIPS 203).` },
|
|
15
|
+
ECDH: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
16
|
+
DH: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
17
|
+
X25519: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
18
|
+
X448: { primitive: "key-agreement", risk: "quantum-vulnerable", severity: "high", fix: KEM_FIX },
|
|
19
|
+
Ed25519: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
20
|
+
Ed448: { primitive: "signature", risk: "quantum-vulnerable", severity: "medium", fix: SIG_FIX },
|
|
21
|
+
DSA: { primitive: "signature", risk: "weak-now", severity: "high", fix: `DSA is no longer approved. ${SIG_FIX}` },
|
|
22
|
+
MD5: { primitive: "hash", risk: "weak-now", severity: "medium", fix: HASH_FIX },
|
|
23
|
+
"SHA-1": { primitive: "hash", risk: "weak-now", severity: "medium", fix: HASH_FIX },
|
|
24
|
+
DES: { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
25
|
+
"3DES": { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
26
|
+
RC4: { primitive: "stream-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
27
|
+
"ECB mode": { primitive: "block-cipher", risk: "weak-now", severity: "high", fix: CIPHER_FIX },
|
|
28
|
+
"TLS 1.0/1.1": { primitive: "protocol", risk: "weak-now", severity: "high", fix: TLS_FIX },
|
|
29
|
+
"Weak TLS ciphers": { primitive: "protocol", risk: "weak-now", severity: "high", fix: "Allow only AES-GCM and ChaCha20 cipher suites." },
|
|
30
|
+
};
|
|
31
|
+
// Maps a key-type word used by many APIs to an algorithm name.
|
|
32
|
+
function keyType(word) {
|
|
33
|
+
const w = word.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
34
|
+
if (w.startsWith("rsa"))
|
|
35
|
+
return "RSA";
|
|
36
|
+
if (w === "ec" || w === "ecdsa")
|
|
37
|
+
return "ECDSA";
|
|
38
|
+
if (w === "ecdh")
|
|
39
|
+
return "ECDH";
|
|
40
|
+
if (w === "dsa")
|
|
41
|
+
return "DSA";
|
|
42
|
+
if (w === "dh" || w === "diffiehellman")
|
|
43
|
+
return "DH";
|
|
44
|
+
if (w === "ed25519")
|
|
45
|
+
return "Ed25519";
|
|
46
|
+
if (w === "ed448")
|
|
47
|
+
return "Ed448";
|
|
48
|
+
if (w === "x25519")
|
|
49
|
+
return "X25519";
|
|
50
|
+
if (w === "x448")
|
|
51
|
+
return "X448";
|
|
52
|
+
if (w === "xdh")
|
|
53
|
+
return "X25519";
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function hashOrCipher(word) {
|
|
57
|
+
const w = word.toLowerCase();
|
|
58
|
+
if (w === "md5")
|
|
59
|
+
return "MD5";
|
|
60
|
+
if (w === "sha1" || w === "sha-1")
|
|
61
|
+
return "SHA-1";
|
|
62
|
+
if (w.startsWith("des-ede") || w === "desede" || w.startsWith("des3") || w === "3des")
|
|
63
|
+
return "3DES";
|
|
64
|
+
if (w.startsWith("des"))
|
|
65
|
+
return "DES";
|
|
66
|
+
if (w.startsWith("rc4") || w === "arc4" || w === "arcfour")
|
|
67
|
+
return "RC4";
|
|
68
|
+
if (/ecb/.test(w))
|
|
69
|
+
return "ECB mode";
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
export const CRYPTO_RULES = [
|
|
73
|
+
// ---------- Python ----------
|
|
74
|
+
{ 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})/ },
|
|
75
|
+
{ id: "py-rsa-padding", langs: ["python"], pattern: /\bPKCS1_OAEP\b|\bpadding\.OAEP\s*\(/, algorithm: "RSA encryption" },
|
|
76
|
+
{ id: "py-rsa-sign", langs: ["python"], pattern: /\bpadding\.PSS\s*\(|\bpadding\.PKCS1v15\s*\(|\bpkcs1_15\.new\s*\(/, algorithm: "RSA signature" },
|
|
77
|
+
{ id: "py-ec-generate", langs: ["python"], pattern: /\bec\.generate_private_key\s*\(|\bECC\.generate\s*\(|\bSigningKey\.generate\s*\(/, algorithm: "ECDSA" },
|
|
78
|
+
{ id: "py-ecdh", langs: ["python"], pattern: /\bec\.ECDH\s*\(/, algorithm: "ECDH" },
|
|
79
|
+
{ id: "py-dsa", langs: ["python"], pattern: /\bdsa\.generate_private_key\s*\(|\bDSA\.generate\s*\(/, algorithm: "DSA" },
|
|
80
|
+
{ id: "py-dh", langs: ["python"], pattern: /\bdh\.generate_parameters\s*\(/, algorithm: "DH" },
|
|
81
|
+
{ id: "py-ed25519", langs: ["python"], pattern: /\bEd25519PrivateKey\b/, algorithm: "Ed25519" },
|
|
82
|
+
{ id: "py-x25519", langs: ["python"], pattern: /\bX25519PrivateKey\b/, algorithm: "X25519" },
|
|
83
|
+
{ 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] ?? "") },
|
|
84
|
+
{ 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")) },
|
|
85
|
+
{ id: "py-ecb", langs: ["python"], pattern: /\bmodes\.ECB\s*\(|\bMODE_ECB\b/, algorithm: "ECB mode" },
|
|
86
|
+
// ---------- JavaScript / TypeScript ----------
|
|
87
|
+
{ 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})/ },
|
|
88
|
+
{ id: "js-ecdh", langs: ["js"], pattern: /\bcreateECDH\s*\(/, algorithm: "ECDH" },
|
|
89
|
+
{ id: "js-dh", langs: ["js"], pattern: /\bcreateDiffieHellman(?:Group)?\s*\(/, algorithm: "DH" },
|
|
90
|
+
{ 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})/ },
|
|
91
|
+
{ 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") },
|
|
92
|
+
{ id: "js-forge-rsa", langs: ["js"], pattern: /\bpki\.rsa\.generateKeyPair\s*\(/, algorithm: "RSA", keySize: /generateKeyPair\s*\(\s*(?:\{\s*bits\s*:\s*)?(\d{3,5})/ },
|
|
93
|
+
{ id: "js-weak-hash", langs: ["js"], pattern: /\bcreateHash\s*\(\s*['"`](md5|sha1)['"`]|\bcreateHmac\s*\(\s*['"`](md5|sha1)['"`]/i, algorithm: (m) => hashOrCipher(m[1] ?? m[2]) },
|
|
94
|
+
{ 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]) },
|
|
95
|
+
// ---------- Go ----------
|
|
96
|
+
{ id: "go-rsa", langs: ["go"], pattern: /\brsa\.GenerateKey\s*\(/, algorithm: "RSA", keySize: /GenerateKey\s*\([^,]+,\s*(\d{3,5})/ },
|
|
97
|
+
{ id: "go-rsa-encrypt", langs: ["go"], pattern: /\brsa\.Encrypt(?:OAEP|PKCS1v15)\s*\(/, algorithm: "RSA encryption" },
|
|
98
|
+
{ id: "go-rsa-sign", langs: ["go"], pattern: /\brsa\.Sign(?:PSS|PKCS1v15)\s*\(/, algorithm: "RSA signature" },
|
|
99
|
+
{ id: "go-ecdsa", langs: ["go"], pattern: /\becdsa\.(?:GenerateKey|Sign|SignASN1)\s*\(/, algorithm: "ECDSA" },
|
|
100
|
+
{ id: "go-ecdh", langs: ["go"], pattern: /\becdh\.(P256|P384|P521|X25519)\s*\(/, algorithm: (m) => (m[1] === "X25519" ? "X25519" : "ECDH") },
|
|
101
|
+
{ id: "go-ed25519", langs: ["go"], pattern: /\bed25519\.(?:GenerateKey|Sign|NewKeyFromSeed)\s*\(/, algorithm: "Ed25519" },
|
|
102
|
+
{ id: "go-dsa", langs: ["go"], pattern: /\bdsa\.GenerateKey\s*\(/, algorithm: "DSA" },
|
|
103
|
+
{ id: "go-weak-hash", langs: ["go"], pattern: /\b(md5|sha1)\.(?:New|Sum)\s*\(/, algorithm: (m) => hashOrCipher(m[1]) },
|
|
104
|
+
{ id: "go-weak-cipher", langs: ["go"], pattern: /\bdes\.(NewCipher|NewTripleDESCipher)\s*\(|\brc4\.NewCipher\s*\(/, algorithm: (m) => (m[1] === "NewTripleDESCipher" ? "3DES" : m[1] ? "DES" : "RC4") },
|
|
105
|
+
// A TLS curve list that leaves out the hybrid ML-KEM group turns off Go's post-quantum default (Go 1.24+).
|
|
106
|
+
{ id: "go-tls-curves", langs: ["go"], pattern: /(?<!MLKEM.*)\btls\.(X25519|CurveP256|CurveP384|CurveP521)\b(?!.*MLKEM)/, algorithm: (m) => (m[1] === "X25519" ? "X25519" : "ECDH") },
|
|
107
|
+
{ id: "go-tls-old", langs: ["go"], pattern: /\bMinVersion\s*:\s*tls\.VersionTLS1[01]\b/, algorithm: "TLS 1.0/1.1" },
|
|
108
|
+
// ---------- Java / Kotlin ----------
|
|
109
|
+
{ id: "java-keypairgen", langs: ["java"], pattern: /KeyPairGenerator\.getInstance\s*\(\s*"([A-Za-z0-9]+)"/, algorithm: (m) => keyType(m[1]) },
|
|
110
|
+
{ id: "java-keyagreement", langs: ["java"], pattern: /KeyAgreement\.getInstance\s*\(\s*"([A-Za-z0-9]+)"/, algorithm: (m) => (keyType(m[1]) === "ECDSA" ? "ECDH" : keyType(m[1])) },
|
|
111
|
+
{ 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]) },
|
|
112
|
+
{ id: "java-signature-ed", langs: ["java"], pattern: /Signature\.getInstance\s*\(\s*"(Ed25519|Ed448|EdDSA)"/, algorithm: (m) => (m[1] === "Ed448" ? "Ed448" : "Ed25519") },
|
|
113
|
+
{ id: "java-cipher-rsa", langs: ["java"], pattern: /Cipher\.getInstance\s*\(\s*"RSA[^"]*"/, algorithm: "RSA encryption" },
|
|
114
|
+
{ 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])) },
|
|
115
|
+
{ id: "java-weak-hash", langs: ["java"], pattern: /MessageDigest\.getInstance\s*\(\s*"(MD5|SHA-?1)"/, algorithm: (m) => hashOrCipher(m[1]) },
|
|
116
|
+
{ id: "java-keysize", langs: ["java"], pattern: /\.initialize\s*\(\s*(\d{3,4})\s*[,)]/, algorithm: (m) => (Number(m[1]) < 2048 && Number(m[1]) >= 512 ? "RSA" : null), keySize: /\.initialize\s*\(\s*(\d{3,4})/ },
|
|
117
|
+
// ---------- Config, keys, certificates (any file) ----------
|
|
118
|
+
{ id: "ssh-public-key", langs: ["any"], pattern: /\b(ssh-rsa|ssh-dss|ecdsa-sha2-nistp\d+|ssh-ed25519) AAAA[0-9A-Za-z+/]{20,}/, algorithm: (m) => ({ "ssh-rsa": "RSA signature", "ssh-dss": "DSA", "ssh-ed25519": "Ed25519" }[m[1]] ?? "ECDSA") },
|
|
119
|
+
];
|
|
120
|
+
export function langFor(path) {
|
|
121
|
+
const p = path.toLowerCase();
|
|
122
|
+
if (/\.(py|pyw)$/.test(p))
|
|
123
|
+
return "python";
|
|
124
|
+
if (/\.(js|mjs|cjs|jsx|ts|mts|cts|tsx)$/.test(p))
|
|
125
|
+
return "js";
|
|
126
|
+
if (/\.go$/.test(p))
|
|
127
|
+
return "go";
|
|
128
|
+
if (/\.(java|kt|kts|scala)$/.test(p))
|
|
129
|
+
return "java";
|
|
130
|
+
if (/(\.conf|\.cfg|\.ini|\.ya?ml|\.toml|\.tf|\.json|\.env|nginx[^/]*|httpd[^/]*|dockerfile[^/]*|containerfile[^/]*|\.hcl|\.tfvars|\.template|\.properties)$/.test(p))
|
|
131
|
+
return "config";
|
|
132
|
+
if (/\.(pem|key|crt|cer|pub|txt|sh|md)$/.test(p) || /(^|\/)(authorized_keys|known_hosts|id_[a-z0-9]+)$/.test(p))
|
|
133
|
+
return "any";
|
|
134
|
+
return null;
|
|
135
|
+
}
|
package/dist/sarif.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
// SARIF 2.1.0 output, so GitHub code scanning (and other tools) can show findings.
|
|
2
|
-
import { shortLabel } from "./report.js";
|
|
3
|
-
const LEVEL = {
|
|
4
|
-
secret: "error",
|
|
5
|
-
"weak-now": "error",
|
|
6
|
-
"quantum-vulnerable": "warning",
|
|
7
|
-
exposed: "error",
|
|
8
|
-
};
|
|
9
|
-
/** One SARIF rule per kind of problem, like "weak-now/md5" or "secret/aws-access-key". */
|
|
10
|
-
function ruleId(f) {
|
|
11
|
-
const label = shortLabel(f).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
12
|
-
return `${f.risk}/${label}`;
|
|
13
|
-
}
|
|
14
|
-
export function buildSarif(findings, toolVersion) {
|
|
15
|
-
const rules = new Map();
|
|
16
|
-
for (const f of findings) {
|
|
17
|
-
const id = ruleId(f);
|
|
18
|
-
if (!rules.has(id))
|
|
19
|
-
rules.set(id, { id, name: shortLabel(f), shortDescription: { text: f.title }, help: { text: f.fix } });
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
23
|
-
version: "2.1.0",
|
|
24
|
-
runs: [
|
|
25
|
-
{
|
|
26
|
-
tool: {
|
|
27
|
-
driver: {
|
|
28
|
-
name: "Hard Keel Quantum Scan",
|
|
29
|
-
version: toolVersion,
|
|
30
|
-
informationUri: "https://hardkeel.com",
|
|
31
|
-
rules: [...rules.values()],
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
results: findings.map((f) => ({
|
|
35
|
-
ruleId: ruleId(f),
|
|
36
|
-
level: LEVEL[f.risk],
|
|
37
|
-
message: { text: `${f.title}. ${f.fix}` },
|
|
38
|
-
locations: [{ physicalLocation: { artifactLocation: { uri: f.file }, region: { startLine: f.line } } }],
|
|
39
|
-
})),
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
}
|
|
1
|
+
// SARIF 2.1.0 output, so GitHub code scanning (and other tools) can show findings.
|
|
2
|
+
import { shortLabel } from "./report.js";
|
|
3
|
+
const LEVEL = {
|
|
4
|
+
secret: "error",
|
|
5
|
+
"weak-now": "error",
|
|
6
|
+
"quantum-vulnerable": "warning",
|
|
7
|
+
exposed: "error",
|
|
8
|
+
};
|
|
9
|
+
/** One SARIF rule per kind of problem, like "weak-now/md5" or "secret/aws-access-key". */
|
|
10
|
+
function ruleId(f) {
|
|
11
|
+
const label = shortLabel(f).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
12
|
+
return `${f.risk}/${label}`;
|
|
13
|
+
}
|
|
14
|
+
export function buildSarif(findings, toolVersion) {
|
|
15
|
+
const rules = new Map();
|
|
16
|
+
for (const f of findings) {
|
|
17
|
+
const id = ruleId(f);
|
|
18
|
+
if (!rules.has(id))
|
|
19
|
+
rules.set(id, { id, name: shortLabel(f), shortDescription: { text: f.title }, help: { text: f.fix } });
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
23
|
+
version: "2.1.0",
|
|
24
|
+
runs: [
|
|
25
|
+
{
|
|
26
|
+
tool: {
|
|
27
|
+
driver: {
|
|
28
|
+
name: "Hard Keel Quantum Scan",
|
|
29
|
+
version: toolVersion,
|
|
30
|
+
informationUri: "https://hardkeel.com",
|
|
31
|
+
rules: [...rules.values()],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
results: findings.map((f) => ({
|
|
35
|
+
ruleId: ruleId(f),
|
|
36
|
+
level: LEVEL[f.risk],
|
|
37
|
+
message: { text: `${f.title}. ${f.fix}` },
|
|
38
|
+
locations: [{ physicalLocation: { artifactLocation: { uri: f.file }, region: { startLine: f.line } } }],
|
|
39
|
+
})),
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
}
|