@quantakrypto/core 0.4.1 → 0.4.3
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/LICENSE +201 -0
- package/README.md +38 -10
- package/dist/agent-types.js.map +1 -1
- package/dist/baseline.js.map +1 -1
- package/dist/cache.js.map +1 -1
- package/dist/cbom.d.ts.map +1 -1
- package/dist/cbom.js +13 -4
- package/dist/cbom.js.map +1 -1
- package/dist/changed.js.map +1 -1
- package/dist/codemods/config-toggle.js.map +1 -1
- package/dist/codemods/registry.js.map +1 -1
- package/dist/comments.d.ts +26 -0
- package/dist/comments.d.ts.map +1 -1
- package/dist/comments.js +141 -1
- package/dist/comments.js.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/cwe.js.map +1 -1
- package/dist/dependencies.d.ts +3 -2
- package/dist/dependencies.d.ts.map +1 -1
- package/dist/dependencies.js +151 -4
- package/dist/dependencies.js.map +1 -1
- package/dist/detect-utils.d.ts +14 -3
- package/dist/detect-utils.d.ts.map +1 -1
- package/dist/detect-utils.js +32 -4
- package/dist/detect-utils.js.map +1 -1
- package/dist/detectors/c.d.ts.map +1 -1
- package/dist/detectors/c.js +190 -2
- package/dist/detectors/c.js.map +1 -1
- package/dist/detectors/csharp.d.ts.map +1 -1
- package/dist/detectors/csharp.js +141 -3
- package/dist/detectors/csharp.js.map +1 -1
- package/dist/detectors/go.d.ts +5 -3
- package/dist/detectors/go.d.ts.map +1 -1
- package/dist/detectors/go.js +187 -3
- package/dist/detectors/go.js.map +1 -1
- package/dist/detectors/java.d.ts.map +1 -1
- package/dist/detectors/java.js +168 -3
- package/dist/detectors/java.js.map +1 -1
- package/dist/detectors/pem.d.ts.map +1 -1
- package/dist/detectors/pem.js +49 -1
- package/dist/detectors/pem.js.map +1 -1
- package/dist/detectors/python.d.ts.map +1 -1
- package/dist/detectors/python.js +74 -3
- package/dist/detectors/python.js.map +1 -1
- package/dist/detectors/ruby.d.ts +9 -5
- package/dist/detectors/ruby.d.ts.map +1 -1
- package/dist/detectors/ruby.js +122 -2
- package/dist/detectors/ruby.js.map +1 -1
- package/dist/detectors/rust.d.ts +8 -3
- package/dist/detectors/rust.d.ts.map +1 -1
- package/dist/detectors/rust.js +185 -3
- package/dist/detectors/rust.js.map +1 -1
- package/dist/detectors/source.d.ts.map +1 -1
- package/dist/detectors/source.js +131 -13
- package/dist/detectors/source.js.map +1 -1
- package/dist/detectors/stateful-hbs.d.ts +22 -0
- package/dist/detectors/stateful-hbs.d.ts.map +1 -0
- package/dist/detectors/stateful-hbs.js +139 -0
- package/dist/detectors/stateful-hbs.js.map +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/evidence.d.ts +48 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +76 -0
- package/dist/evidence.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/inventory.d.ts +2 -0
- package/dist/inventory.d.ts.map +1 -1
- package/dist/inventory.js +27 -1
- package/dist/inventory.js.map +1 -1
- package/dist/parallel.js +15 -0
- package/dist/parallel.js.map +1 -1
- package/dist/patch-policy.js.map +1 -1
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +122 -7
- package/dist/redact.js.map +1 -1
- package/dist/registry.d.ts +2 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +4 -2
- package/dist/registry.js.map +1 -1
- package/dist/remediate-pipeline.d.ts +3 -0
- package/dist/remediate-pipeline.d.ts.map +1 -1
- package/dist/remediate-pipeline.js +50 -0
- package/dist/remediate-pipeline.js.map +1 -1
- package/dist/remediate-request.js.map +1 -1
- package/dist/remediation.d.ts +9 -3
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +33 -6
- package/dist/remediation.js.map +1 -1
- package/dist/report.d.ts +9 -0
- package/dist/report.d.ts.map +1 -1
- package/dist/report.js +31 -0
- package/dist/report.js.map +1 -1
- package/dist/scan-worker.js.map +1 -1
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +16 -2
- package/dist/scan.js.map +1 -1
- package/dist/severity.js.map +1 -1
- package/dist/triage.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/verify.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/walk.js.map +1 -1
- package/dist/worktree.d.ts.map +1 -1
- package/dist/worktree.js +10 -1
- package/dist/worktree.js.map +1 -1
- package/package.json +1 -1
- package/src/cbom.ts +13 -4
- package/src/comments.ts +140 -1
- package/src/dependencies.ts +156 -6
- package/src/detect-utils.ts +33 -4
- package/src/detectors/c.ts +202 -2
- package/src/detectors/csharp.ts +154 -3
- package/src/detectors/go.ts +209 -6
- package/src/detectors/java.ts +189 -3
- package/src/detectors/pem.ts +53 -1
- package/src/detectors/python.ts +82 -3
- package/src/detectors/ruby.ts +138 -7
- package/src/detectors/rust.ts +211 -7
- package/src/detectors/source.ts +163 -12
- package/src/detectors/stateful-hbs.ts +177 -0
- package/src/evidence.ts +124 -0
- package/src/index.ts +5 -1
- package/src/inventory.ts +31 -1
- package/src/parallel.ts +15 -0
- package/src/redact.ts +125 -8
- package/src/registry.ts +4 -2
- package/src/remediate-pipeline.ts +55 -0
- package/src/remediation.ts +41 -9
- package/src/report.ts +41 -2
- package/src/scan.ts +21 -2
- package/src/types.ts +8 -1
- package/src/version.ts +1 -1
- package/src/worktree.ts +9 -1
package/src/detectors/rust.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Source-code detector for classical asymmetric cryptography in Rust. Covers the
|
|
3
3
|
* common crypto crates: `rsa`, `ring`, the `*-dalek` family (ed25519/x25519),
|
|
4
|
-
*
|
|
5
|
-
* strategy as the other packs; the `::` path
|
|
4
|
+
* the RustCrypto elliptic-curve crates (`p256`/`p384`/`k256`), and the `openssl`
|
|
5
|
+
* crate bindings. Lexical, same strategy as the other packs; the `::` path
|
|
6
|
+
* syntax makes the signals precise.
|
|
6
7
|
*
|
|
7
8
|
* HNDL: RSA encryption and (EC/X)DH key agreement are harvest-now-decrypt-later
|
|
8
|
-
* exposed (hndl:true); ECDSA / Ed25519 signatures are hndl:false but
|
|
9
|
+
* exposed (hndl:true); ECDSA / DSA / Ed25519 signatures are hndl:false but
|
|
10
|
+
* forgeable. `openssl::EcKey` keygen is ambiguous (feeds ECDSA + ECDH),
|
|
11
|
+
* classified conservatively as key-exchange-capable (hndl:true). Also flags
|
|
12
|
+
* Rust TLS certificate-validation bypasses (reqwest / rustls) — not quantum but
|
|
13
|
+
* mirrors the JS tlsDetector's cert-validation category.
|
|
9
14
|
*/
|
|
10
|
-
import type { Detector, Finding, RuleMeta } from "../types.js";
|
|
15
|
+
import type { AlgorithmFamily, Detector, Finding, RuleMeta } from "../types.js";
|
|
11
16
|
import { RUST_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
|
|
12
|
-
import { CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
17
|
+
import { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION } from "../cwe.js";
|
|
13
18
|
|
|
14
19
|
// `rsa` crate + ring RsaKeyPair. `::` after the type marks an associated-fn call.
|
|
15
20
|
const RE_RUST_RSA = /\b(?:RsaPrivateKey|RsaPublicKey|RsaKeyPair)::/g;
|
|
@@ -22,6 +27,31 @@ const RE_RUST_ECDH = /\becdh::EphemeralSecret\b|\bagreement::ECDH_P(?:256|384)\b
|
|
|
22
27
|
const RE_RUST_ED25519 = /\bed25519_dalek::(?:SigningKey|Keypair|SecretKey)\b|\bEd25519KeyPair::/g;
|
|
23
28
|
// X25519 key agreement (dalek).
|
|
24
29
|
const RE_RUST_X25519 = /\bx25519_dalek::(?:EphemeralSecret|StaticSecret)\b/g;
|
|
30
|
+
// openssl crate bindings — the `Type::generate(` / `Dh::` call forms, distinct
|
|
31
|
+
// from the ring / RustCrypto path syntax above (audit F5/F9 false-negatives).
|
|
32
|
+
const RE_RUST_OPENSSL_RSA = /\bRsa::generate\s*\(/g;
|
|
33
|
+
const RE_RUST_OPENSSL_EC = /\bEcKey::generate\s*\(/g;
|
|
34
|
+
const RE_RUST_OPENSSL_DSA = /\bDsa::generate\s*\(/g;
|
|
35
|
+
const RE_RUST_OPENSSL_DH = /\bDh::/g;
|
|
36
|
+
// ring X25519 agreement (the ECDH_P* forms are handled by RE_RUST_ECDH above).
|
|
37
|
+
const RE_RUST_RING_X25519 = /\bagreement::X25519\b/g;
|
|
38
|
+
// Bare (unqualified) constructors: a braced `use x25519_dalek::{EphemeralSecret}`
|
|
39
|
+
// / `use ed25519_dalek::{SigningKey}` strips the `::` path prefix, defeating the
|
|
40
|
+
// path-qualified rules above. The `(?<![:\w])` lookbehind keeps these from
|
|
41
|
+
// double-matching the qualified forms (e.g. `p256::ecdsa::SigningKey::random`).
|
|
42
|
+
const RE_RUST_BARE_X25519 = /(?<![:\w])EphemeralSecret::new\s*\(/g;
|
|
43
|
+
const RE_RUST_BARE_SIGNINGKEY = /(?<![:\w])SigningKey::(?:generate|random)\s*\(/g;
|
|
44
|
+
// jsonwebtoken crate `Algorithm` enum variants selecting a classical JWT signer:
|
|
45
|
+
// RSASSA-PKCS1 (RS*), RSASSA-PSS (PS*), ECDSA (ES*), and Ed25519 (EdDSA). The
|
|
46
|
+
// `\s*` between `Algorithm` and `::` catches the variant split across lines /
|
|
47
|
+
// routed through a helper (audit token_policy false-negative); the required
|
|
48
|
+
// suffix keeps it off unrelated `Algorithm::` uses (e.g. `HS256` HMAC, which is
|
|
49
|
+
// symmetric and not quantum-vulnerable, or `Algorithm::new`).
|
|
50
|
+
const RE_RUST_JWT_ALG = /\bAlgorithm\s*::(RS|PS|ES)(?:256|384|512)\b|\bAlgorithm\s*::EdDSA\b/g;
|
|
51
|
+
// Rust TLS certificate-validation bypass: reqwest `danger_accept_invalid_certs`
|
|
52
|
+
// and the rustls `.dangerous()` escape hatch. Mirrors the JS tlsDetector.
|
|
53
|
+
const RE_RUST_TLS_ACCEPT_INVALID = /\bdanger_accept_invalid_certs\s*\(\s*true/g;
|
|
54
|
+
const RE_RUST_TLS_DANGEROUS = /\.dangerous\s*\(\s*\)/g;
|
|
25
55
|
|
|
26
56
|
const RULE_RUST_RSA: RuleMeta = {
|
|
27
57
|
id: "rust-rsa",
|
|
@@ -78,13 +108,148 @@ const RULE_RUST_X25519: RuleMeta = {
|
|
|
78
108
|
title: "Rust X25519 key agreement",
|
|
79
109
|
description: "x25519-dalek EphemeralSecret/StaticSecret",
|
|
80
110
|
category: "key-exchange",
|
|
81
|
-
severity: "
|
|
111
|
+
severity: "medium",
|
|
82
112
|
confidence: "high",
|
|
83
113
|
algorithm: "X25519",
|
|
84
114
|
hndl: true,
|
|
85
115
|
cwe: CWE_BROKEN_CRYPTO,
|
|
86
116
|
message: "X25519 (Rust) is modern but still classical key agreement — harvest-now-decrypt-later.",
|
|
87
117
|
};
|
|
118
|
+
const RULE_RUST_OPENSSL_RSA: RuleMeta = {
|
|
119
|
+
id: "rust-openssl-rsa",
|
|
120
|
+
title: "Rust openssl RSA key generation",
|
|
121
|
+
description: "openssl crate Rsa::generate",
|
|
122
|
+
category: "kem",
|
|
123
|
+
severity: "high",
|
|
124
|
+
confidence: "high",
|
|
125
|
+
algorithm: "RSA",
|
|
126
|
+
hndl: true,
|
|
127
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
128
|
+
message:
|
|
129
|
+
"Generates a classical RSA key pair via the Rust `openssl` crate — not quantum-safe and RSA encryption is HNDL-exposed.",
|
|
130
|
+
};
|
|
131
|
+
const RULE_RUST_OPENSSL_EC: RuleMeta = {
|
|
132
|
+
id: "rust-openssl-ec",
|
|
133
|
+
title: "Rust openssl EC key generation",
|
|
134
|
+
description: "openssl crate EcKey::generate",
|
|
135
|
+
category: "key-exchange",
|
|
136
|
+
severity: "high",
|
|
137
|
+
confidence: "high",
|
|
138
|
+
algorithm: "ECDH",
|
|
139
|
+
hndl: true,
|
|
140
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
141
|
+
message:
|
|
142
|
+
"Generates a classical EC key pair via the Rust `openssl` crate. EC keys feed BOTH ECDSA signatures and ECDH key agreement; the ECDH path is harvest-now-decrypt-later exposed.",
|
|
143
|
+
remediation:
|
|
144
|
+
"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
|
|
145
|
+
};
|
|
146
|
+
const RULE_RUST_OPENSSL_DSA: RuleMeta = {
|
|
147
|
+
id: "rust-openssl-dsa",
|
|
148
|
+
title: "Rust openssl DSA key/usage",
|
|
149
|
+
description: "openssl crate Dsa::generate",
|
|
150
|
+
category: "signature",
|
|
151
|
+
severity: "high",
|
|
152
|
+
confidence: "high",
|
|
153
|
+
algorithm: "DSA",
|
|
154
|
+
hndl: false,
|
|
155
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
156
|
+
message:
|
|
157
|
+
"Classical DSA via the Rust `openssl` crate is deprecated and forgeable by a quantum attacker.",
|
|
158
|
+
remediation: "Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).",
|
|
159
|
+
};
|
|
160
|
+
const RULE_RUST_OPENSSL_DH: RuleMeta = {
|
|
161
|
+
id: "rust-openssl-dh",
|
|
162
|
+
title: "Rust openssl Diffie-Hellman key exchange",
|
|
163
|
+
description: "openssl crate Dh params / key generation",
|
|
164
|
+
category: "key-exchange",
|
|
165
|
+
severity: "high",
|
|
166
|
+
confidence: "high",
|
|
167
|
+
algorithm: "DH",
|
|
168
|
+
hndl: true,
|
|
169
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
170
|
+
message:
|
|
171
|
+
"Finite-field Diffie-Hellman via the Rust `openssl` crate is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
172
|
+
};
|
|
173
|
+
const RULE_RUST_RING_X25519: RuleMeta = {
|
|
174
|
+
id: "rust-ring-x25519",
|
|
175
|
+
title: "Rust ring X25519 key agreement",
|
|
176
|
+
description: "ring agreement::X25519",
|
|
177
|
+
category: "key-exchange",
|
|
178
|
+
severity: "medium",
|
|
179
|
+
confidence: "high",
|
|
180
|
+
algorithm: "X25519",
|
|
181
|
+
hndl: true,
|
|
182
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
183
|
+
message:
|
|
184
|
+
"X25519 key agreement via ring (Rust) is modern but still classical — harvest-now-decrypt-later.",
|
|
185
|
+
};
|
|
186
|
+
const RULE_RUST_BARE_X25519: RuleMeta = {
|
|
187
|
+
id: "rust-x25519-bare",
|
|
188
|
+
title: "Rust X25519 key agreement (unqualified)",
|
|
189
|
+
description: "bare EphemeralSecret::new (x25519-dalek imported via `use`)",
|
|
190
|
+
category: "key-exchange",
|
|
191
|
+
severity: "medium",
|
|
192
|
+
confidence: "medium",
|
|
193
|
+
algorithm: "X25519",
|
|
194
|
+
hndl: true,
|
|
195
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
196
|
+
message:
|
|
197
|
+
"X25519 key agreement (x25519-dalek, imported unqualified) is modern but still classical — harvest-now-decrypt-later.",
|
|
198
|
+
};
|
|
199
|
+
const RULE_RUST_BARE_SIGNINGKEY: RuleMeta = {
|
|
200
|
+
id: "rust-signingkey-bare",
|
|
201
|
+
title: "Rust signature key (unqualified)",
|
|
202
|
+
description: "bare SigningKey::generate/random (ed25519-dalek / k256 via `use`)",
|
|
203
|
+
category: "signature",
|
|
204
|
+
severity: "medium",
|
|
205
|
+
confidence: "medium",
|
|
206
|
+
algorithm: "unknown",
|
|
207
|
+
hndl: false,
|
|
208
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
209
|
+
message:
|
|
210
|
+
"Classical signature key from an unqualified `SigningKey` (ed25519-dalek Ed25519 / k256 ECDSA) — forgeable by a quantum attacker.",
|
|
211
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
212
|
+
};
|
|
213
|
+
const RULE_RUST_JWT_ALGORITHM: RuleMeta = {
|
|
214
|
+
id: "rust-jwt-algorithm",
|
|
215
|
+
title: "Rust jsonwebtoken classical signature algorithm",
|
|
216
|
+
description: "jsonwebtoken Algorithm::{RS,PS,ES}* / Algorithm::EdDSA enum variant",
|
|
217
|
+
category: "signature",
|
|
218
|
+
severity: "high",
|
|
219
|
+
confidence: "high",
|
|
220
|
+
// Representative family; refined per-finding (RS*/PS* → RSA, ES* → ECDSA, EdDSA).
|
|
221
|
+
algorithm: "RSA",
|
|
222
|
+
hndl: false,
|
|
223
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
224
|
+
message:
|
|
225
|
+
"Selects a classical JWT signature algorithm (jsonwebtoken RS*/PS*/ES*/EdDSA), forgeable by a quantum attacker.",
|
|
226
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
227
|
+
};
|
|
228
|
+
const RULE_RUST_TLS_ACCEPT_INVALID: RuleMeta = {
|
|
229
|
+
id: "rust-tls-accept-invalid-certs",
|
|
230
|
+
title: "Rust TLS certificate verification disabled",
|
|
231
|
+
description: "reqwest danger_accept_invalid_certs(true)",
|
|
232
|
+
category: "tls",
|
|
233
|
+
severity: "high",
|
|
234
|
+
confidence: "high",
|
|
235
|
+
hndl: false,
|
|
236
|
+
cwe: CWE_CERT_VALIDATION,
|
|
237
|
+
message:
|
|
238
|
+
"danger_accept_invalid_certs(true) disables TLS certificate verification in reqwest (MITM risk).",
|
|
239
|
+
remediation: "Remove danger_accept_invalid_certs(true); verify certificates properly.",
|
|
240
|
+
};
|
|
241
|
+
const RULE_RUST_TLS_DANGEROUS: RuleMeta = {
|
|
242
|
+
id: "rust-tls-rustls-dangerous",
|
|
243
|
+
title: "Rust rustls dangerous certificate config",
|
|
244
|
+
description: "rustls ClientConfig .dangerous() escape hatch",
|
|
245
|
+
category: "tls",
|
|
246
|
+
severity: "high",
|
|
247
|
+
confidence: "medium",
|
|
248
|
+
hndl: false,
|
|
249
|
+
cwe: CWE_CERT_VALIDATION,
|
|
250
|
+
message: "rustls `.dangerous()` opts into disabling certificate verification (MITM risk).",
|
|
251
|
+
remediation: "Avoid the dangerous() escape hatch; keep the default certificate verifier.",
|
|
252
|
+
};
|
|
88
253
|
|
|
89
254
|
/** Detects classical asymmetric crypto in Rust (rsa, ring, dalek, p256/k256). */
|
|
90
255
|
export const rustDetector: Detector = {
|
|
@@ -92,7 +257,23 @@ export const rustDetector: Detector = {
|
|
|
92
257
|
description: "Classical asymmetric crypto in Rust (rsa, ring, *-dalek, p256/k256)",
|
|
93
258
|
scope: "source",
|
|
94
259
|
language: "rust",
|
|
95
|
-
rules: [
|
|
260
|
+
rules: [
|
|
261
|
+
RULE_RUST_RSA,
|
|
262
|
+
RULE_RUST_ECDSA,
|
|
263
|
+
RULE_RUST_ECDH,
|
|
264
|
+
RULE_RUST_ED25519,
|
|
265
|
+
RULE_RUST_X25519,
|
|
266
|
+
RULE_RUST_OPENSSL_RSA,
|
|
267
|
+
RULE_RUST_OPENSSL_EC,
|
|
268
|
+
RULE_RUST_OPENSSL_DSA,
|
|
269
|
+
RULE_RUST_OPENSSL_DH,
|
|
270
|
+
RULE_RUST_RING_X25519,
|
|
271
|
+
RULE_RUST_BARE_X25519,
|
|
272
|
+
RULE_RUST_BARE_SIGNINGKEY,
|
|
273
|
+
RULE_RUST_JWT_ALGORITHM,
|
|
274
|
+
RULE_RUST_TLS_ACCEPT_INVALID,
|
|
275
|
+
RULE_RUST_TLS_DANGEROUS,
|
|
276
|
+
],
|
|
96
277
|
appliesTo: (f) => hasExtension(f, RUST_EXTENSIONS),
|
|
97
278
|
detect({ file, content }): Finding[] {
|
|
98
279
|
const findings: Finding[] = [];
|
|
@@ -107,6 +288,29 @@ export const rustDetector: Detector = {
|
|
|
107
288
|
add(RE_RUST_ECDH, RULE_RUST_ECDH);
|
|
108
289
|
add(RE_RUST_ED25519, RULE_RUST_ED25519);
|
|
109
290
|
add(RE_RUST_X25519, RULE_RUST_X25519);
|
|
291
|
+
add(RE_RUST_OPENSSL_RSA, RULE_RUST_OPENSSL_RSA);
|
|
292
|
+
add(RE_RUST_OPENSSL_EC, RULE_RUST_OPENSSL_EC);
|
|
293
|
+
add(RE_RUST_OPENSSL_DSA, RULE_RUST_OPENSSL_DSA);
|
|
294
|
+
add(RE_RUST_OPENSSL_DH, RULE_RUST_OPENSSL_DH);
|
|
295
|
+
add(RE_RUST_RING_X25519, RULE_RUST_RING_X25519);
|
|
296
|
+
add(RE_RUST_BARE_X25519, RULE_RUST_BARE_X25519);
|
|
297
|
+
add(RE_RUST_BARE_SIGNINGKEY, RULE_RUST_BARE_SIGNINGKEY);
|
|
298
|
+
// jsonwebtoken Algorithm enum variants — resolve the family per match: the
|
|
299
|
+
// RS*/PS* variants are RSASSA (RSA), ES* is ECDSA, EdDSA is Ed25519.
|
|
300
|
+
eachMatch(RE_RUST_JWT_ALG, content, (m) => {
|
|
301
|
+
const prefix = m[1];
|
|
302
|
+
const algorithm: AlgorithmFamily =
|
|
303
|
+
prefix === undefined ? "EdDSA" : prefix === "ES" ? "ECDSA" : "RSA";
|
|
304
|
+
findings.push(
|
|
305
|
+
findingFromRule(
|
|
306
|
+
RULE_RUST_JWT_ALGORITHM,
|
|
307
|
+
{ file, content, index: m.index, matchLength: m[0].length },
|
|
308
|
+
{ algorithm },
|
|
309
|
+
),
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
add(RE_RUST_TLS_ACCEPT_INVALID, RULE_RUST_TLS_ACCEPT_INVALID);
|
|
313
|
+
add(RE_RUST_TLS_DANGEROUS, RULE_RUST_TLS_DANGEROUS);
|
|
110
314
|
return findings;
|
|
111
315
|
},
|
|
112
316
|
};
|
package/src/detectors/source.ts
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
import type { Detector, Finding, RuleMeta } from "../types.js";
|
|
30
30
|
import {
|
|
31
31
|
JS_TS_EXTENSIONS,
|
|
32
|
+
DOC_EXTENSIONS,
|
|
32
33
|
JWT_HOST_EXTENSIONS,
|
|
33
34
|
eachMatch,
|
|
34
35
|
findingFromRule,
|
|
@@ -95,8 +96,11 @@ const RE_TLS_REJECT = /rejectUnauthorized\s*:\s*false/g;
|
|
|
95
96
|
// Hardened cipher regex: bounded spans (no unbounded `[^'"`]*` straddling the
|
|
96
97
|
// alternation), single-quote-style anchoring removed in favour of {0,256} bounds
|
|
97
98
|
// so worst-case backtracking is linear in the bound, not the file (P0-6).
|
|
99
|
+
// The `(?<![!-])` lookbehind skips OpenSSL EXCLUSION syntax — `!MD5` / `-RC4`
|
|
100
|
+
// DISABLE those ciphers, so a hardened list like `...:!aNULL:!MD5:!RC4` must not
|
|
101
|
+
// be flagged as weak (audit: crypto #7). A genuinely-enabled `RC4` still matches.
|
|
98
102
|
const RE_TLS_WEAK_CIPHER =
|
|
99
|
-
/ciphers\s*:\s*['"`][^'"`\n]{0,256}?\b(RC4|DES|3DES|MD5|NULL|EXPORT|aNULL|eNULL)\b[^'"`\n]{0,256}?['"`]/gi;
|
|
103
|
+
/ciphers\s*:\s*['"`][^'"`\n]{0,256}?\b(?<![!-])(RC4|DES|3DES|MD5|NULL|EXPORT|aNULL|eNULL)\b[^'"`\n]{0,256}?['"`]/gi;
|
|
100
104
|
|
|
101
105
|
/* -------------------------------------------------------------------------- */
|
|
102
106
|
/* Node.js `crypto` module */
|
|
@@ -277,8 +281,8 @@ const nodeCryptoDetector: Detector = {
|
|
|
277
281
|
},
|
|
278
282
|
dsa: { algo: "DSA", cat: "signature", sev: "high", hndl: false, label: "DSA" },
|
|
279
283
|
dh: { algo: "DH", cat: "key-exchange", sev: "high", hndl: true, label: "Diffie-Hellman" },
|
|
280
|
-
x25519: { algo: "X25519", cat: "key-exchange", sev: "
|
|
281
|
-
x448: { algo: "X448", cat: "key-exchange", sev: "
|
|
284
|
+
x25519: { algo: "X25519", cat: "key-exchange", sev: "medium", hndl: true, label: "X25519" },
|
|
285
|
+
x448: { algo: "X448", cat: "key-exchange", sev: "medium", hndl: true, label: "X448" },
|
|
282
286
|
ed25519: { algo: "EdDSA", cat: "signature", sev: "low", hndl: false, label: "Ed25519" },
|
|
283
287
|
ed448: { algo: "EdDSA", cat: "signature", sev: "low", hndl: false, label: "Ed448" },
|
|
284
288
|
};
|
|
@@ -511,11 +515,14 @@ const RULE_ELLIPTIC_EC: RuleMeta = {
|
|
|
511
515
|
id: "elliptic-ec",
|
|
512
516
|
title: "elliptic curve instantiation",
|
|
513
517
|
description: "the `elliptic` library — new EC(...)",
|
|
514
|
-
|
|
518
|
+
// `new EC(...)` is a dual-use curve context (ECDSA sign AND ECDH `key.derive()`).
|
|
519
|
+
// Per this scanner's own EC-ambiguity policy, ambiguous EC is treated as
|
|
520
|
+
// key-agreement-capable and HNDL-exposed (audit: crypto #8).
|
|
521
|
+
category: "key-exchange",
|
|
515
522
|
severity: "high",
|
|
516
523
|
confidence: "high",
|
|
517
|
-
algorithm: "
|
|
518
|
-
hndl:
|
|
524
|
+
algorithm: "ECDH",
|
|
525
|
+
hndl: true,
|
|
519
526
|
cwe: CWE_BROKEN_CRYPTO,
|
|
520
527
|
message:
|
|
521
528
|
"The `elliptic` library implements classical ECDSA/ECDH, both broken by Shor's algorithm.",
|
|
@@ -538,11 +545,13 @@ const RULE_JSRSASIGN_KEYGEN: RuleMeta = {
|
|
|
538
545
|
id: "jsrsasign-keygen",
|
|
539
546
|
title: "jsrsasign key generation",
|
|
540
547
|
description: "jsrsasign KEYUTIL.generateKeypair",
|
|
541
|
-
|
|
548
|
+
// KEYUTIL.generateKeypair("RSA"|"EC") makes keys usable for RSA-OAEP encryption
|
|
549
|
+
// and ECDH — HNDL-exposed, like Node's generateKeyPair (audit: crypto #13).
|
|
550
|
+
category: "key-exchange",
|
|
542
551
|
severity: "high",
|
|
543
552
|
confidence: "high",
|
|
544
553
|
algorithm: "unknown",
|
|
545
|
-
hndl:
|
|
554
|
+
hndl: true,
|
|
546
555
|
cwe: CWE_BROKEN_CRYPTO,
|
|
547
556
|
message: "jsrsasign generates classical RSA/EC key pairs, which are not quantum-safe.",
|
|
548
557
|
remediation: "ML-KEM-768 (FIPS 203) / ML-DSA-65 (FIPS 204)",
|
|
@@ -615,6 +624,11 @@ const libraryDetector: Detector = {
|
|
|
615
624
|
/* JWT / JOSE / COSE algorithm strings */
|
|
616
625
|
/* -------------------------------------------------------------------------- */
|
|
617
626
|
|
|
627
|
+
// JOSE RSA key-transport algorithms (JWE `alg`): quoted RSA-OAEP / RSA-OAEP-256
|
|
628
|
+
// /384/512 / RSA1_5. Classical RSA *encryption* (key transport) — distinct from
|
|
629
|
+
// the RS*/PS* *signature* tokens above, and a harvest-now-decrypt-later surface.
|
|
630
|
+
const RE_JOSE_KEM = /['"`](RSA-OAEP(?:-(?:256|384|512))?|RSA1_5)['"`]/g;
|
|
631
|
+
|
|
618
632
|
const RULE_JWT_ALG: RuleMeta = {
|
|
619
633
|
id: "jwt-classical-alg",
|
|
620
634
|
title: "Classical JWT/JOSE algorithm",
|
|
@@ -642,6 +656,20 @@ const RULE_JOSE_ECDH: RuleMeta = {
|
|
|
642
656
|
"JOSE ECDH-ES performs classical ECDH key agreement — harvest-now-decrypt-later exposed.",
|
|
643
657
|
remediation: "Track IETF PQC JOSE/COSE; adopt hybrid X25519MLKEM768 KEM-based encryption.",
|
|
644
658
|
};
|
|
659
|
+
const RULE_JOSE_RSA_OAEP: RuleMeta = {
|
|
660
|
+
id: "jose-rsa-oaep",
|
|
661
|
+
title: "JOSE RSA key-transport algorithm",
|
|
662
|
+
description: "JWE RSA-OAEP / RSA-OAEP-256/384/512 / RSA1_5 key encryption",
|
|
663
|
+
category: "key-exchange",
|
|
664
|
+
severity: "high",
|
|
665
|
+
confidence: "medium",
|
|
666
|
+
algorithm: "RSA",
|
|
667
|
+
hndl: true,
|
|
668
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
669
|
+
message:
|
|
670
|
+
"JOSE RSA key transport (RSA-OAEP / RSA1_5) is classical RSA encryption — harvest-now-decrypt-later exposed.",
|
|
671
|
+
remediation: "Track IETF PQC JOSE/COSE; adopt hybrid X25519MLKEM768 KEM-based encryption.",
|
|
672
|
+
};
|
|
645
673
|
|
|
646
674
|
/**
|
|
647
675
|
* Detects classical signature algorithm identifiers used by JWT/JOSE, plus
|
|
@@ -656,7 +684,7 @@ const jwtDetector: Detector = {
|
|
|
656
684
|
// signal in JS/TS or Python (e.g. PyJWT `algorithm="RS256"`), so this detector
|
|
657
685
|
// is un-gated from JS-only to the JWT host surfaces.
|
|
658
686
|
language: "any",
|
|
659
|
-
rules: [RULE_JWT_ALG, RULE_JOSE_ECDH],
|
|
687
|
+
rules: [RULE_JWT_ALG, RULE_JOSE_ECDH, RULE_JOSE_RSA_OAEP],
|
|
660
688
|
appliesTo: (f) => hasExtension(f, JWT_HOST_EXTENSIONS),
|
|
661
689
|
detect({ file, content }): Finding[] {
|
|
662
690
|
const findings: Finding[] = [];
|
|
@@ -695,6 +723,20 @@ const jwtDetector: Detector = {
|
|
|
695
723
|
);
|
|
696
724
|
});
|
|
697
725
|
|
|
726
|
+
// JOSE RSA key transport (RSA-OAEP / RSA1_5) — classical RSA encryption, HNDL.
|
|
727
|
+
eachMatch(RE_JOSE_KEM, content, (m) => {
|
|
728
|
+
findings.push(
|
|
729
|
+
findingFromRule(
|
|
730
|
+
RULE_JOSE_RSA_OAEP,
|
|
731
|
+
{ file, content, index: m.index, matchLength: m[0].length },
|
|
732
|
+
{
|
|
733
|
+
title: `JOSE RSA key transport ${m[1]}`,
|
|
734
|
+
message: `JOSE "${m[1]}" is classical RSA key transport — harvest-now-decrypt-later exposed.`,
|
|
735
|
+
},
|
|
736
|
+
),
|
|
737
|
+
);
|
|
738
|
+
});
|
|
739
|
+
|
|
698
740
|
return findings;
|
|
699
741
|
},
|
|
700
742
|
};
|
|
@@ -802,6 +844,13 @@ const tlsDetector: Detector = {
|
|
|
802
844
|
const RE_SSH_PUBKEY = /\b(ssh-rsa|ssh-ed25519|ssh-dss|ecdsa-sha2-nistp(?:256|384|521))\b/g;
|
|
803
845
|
const RE_CERT_SIG_ALG =
|
|
804
846
|
/\b(sha(?:1|256|384|512)WithRSAEncryption|ecdsa-with-SHA(?:1|256|384|512)|rsassaPss|dsaWithSHA(?:1|256))\b/g;
|
|
847
|
+
// Classical SSH key-exchange algorithm identifiers: finite-field DH groups
|
|
848
|
+
// (diffie-hellman-group{1,14,15,16,17,18} + group-exchange), ECDH over NIST
|
|
849
|
+
// curves (ecdh-sha2-nistp*), and Curve25519 (curve25519-sha256). All are
|
|
850
|
+
// Shor-broken key agreement — the harvest-now-decrypt-later surface a lexical
|
|
851
|
+
// scan misses when only the `crypto/*` API is matched, not the negotiated kex.
|
|
852
|
+
const RE_SSH_KEX =
|
|
853
|
+
/\b(diffie-hellman-group(?:1|14|15|16|17|18)(?:-sha1|-sha256|-sha512)?|diffie-hellman-group-exchange-sha(?:1|256)|ecdh-sha2-nistp(?:256|384|521)|curve25519-sha256)\b/g;
|
|
805
854
|
|
|
806
855
|
const RULE_SSH_PUBKEY: RuleMeta = {
|
|
807
856
|
id: "ssh-public-key",
|
|
@@ -815,7 +864,8 @@ const RULE_SSH_PUBKEY: RuleMeta = {
|
|
|
815
864
|
cwe: CWE_BROKEN_CRYPTO,
|
|
816
865
|
sensitive: true,
|
|
817
866
|
message: "A classical SSH public key is forgeable by a quantum attacker.",
|
|
818
|
-
remediation:
|
|
867
|
+
remediation:
|
|
868
|
+
"Plan migration to PQC-capable SSH: prefer the mlkem768x25519-sha256 KEX (ML-KEM-768 hybrid, OpenSSH 10's default since Apr 2025); sntrup761x25519 is an acceptable interim. Rotate to PQC host keys as they land.",
|
|
819
869
|
};
|
|
820
870
|
const RULE_CERT_SIG_ALG: RuleMeta = {
|
|
821
871
|
id: "cert-signature-algorithm",
|
|
@@ -831,6 +881,21 @@ const RULE_CERT_SIG_ALG: RuleMeta = {
|
|
|
831
881
|
"A classical certificate signature algorithm (RSA/ECDSA/DSA) is a quantum forgery surface.",
|
|
832
882
|
remediation: "Plan re-issuance with PQC-capable CAs as ML-DSA certificate profiles mature.",
|
|
833
883
|
};
|
|
884
|
+
const RULE_SSH_KEX: RuleMeta = {
|
|
885
|
+
id: "ssh-kex-classical",
|
|
886
|
+
title: "Classical SSH key exchange",
|
|
887
|
+
description: "diffie-hellman-group* / group-exchange / ecdh-sha2-* / curve25519-sha256 kex",
|
|
888
|
+
category: "key-exchange",
|
|
889
|
+
severity: "medium",
|
|
890
|
+
confidence: "medium",
|
|
891
|
+
algorithm: "unknown",
|
|
892
|
+
hndl: true,
|
|
893
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
894
|
+
message:
|
|
895
|
+
"A classical SSH key-exchange algorithm (finite-field DH / ECDH / X25519) is harvest-now-decrypt-later exposed.",
|
|
896
|
+
remediation:
|
|
897
|
+
"Prefer the mlkem768x25519-sha256 KEX (ML-KEM-768 hybrid, OpenSSH 10 default); sntrup761x25519 is an acceptable interim.",
|
|
898
|
+
};
|
|
834
899
|
|
|
835
900
|
/**
|
|
836
901
|
* Detects classical SSH public keys (`authorized_keys` / `known_hosts` lines)
|
|
@@ -843,8 +908,10 @@ const sshCertDetector: Detector = {
|
|
|
843
908
|
description: "SSH public keys and TLS/X.509 certificate signature algorithms in config",
|
|
844
909
|
scope: "config",
|
|
845
910
|
language: "any",
|
|
846
|
-
rules: [RULE_SSH_PUBKEY, RULE_CERT_SIG_ALG],
|
|
847
|
-
|
|
911
|
+
rules: [RULE_SSH_PUBKEY, RULE_CERT_SIG_ALG, RULE_SSH_KEX],
|
|
912
|
+
// Skip prose/docs: a changelog or README that merely mentions `ssh-rsa` in a
|
|
913
|
+
// sentence is not crypto config. PEM material is caught by its own detector.
|
|
914
|
+
appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
|
|
848
915
|
detect({ file, content }): Finding[] {
|
|
849
916
|
const findings: Finding[] = [];
|
|
850
917
|
|
|
@@ -892,6 +959,89 @@ const sshCertDetector: Detector = {
|
|
|
892
959
|
);
|
|
893
960
|
});
|
|
894
961
|
|
|
962
|
+
// SSH key-exchange algorithm identifiers (finite-field DH / ECDH / X25519).
|
|
963
|
+
eachMatch(RE_SSH_KEX, content, (m) => {
|
|
964
|
+
const tok = m[1];
|
|
965
|
+
const algorithm: Finding["algorithm"] = tok.startsWith("diffie-hellman")
|
|
966
|
+
? "DH"
|
|
967
|
+
: tok.startsWith("ecdh")
|
|
968
|
+
? "ECDH"
|
|
969
|
+
: "X25519";
|
|
970
|
+
findings.push(
|
|
971
|
+
findingFromRule(
|
|
972
|
+
RULE_SSH_KEX,
|
|
973
|
+
{ file, content, index: m.index, matchLength: m[0].length },
|
|
974
|
+
{
|
|
975
|
+
title: `Classical SSH key exchange (${tok})`,
|
|
976
|
+
algorithm,
|
|
977
|
+
message: `SSH key-exchange "${tok}" is classical (${algorithm}) — harvest-now-decrypt-later exposed.`,
|
|
978
|
+
},
|
|
979
|
+
),
|
|
980
|
+
);
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
return findings;
|
|
984
|
+
},
|
|
985
|
+
};
|
|
986
|
+
|
|
987
|
+
/* -------------------------------------------------------------------------- */
|
|
988
|
+
/* Classical TLS key-exchange cipher suites (language-agnostic config) */
|
|
989
|
+
/* -------------------------------------------------------------------------- */
|
|
990
|
+
|
|
991
|
+
// Classical KEX cipher-suite identifiers, in both the OpenSSL (`ECDHE-RSA-…`) and
|
|
992
|
+
// IANA (`TLS_ECDHE_RSA_WITH_…`) spellings, with `-` or `_` separators. These name
|
|
993
|
+
// a Shor-broken key exchange (ECDHE/DHE), so they are the harvest-now surface a
|
|
994
|
+
// PQC scanner should flag — distinct from the legacy-*version* / weak-cipher rules
|
|
995
|
+
// above. Case-sensitive on purpose: cipher-suite tokens are upper-case constants,
|
|
996
|
+
// so prose like "ecdhe rsa" does not misfire. No trailing \b so the IANA
|
|
997
|
+
// `TLS_ECDHE_RSA_WITH_…` form (a `_` follows `RSA`) still matches.
|
|
998
|
+
const RE_TLS_CLASSICAL_KEX = /\b(?:TLS_)?(?:ECDHE|ECDH|DHE)[-_](?:RSA|ECDSA|DSS)/g;
|
|
999
|
+
|
|
1000
|
+
const RULE_TLS_CLASSICAL_KEX: RuleMeta = {
|
|
1001
|
+
id: "tls-classical-kex",
|
|
1002
|
+
title: "Classical TLS key-exchange cipher suite",
|
|
1003
|
+
description: "ECDHE / DHE cipher suites negotiate Shor-broken key exchange",
|
|
1004
|
+
category: "tls",
|
|
1005
|
+
severity: "medium",
|
|
1006
|
+
confidence: "medium",
|
|
1007
|
+
algorithm: "unknown",
|
|
1008
|
+
hndl: true,
|
|
1009
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
1010
|
+
message:
|
|
1011
|
+
"Classical TLS key exchange (ECDHE/DHE) is harvest-now-decrypt-later exposed — the session key can be recorded now and recovered by a quantum attacker.",
|
|
1012
|
+
remediation:
|
|
1013
|
+
"Adopt a PQC-hybrid TLS 1.3 key exchange (e.g. X25519MLKEM768) as your stack and peers support it; keep classical suites only as a transitional fallback.",
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Detects classical TLS key-exchange cipher suites in any text/config file
|
|
1018
|
+
* (OpenSSL cipher lists, IANA suite constants in Go/Java/C#/Rust, `.properties`,
|
|
1019
|
+
* etc.). Language-agnostic because the suite identifiers are the same tokens
|
|
1020
|
+
* everywhere — this is the cross-language TLS gap the legacy-version rule misses.
|
|
1021
|
+
*/
|
|
1022
|
+
const tlsClassicalKexDetector: Detector = {
|
|
1023
|
+
id: "tls-cipher-suite",
|
|
1024
|
+
description: "Classical TLS key-exchange cipher suites (ECDHE/DHE) in any config",
|
|
1025
|
+
scope: "config",
|
|
1026
|
+
language: "any",
|
|
1027
|
+
rules: [RULE_TLS_CLASSICAL_KEX],
|
|
1028
|
+
appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
|
|
1029
|
+
detect({ file, content }): Finding[] {
|
|
1030
|
+
const findings: Finding[] = [];
|
|
1031
|
+
eachMatch(RE_TLS_CLASSICAL_KEX, content, (m) => {
|
|
1032
|
+
const tok = m[0];
|
|
1033
|
+
const algorithm: Finding["algorithm"] = tok.includes("ECDH") ? "ECDH" : "DH";
|
|
1034
|
+
findings.push(
|
|
1035
|
+
findingFromRule(
|
|
1036
|
+
RULE_TLS_CLASSICAL_KEX,
|
|
1037
|
+
{ file, content, index: m.index, matchLength: m[0].length },
|
|
1038
|
+
{
|
|
1039
|
+
algorithm,
|
|
1040
|
+
message: `Classical TLS key-exchange suite "${tok}…" (${algorithm}) is harvest-now-decrypt-later exposed.`,
|
|
1041
|
+
},
|
|
1042
|
+
),
|
|
1043
|
+
);
|
|
1044
|
+
});
|
|
895
1045
|
return findings;
|
|
896
1046
|
},
|
|
897
1047
|
};
|
|
@@ -904,4 +1054,5 @@ export const sourceDetectors: Detector[] = [
|
|
|
904
1054
|
jwtDetector,
|
|
905
1055
|
tlsDetector,
|
|
906
1056
|
sshCertDetector,
|
|
1057
|
+
tlsClassicalKexDetector,
|
|
907
1058
|
];
|