@quantakrypto/core 0.4.2 → 0.4.4
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-merge.d.ts +9 -0
- package/dist/cbom-merge.d.ts.map +1 -0
- package/dist/cbom-merge.js +99 -0
- package/dist/cbom-merge.js.map +1 -0
- 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 +29 -2
- package/dist/comments.d.ts.map +1 -1
- package/dist/comments.js +178 -18
- 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 +138 -2
- package/dist/dependencies.js.map +1 -1
- package/dist/detect-utils.d.ts +19 -4
- package/dist/detect-utils.d.ts.map +1 -1
- package/dist/detect-utils.js +43 -6
- package/dist/detect-utils.js.map +1 -1
- package/dist/detectors/c.d.ts +4 -2
- package/dist/detectors/c.d.ts.map +1 -1
- package/dist/detectors/c.js +382 -3
- package/dist/detectors/c.js.map +1 -1
- package/dist/detectors/cicd.d.ts +27 -0
- package/dist/detectors/cicd.d.ts.map +1 -0
- package/dist/detectors/cicd.js +116 -0
- package/dist/detectors/cicd.js.map +1 -0
- package/dist/detectors/cloud-kms.d.ts +21 -0
- package/dist/detectors/cloud-kms.d.ts.map +1 -0
- package/dist/detectors/cloud-kms.js +57 -0
- package/dist/detectors/cloud-kms.js.map +1 -0
- package/dist/detectors/cloudformation.d.ts +30 -0
- package/dist/detectors/cloudformation.d.ts.map +1 -0
- package/dist/detectors/cloudformation.js +170 -0
- package/dist/detectors/cloudformation.js.map +1 -0
- 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/database.d.ts +17 -0
- package/dist/detectors/database.d.ts.map +1 -0
- package/dist/detectors/database.js +60 -0
- package/dist/detectors/database.js.map +1 -0
- package/dist/detectors/dnssec.d.ts +55 -0
- package/dist/detectors/dnssec.d.ts.map +1 -0
- package/dist/detectors/dnssec.js +107 -0
- package/dist/detectors/dnssec.js.map +1 -0
- package/dist/detectors/elixir.d.ts +20 -0
- package/dist/detectors/elixir.d.ts.map +1 -0
- package/dist/detectors/elixir.js +195 -0
- package/dist/detectors/elixir.js.map +1 -0
- 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 +169 -4
- package/dist/detectors/java.js.map +1 -1
- package/dist/detectors/jose.d.ts +20 -0
- package/dist/detectors/jose.d.ts.map +1 -0
- package/dist/detectors/jose.js +62 -0
- package/dist/detectors/jose.js.map +1 -0
- package/dist/detectors/jwk.d.ts +25 -0
- package/dist/detectors/jwk.d.ts.map +1 -0
- package/dist/detectors/jwk.js +95 -0
- package/dist/detectors/jwk.js.map +1 -0
- package/dist/detectors/k8s.d.ts +17 -0
- package/dist/detectors/k8s.d.ts.map +1 -0
- package/dist/detectors/k8s.js +85 -0
- package/dist/detectors/k8s.js.map +1 -0
- package/dist/detectors/mesh.d.ts +35 -0
- package/dist/detectors/mesh.d.ts.map +1 -0
- package/dist/detectors/mesh.js +109 -0
- package/dist/detectors/mesh.js.map +1 -0
- package/dist/detectors/messaging.d.ts +16 -0
- package/dist/detectors/messaging.d.ts.map +1 -0
- package/dist/detectors/messaging.js +72 -0
- package/dist/detectors/messaging.js.map +1 -0
- package/dist/detectors/pem.d.ts.map +1 -1
- package/dist/detectors/pem.js +50 -2
- package/dist/detectors/pem.js.map +1 -1
- package/dist/detectors/php.d.ts +24 -0
- package/dist/detectors/php.d.ts.map +1 -0
- package/dist/detectors/php.js +167 -0
- package/dist/detectors/php.js.map +1 -0
- package/dist/detectors/python.d.ts.map +1 -1
- package/dist/detectors/python.js +144 -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 +253 -3
- package/dist/detectors/rust.js.map +1 -1
- package/dist/detectors/secrets.d.ts +21 -0
- package/dist/detectors/secrets.d.ts.map +1 -0
- package/dist/detectors/secrets.js +79 -0
- package/dist/detectors/secrets.js.map +1 -0
- package/dist/detectors/source.d.ts.map +1 -1
- package/dist/detectors/source.js +305 -52
- 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 +142 -0
- package/dist/detectors/stateful-hbs.js.map +1 -0
- package/dist/detectors/terraform.d.ts +21 -0
- package/dist/detectors/terraform.d.ts.map +1 -0
- package/dist/detectors/terraform.js +123 -0
- package/dist/detectors/terraform.js.map +1 -0
- package/dist/detectors/vpn.d.ts +22 -0
- package/dist/detectors/vpn.d.ts.map +1 -0
- package/dist/detectors/vpn.js +99 -0
- package/dist/detectors/vpn.js.map +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/evidence.d.ts +53 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +81 -0
- package/dist/evidence.js.map +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -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.map +1 -1
- package/dist/patch-policy.js.map +1 -1
- package/dist/policy.d.ts +67 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +115 -0
- package/dist/policy.js.map +1 -0
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +39 -0
- 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 +34 -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 +71 -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 +17 -5
- 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 +38 -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 +8 -1
- package/dist/scan.js.map +1 -1
- package/dist/severity.js.map +1 -1
- package/dist/standards.d.ts +96 -0
- package/dist/standards.d.ts.map +1 -0
- package/dist/standards.js +107 -0
- package/dist/standards.js.map +1 -0
- package/dist/triage.js.map +1 -1
- package/dist/types.d.ts +2 -2
- 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.js.map +1 -1
- package/package.json +1 -1
- package/src/cbom-merge.ts +116 -0
- package/src/comments.ts +183 -18
- package/src/dependencies.ts +144 -4
- package/src/detect-utils.ts +47 -6
- package/src/detectors/c.ts +411 -5
- package/src/detectors/cicd.ts +158 -0
- package/src/detectors/cloud-kms.ts +87 -0
- package/src/detectors/cloudformation.ts +215 -0
- package/src/detectors/csharp.ts +154 -3
- package/src/detectors/database.ts +88 -0
- package/src/detectors/dnssec.ts +186 -0
- package/src/detectors/elixir.ts +237 -0
- package/src/detectors/go.ts +209 -6
- package/src/detectors/java.ts +191 -4
- package/src/detectors/jose.ts +94 -0
- package/src/detectors/jwk.ts +128 -0
- package/src/detectors/k8s.ts +112 -0
- package/src/detectors/mesh.ts +154 -0
- package/src/detectors/messaging.ts +98 -0
- package/src/detectors/pem.ts +54 -2
- package/src/detectors/php.ts +225 -0
- package/src/detectors/python.ts +153 -3
- package/src/detectors/ruby.ts +138 -7
- package/src/detectors/rust.ts +282 -7
- package/src/detectors/secrets.ts +114 -0
- package/src/detectors/source.ts +382 -72
- package/src/detectors/stateful-hbs.ts +180 -0
- package/src/detectors/terraform.ts +154 -0
- package/src/detectors/vpn.ts +131 -0
- package/src/evidence.ts +135 -0
- package/src/index.ts +15 -1
- package/src/inventory.ts +31 -1
- package/src/policy.ts +180 -0
- package/src/redact.ts +41 -0
- package/src/registry.ts +34 -2
- package/src/remediate-pipeline.ts +78 -0
- package/src/remediation.ts +23 -8
- package/src/report.ts +48 -2
- package/src/scan.ts +13 -1
- package/src/standards.ts +186 -0
- package/src/types.ts +3 -1
- package/src/version.ts +1 -1
package/dist/detectors/python.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PYTHON_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
|
|
2
|
-
import { CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
2
|
+
import { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from "../cwe.js";
|
|
3
3
|
/* -------------------------------------------------------------------------- */
|
|
4
4
|
/* Precompiled regexes (module scope) */
|
|
5
5
|
/* -------------------------------------------------------------------------- */
|
|
@@ -12,8 +12,15 @@ const RE_PY_RSA_ENCRYPT = /\bpadding\.OAEP\s*\(|\bPKCS1_OAEP\.new\s*\(/g;
|
|
|
12
12
|
const RE_PY_EC_KEYGEN = /\bec\.generate_private_key\s*\(|\bECC\.generate\s*\(/g;
|
|
13
13
|
// ECDSA signatures: cryptography `ec.ECDSA(`, paramiko ECDSAKey.
|
|
14
14
|
const RE_PY_ECDSA = /\bec\.ECDSA\s*\(|\bparamiko\.ECDSAKey\b|\bECDSAKey\.generate\s*\(/g;
|
|
15
|
+
// ECDH key agreement: cryptography `ec.ECDH(` — the actual harvest-now event in
|
|
16
|
+
// `private_key.exchange(ec.ECDH(), peer)`; previously missed entirely (audit F3).
|
|
17
|
+
const RE_PY_ECDH = /\bec\.ECDH\s*\(/g;
|
|
15
18
|
// DSA: PyCryptodome `DSA.generate(`, paramiko DSSKey.
|
|
16
19
|
const RE_PY_DSA = /\bDSA\.generate\s*\(|\bparamiko\.DSSKey\b|\bDSSKey\.generate\s*\(/g;
|
|
20
|
+
// hazmat DSA: cryptography `dsa.generate_private_key(` — the `cryptography` DSA
|
|
21
|
+
// keygen path (lowercase module) that RE_PY_DSA's uppercase `DSA.generate` misses
|
|
22
|
+
// (audit F9-python).
|
|
23
|
+
const RE_PY_HAZMAT_DSA = /\bdsa\.generate_private_key\s*\(/g;
|
|
17
24
|
// Finite-field Diffie-Hellman (cryptography `dh`).
|
|
18
25
|
const RE_PY_DH = /\bdh\.generate_parameters\s*\(|\bdh\.DHParameterNumbers\s*\(/g;
|
|
19
26
|
// Modern-but-classical curve primitives (cryptography). `.generate(` anchors so
|
|
@@ -21,6 +28,13 @@ const RE_PY_DH = /\bdh\.generate_parameters\s*\(|\bdh\.DHParameterNumbers\s*\(/g
|
|
|
21
28
|
const RE_PY_X25519 = /\bX25519PrivateKey\.generate\s*\(/g;
|
|
22
29
|
const RE_PY_X448 = /\bX448PrivateKey\.generate\s*\(/g;
|
|
23
30
|
const RE_PY_EDDSA = /\b(?:Ed25519|Ed448)PrivateKey\.generate\s*\(|\bparamiko\.Ed25519Key\b/g;
|
|
31
|
+
// Python TLS misconfiguration. Mirrors the JS `tlsDetector` split of source.ts:
|
|
32
|
+
// certificate-verification bypass (requests `verify=False`, `ssl.CERT_NONE`,
|
|
33
|
+
// `check_hostname=False`, `ssl._create_unverified_context(`) is the high-severity
|
|
34
|
+
// MITM surface (CWE-295); a pinned legacy protocol (`ssl.PROTOCOL_TLSv1`) is the
|
|
35
|
+
// medium-severity weak-strength surface (CWE-326).
|
|
36
|
+
const RE_PY_TLS_REJECT = /\bverify\s*=\s*False\b|\bssl\.CERT_NONE\b|\bcheck_hostname\s*=\s*False\b|\bssl\._create_unverified_context\s*\(/g;
|
|
37
|
+
const RE_PY_TLS_LEGACY = /\bPROTOCOL_TLSv1\b/g;
|
|
24
38
|
/* -------------------------------------------------------------------------- */
|
|
25
39
|
/* Rule catalog */
|
|
26
40
|
/* -------------------------------------------------------------------------- */
|
|
@@ -74,6 +88,18 @@ const RULE_PY_ECDSA = {
|
|
|
74
88
|
message: "Classical ECDSA signing (Python) is forgeable by a quantum attacker.",
|
|
75
89
|
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
76
90
|
};
|
|
91
|
+
const RULE_PY_ECDH = {
|
|
92
|
+
id: "python-ecdh",
|
|
93
|
+
title: "Python ECDH key agreement",
|
|
94
|
+
description: "cryptography ec.ECDH() exchange",
|
|
95
|
+
category: "key-exchange",
|
|
96
|
+
severity: "high",
|
|
97
|
+
confidence: "high",
|
|
98
|
+
algorithm: "ECDH",
|
|
99
|
+
hndl: true,
|
|
100
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
101
|
+
message: "Elliptic-curve Diffie-Hellman key agreement (Python) is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
102
|
+
};
|
|
77
103
|
const RULE_PY_DSA = {
|
|
78
104
|
id: "python-dsa",
|
|
79
105
|
title: "Python DSA key/usage",
|
|
@@ -87,6 +113,19 @@ const RULE_PY_DSA = {
|
|
|
87
113
|
message: "Classical DSA (Python) is deprecated and forgeable by a quantum attacker.",
|
|
88
114
|
remediation: "Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).",
|
|
89
115
|
};
|
|
116
|
+
const RULE_PY_HAZMAT_DSA = {
|
|
117
|
+
id: "python-hazmat-dsa",
|
|
118
|
+
title: "Python DSA key generation (cryptography)",
|
|
119
|
+
description: "cryptography dsa.generate_private_key",
|
|
120
|
+
category: "signature",
|
|
121
|
+
severity: "high",
|
|
122
|
+
confidence: "high",
|
|
123
|
+
algorithm: "DSA",
|
|
124
|
+
hndl: false,
|
|
125
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
126
|
+
message: "cryptography dsa.generate_private_key (Python) creates a classical DSA key; DSA is deprecated and forgeable by a quantum attacker.",
|
|
127
|
+
remediation: "Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).",
|
|
128
|
+
};
|
|
90
129
|
const RULE_PY_DH = {
|
|
91
130
|
id: "python-dh",
|
|
92
131
|
title: "Python Diffie-Hellman key exchange",
|
|
@@ -104,7 +143,7 @@ const RULE_PY_X25519 = {
|
|
|
104
143
|
title: "Python X25519 key exchange",
|
|
105
144
|
description: "cryptography X25519PrivateKey.generate",
|
|
106
145
|
category: "key-exchange",
|
|
107
|
-
severity: "
|
|
146
|
+
severity: "medium",
|
|
108
147
|
confidence: "high",
|
|
109
148
|
algorithm: "X25519",
|
|
110
149
|
hndl: true,
|
|
@@ -116,7 +155,7 @@ const RULE_PY_X448 = {
|
|
|
116
155
|
title: "Python X448 key exchange",
|
|
117
156
|
description: "cryptography X448PrivateKey.generate",
|
|
118
157
|
category: "key-exchange",
|
|
119
|
-
severity: "
|
|
158
|
+
severity: "medium",
|
|
120
159
|
confidence: "high",
|
|
121
160
|
algorithm: "X448",
|
|
122
161
|
hndl: true,
|
|
@@ -135,6 +174,87 @@ const RULE_PY_EDDSA = {
|
|
|
135
174
|
cwe: CWE_BROKEN_CRYPTO,
|
|
136
175
|
message: "Ed25519/Ed448 (Python) is a modern but still classical signature scheme.",
|
|
137
176
|
};
|
|
177
|
+
const RULE_PY_TLS_REJECT = {
|
|
178
|
+
id: "python-tls-reject",
|
|
179
|
+
title: "Python TLS certificate verification disabled",
|
|
180
|
+
description: "requests verify=False / ssl.CERT_NONE / check_hostname=False / _create_unverified_context",
|
|
181
|
+
category: "tls",
|
|
182
|
+
severity: "high",
|
|
183
|
+
confidence: "high",
|
|
184
|
+
hndl: false,
|
|
185
|
+
cwe: CWE_CERT_VALIDATION,
|
|
186
|
+
message: "TLS certificate verification is disabled (verify=False / CERT_NONE / check_hostname=False / _create_unverified_context), which allows man-in-the-middle attacks.",
|
|
187
|
+
remediation: "Enable certificate verification (verify=True, ssl.CERT_REQUIRED, check_hostname=True) and verify certificates properly.",
|
|
188
|
+
};
|
|
189
|
+
const RULE_PY_TLS_LEGACY = {
|
|
190
|
+
id: "python-tls-legacy-version",
|
|
191
|
+
title: "Python legacy TLS version pinned",
|
|
192
|
+
description: "ssl.PROTOCOL_TLSv1 (TLS 1.0)",
|
|
193
|
+
category: "tls",
|
|
194
|
+
severity: "medium",
|
|
195
|
+
confidence: "high",
|
|
196
|
+
hndl: false,
|
|
197
|
+
cwe: CWE_WEAK_STRENGTH,
|
|
198
|
+
message: "TLS 1.0 (ssl.PROTOCOL_TLSv1) is deprecated and insecure; require TLS 1.3.",
|
|
199
|
+
remediation: "Use ssl.PROTOCOL_TLS_CLIENT with minimum_version = ssl.TLSVersion.TLSv1_3 and prefer PQC-hybrid key exchange.",
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Aliasable `cryptography` / PyCryptodome modules → the (method, rule) pairs
|
|
203
|
+
* reachable through them. Lets an aliased module import
|
|
204
|
+
* (`from ... import rsa as _rsa` → `_rsa.generate_private_key(`) resolve back to
|
|
205
|
+
* the same rule the direct `rsa.generate_private_key(` would fire, since the
|
|
206
|
+
* detector's regexes are module-qualified and miss a renamed prefix.
|
|
207
|
+
*/
|
|
208
|
+
const PY_MODULE_RULES = {
|
|
209
|
+
rsa: [{ method: "generate_private_key", rule: RULE_PY_RSA_KEYGEN }],
|
|
210
|
+
ec: [
|
|
211
|
+
{ method: "generate_private_key", rule: RULE_PY_EC_KEYGEN },
|
|
212
|
+
{ method: "ECDSA", rule: RULE_PY_ECDSA },
|
|
213
|
+
{ method: "ECDH", rule: RULE_PY_ECDH },
|
|
214
|
+
],
|
|
215
|
+
dsa: [{ method: "generate_private_key", rule: RULE_PY_HAZMAT_DSA }],
|
|
216
|
+
dh: [{ method: "generate_parameters", rule: RULE_PY_DH }],
|
|
217
|
+
padding: [{ method: "OAEP", rule: RULE_PY_RSA_ENCRYPT }],
|
|
218
|
+
// PyCryptodome factory modules (`.generate(`).
|
|
219
|
+
RSA: [{ method: "generate", rule: RULE_PY_RSA_KEYGEN }],
|
|
220
|
+
ECC: [{ method: "generate", rule: RULE_PY_EC_KEYGEN }],
|
|
221
|
+
DSA: [{ method: "generate", rule: RULE_PY_DSA }],
|
|
222
|
+
};
|
|
223
|
+
/** Escape a string for interpolation into a dynamically-built RegExp. */
|
|
224
|
+
function escapePyRe(s) {
|
|
225
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Collect module aliases for the aliasable crypto modules, so a later
|
|
229
|
+
* `<alias>.<method>(` call still resolves. Handles both `from <path> import
|
|
230
|
+
* <mod> as <alias>` (including comma-separated specifiers) and the bare
|
|
231
|
+
* `import <path.mod> as <alias>`. Returns Map<module, alias[]>; an alias equal to
|
|
232
|
+
* its own module name is skipped (matched directly already).
|
|
233
|
+
*/
|
|
234
|
+
function collectPyModuleAliases(content) {
|
|
235
|
+
const out = new Map();
|
|
236
|
+
const add = (mod, alias) => {
|
|
237
|
+
if (!alias || alias === mod || !(mod in PY_MODULE_RULES))
|
|
238
|
+
return;
|
|
239
|
+
const list = out.get(mod) ?? [];
|
|
240
|
+
if (!list.includes(alias))
|
|
241
|
+
list.push(alias);
|
|
242
|
+
out.set(mod, list);
|
|
243
|
+
};
|
|
244
|
+
// `from <path> import a as b, c as d` — scan the import list for `X as Y`.
|
|
245
|
+
const fromRe = /(?:^|\n)[ \t]*from\s+[\w.]+\s+import\s+([^\n#]+)/g;
|
|
246
|
+
for (let m = fromRe.exec(content); m; m = fromRe.exec(content)) {
|
|
247
|
+
const specRe = /([A-Za-z_]\w*)\s+as\s+([A-Za-z_]\w*)/g;
|
|
248
|
+
for (let s = specRe.exec(m[1]); s; s = specRe.exec(m[1]))
|
|
249
|
+
add(s[1], s[2]);
|
|
250
|
+
}
|
|
251
|
+
// `import <path.mod> as <alias>` — the aliased module is the last dotted segment.
|
|
252
|
+
const impRe = /(?:^|\n)[ \t]*import\s+([\w.]+)\s+as\s+([A-Za-z_]\w*)/g;
|
|
253
|
+
for (let m = impRe.exec(content); m; m = impRe.exec(content)) {
|
|
254
|
+
add(m[1].split(".").pop() ?? m[1], m[2]);
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
138
258
|
/** Detects classical asymmetric crypto in Python source. */
|
|
139
259
|
export const pythonDetector = {
|
|
140
260
|
id: "python-crypto",
|
|
@@ -146,11 +266,15 @@ export const pythonDetector = {
|
|
|
146
266
|
RULE_PY_RSA_ENCRYPT,
|
|
147
267
|
RULE_PY_EC_KEYGEN,
|
|
148
268
|
RULE_PY_ECDSA,
|
|
269
|
+
RULE_PY_ECDH,
|
|
149
270
|
RULE_PY_DSA,
|
|
271
|
+
RULE_PY_HAZMAT_DSA,
|
|
150
272
|
RULE_PY_DH,
|
|
151
273
|
RULE_PY_X25519,
|
|
152
274
|
RULE_PY_X448,
|
|
153
275
|
RULE_PY_EDDSA,
|
|
276
|
+
RULE_PY_TLS_REJECT,
|
|
277
|
+
RULE_PY_TLS_LEGACY,
|
|
154
278
|
],
|
|
155
279
|
appliesTo: (f) => hasExtension(f, PYTHON_EXTENSIONS),
|
|
156
280
|
detect({ file, content }) {
|
|
@@ -160,11 +284,28 @@ export const pythonDetector = {
|
|
|
160
284
|
add(RE_PY_RSA_ENCRYPT, RULE_PY_RSA_ENCRYPT);
|
|
161
285
|
add(RE_PY_EC_KEYGEN, RULE_PY_EC_KEYGEN);
|
|
162
286
|
add(RE_PY_ECDSA, RULE_PY_ECDSA);
|
|
287
|
+
add(RE_PY_ECDH, RULE_PY_ECDH);
|
|
163
288
|
add(RE_PY_DSA, RULE_PY_DSA);
|
|
289
|
+
add(RE_PY_HAZMAT_DSA, RULE_PY_HAZMAT_DSA);
|
|
164
290
|
add(RE_PY_DH, RULE_PY_DH);
|
|
165
291
|
add(RE_PY_X25519, RULE_PY_X25519);
|
|
166
292
|
add(RE_PY_X448, RULE_PY_X448);
|
|
167
293
|
add(RE_PY_EDDSA, RULE_PY_EDDSA);
|
|
294
|
+
add(RE_PY_TLS_REJECT, RULE_PY_TLS_REJECT);
|
|
295
|
+
add(RE_PY_TLS_LEGACY, RULE_PY_TLS_LEGACY);
|
|
296
|
+
// Module-alias resolution: `from ... import rsa as _rsa` then
|
|
297
|
+
// `_rsa.generate_private_key(` — the direct regexes are module-qualified
|
|
298
|
+
// (`\brsa\.`) and miss a renamed prefix. Runs on the ORIGINAL content so
|
|
299
|
+
// locations stay exact; fires only for an alias explicitly bound to a known
|
|
300
|
+
// crypto module, so precision is unaffected.
|
|
301
|
+
for (const [mod, aliasList] of collectPyModuleAliases(content)) {
|
|
302
|
+
for (const alias of aliasList) {
|
|
303
|
+
const a = escapePyRe(alias);
|
|
304
|
+
for (const { method, rule } of PY_MODULE_RULES[mod]) {
|
|
305
|
+
add(new RegExp(`\\b${a}\\.${method}\\s*\\(`, "g"), rule);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
168
309
|
return findings;
|
|
169
310
|
},
|
|
170
311
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.js","sourceRoot":"","sources":["../../src/detectors/python.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBA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AC;QAE1C,8DAA8D;QAC9D,yEAAyE;QACzE,yEAAyE;QACzE,4EAA4E;QAC5E,6CAA6C;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/D,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;gBAC9B,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;gBAC5B,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;oBACpD,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,MAAM,SAAS,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical, non-quantum-safe asymmetric cryptography\n * in Python. Same lexical (regex-over-source) strategy as the JS/TS detectors:\n * robust to formatting, dependency-free, and confidence-tagged per pattern.\n *\n * Covers the three libraries that carry ~all real-world Python asymmetric\n * crypto:\n * - `cryptography` (hazmat): rsa/ec/dh/x25519/x448/ed25519/ed448 + OAEP padding\n * - PyCryptodome (`Crypto.PublicKey`): RSA/ECC/DSA generate + PKCS1_OAEP\n * - paramiko (SSH): RSAKey / ECDSAKey / Ed25519Key / DSSKey\n *\n * JWT/JOSE algorithm strings (`algorithm=\"RS256\"`) are NOT handled here — the\n * language-agnostic `jwt-jose` detector now applies to Python too (a quoted\n * `\"RS256\"` is the same evidence in any language).\n *\n * HNDL policy mirrors the JS detectors: key agreement / KEM (RSA-OAEP, ECDH, DH,\n * X25519/X448) is harvest-now-decrypt-later exposed (hndl:true); signatures\n * (ECDSA, DSA, Ed25519/Ed448) are hndl:false but still high/low severity because\n * a quantum attacker can forge them. EC key generation is ambiguous (an EC key\n * feeds both ECDSA and ECDH), so it is classified conservatively as\n * key-exchange-capable (hndl:true), exactly as the Node `ec` keygen rule is.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { PYTHON_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\n/* -------------------------------------------------------------------------- */\n/* Precompiled regexes (module scope) */\n/* -------------------------------------------------------------------------- */\n\n// RSA key generation: cryptography `rsa.generate_private_key(`, PyCryptodome\n// `RSA.generate(`, paramiko `paramiko.RSAKey` / `RSAKey.generate(`.\nconst RE_PY_RSA_KEYGEN =\n /\\brsa\\.generate_private_key\\s*\\(|\\bRSA\\.generate\\s*\\(|\\bparamiko\\.RSAKey\\b|\\bRSAKey\\.generate\\s*\\(/g;\n// RSA public-key encryption padding (RSA-OAEP): confidentiality → HNDL.\nconst RE_PY_RSA_ENCRYPT = /\\bpadding\\.OAEP\\s*\\(|\\bPKCS1_OAEP\\.new\\s*\\(/g;\n// EC key generation (ambiguous ECDSA/ECDH): cryptography + PyCryptodome.\nconst RE_PY_EC_KEYGEN = /\\bec\\.generate_private_key\\s*\\(|\\bECC\\.generate\\s*\\(/g;\n// ECDSA signatures: cryptography `ec.ECDSA(`, paramiko ECDSAKey.\nconst RE_PY_ECDSA = /\\bec\\.ECDSA\\s*\\(|\\bparamiko\\.ECDSAKey\\b|\\bECDSAKey\\.generate\\s*\\(/g;\n// ECDH key agreement: cryptography `ec.ECDH(` — the actual harvest-now event in\n// `private_key.exchange(ec.ECDH(), peer)`; previously missed entirely (audit F3).\nconst RE_PY_ECDH = /\\bec\\.ECDH\\s*\\(/g;\n// DSA: PyCryptodome `DSA.generate(`, paramiko DSSKey.\nconst RE_PY_DSA = /\\bDSA\\.generate\\s*\\(|\\bparamiko\\.DSSKey\\b|\\bDSSKey\\.generate\\s*\\(/g;\n// hazmat DSA: cryptography `dsa.generate_private_key(` — the `cryptography` DSA\n// keygen path (lowercase module) that RE_PY_DSA's uppercase `DSA.generate` misses\n// (audit F9-python).\nconst RE_PY_HAZMAT_DSA = /\\bdsa\\.generate_private_key\\s*\\(/g;\n// Finite-field Diffie-Hellman (cryptography `dh`).\nconst RE_PY_DH = /\\bdh\\.generate_parameters\\s*\\(|\\bdh\\.DHParameterNumbers\\s*\\(/g;\n// Modern-but-classical curve primitives (cryptography). `.generate(` anchors so\n// a bare import of the class name does not fire.\nconst RE_PY_X25519 = /\\bX25519PrivateKey\\.generate\\s*\\(/g;\nconst RE_PY_X448 = /\\bX448PrivateKey\\.generate\\s*\\(/g;\nconst RE_PY_EDDSA = /\\b(?:Ed25519|Ed448)PrivateKey\\.generate\\s*\\(|\\bparamiko\\.Ed25519Key\\b/g;\n\n// Python TLS misconfiguration. Mirrors the JS `tlsDetector` split of source.ts:\n// certificate-verification bypass (requests `verify=False`, `ssl.CERT_NONE`,\n// `check_hostname=False`, `ssl._create_unverified_context(`) is the high-severity\n// MITM surface (CWE-295); a pinned legacy protocol (`ssl.PROTOCOL_TLSv1`) is the\n// medium-severity weak-strength surface (CWE-326).\nconst RE_PY_TLS_REJECT =\n /\\bverify\\s*=\\s*False\\b|\\bssl\\.CERT_NONE\\b|\\bcheck_hostname\\s*=\\s*False\\b|\\bssl\\._create_unverified_context\\s*\\(/g;\nconst RE_PY_TLS_LEGACY = /\\bPROTOCOL_TLSv1\\b/g;\n\n/* -------------------------------------------------------------------------- */\n/* Rule catalog */\n/* -------------------------------------------------------------------------- */\n\nconst RULE_PY_RSA_KEYGEN: RuleMeta = {\n id: \"python-rsa-keygen\",\n title: \"Python RSA key generation\",\n description:\n \"cryptography rsa.generate_private_key / PyCryptodome RSA.generate / paramiko RSAKey\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Generates a classical RSA key pair (Python), which is not quantum-safe.\",\n};\nconst RULE_PY_RSA_ENCRYPT: RuleMeta = {\n id: \"python-rsa-encrypt\",\n title: \"Python RSA public-key encryption\",\n description: \"RSA-OAEP / PKCS1_OAEP encryption padding\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"RSA public-key encryption (OAEP) is broken by Shor's algorithm and exposed to harvest-now-decrypt-later.\",\n};\nconst RULE_PY_EC_KEYGEN: RuleMeta = {\n id: \"python-ec-keygen\",\n title: \"Python EC key generation\",\n description: \"cryptography ec.generate_private_key / PyCryptodome ECC.generate\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates a classical EC key pair (Python). EC keys feed BOTH ECDSA signatures and ECDH key agreement; the ECDH path is harvest-now-decrypt-later exposed.\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_PY_ECDSA: RuleMeta = {\n id: \"python-ecdsa\",\n title: \"Python ECDSA signature\",\n description: \"cryptography ec.ECDSA / paramiko ECDSAKey\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"medium\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical ECDSA signing (Python) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_PY_ECDH: RuleMeta = {\n id: \"python-ecdh\",\n title: \"Python ECDH key agreement\",\n description: \"cryptography ec.ECDH() exchange\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Elliptic-curve Diffie-Hellman key agreement (Python) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_PY_DSA: RuleMeta = {\n id: \"python-dsa\",\n title: \"Python DSA key/usage\",\n description: \"PyCryptodome DSA.generate / paramiko DSSKey\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (Python) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_PY_HAZMAT_DSA: RuleMeta = {\n id: \"python-hazmat-dsa\",\n title: \"Python DSA key generation (cryptography)\",\n description: \"cryptography dsa.generate_private_key\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"cryptography dsa.generate_private_key (Python) creates a classical DSA key; DSA is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_PY_DH: RuleMeta = {\n id: \"python-dh\",\n title: \"Python Diffie-Hellman key exchange\",\n description: \"cryptography dh.generate_parameters / DHParameterNumbers\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Finite-field Diffie-Hellman (Python) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_PY_X25519: RuleMeta = {\n id: \"python-x25519\",\n title: \"Python X25519 key exchange\",\n description: \"cryptography X25519PrivateKey.generate\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519 (Python) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_PY_X448: RuleMeta = {\n id: \"python-x448\",\n title: \"Python X448 key exchange\",\n description: \"cryptography X448PrivateKey.generate\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X448\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"X448 (Python) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_PY_EDDSA: RuleMeta = {\n id: \"python-eddsa\",\n title: \"Python Ed25519/Ed448 signature\",\n description: \"cryptography Ed25519/Ed448 PrivateKey.generate / paramiko Ed25519Key\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Ed25519/Ed448 (Python) is a modern but still classical signature scheme.\",\n};\nconst RULE_PY_TLS_REJECT: RuleMeta = {\n id: \"python-tls-reject\",\n title: \"Python TLS certificate verification disabled\",\n description:\n \"requests verify=False / ssl.CERT_NONE / check_hostname=False / _create_unverified_context\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message:\n \"TLS certificate verification is disabled (verify=False / CERT_NONE / check_hostname=False / _create_unverified_context), which allows man-in-the-middle attacks.\",\n remediation:\n \"Enable certificate verification (verify=True, ssl.CERT_REQUIRED, check_hostname=True) and verify certificates properly.\",\n};\nconst RULE_PY_TLS_LEGACY: RuleMeta = {\n id: \"python-tls-legacy-version\",\n title: \"Python legacy TLS version pinned\",\n description: \"ssl.PROTOCOL_TLSv1 (TLS 1.0)\",\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"TLS 1.0 (ssl.PROTOCOL_TLSv1) is deprecated and insecure; require TLS 1.3.\",\n remediation:\n \"Use ssl.PROTOCOL_TLS_CLIENT with minimum_version = ssl.TLSVersion.TLSv1_3 and prefer PQC-hybrid key exchange.\",\n};\n\n/**\n * Aliasable `cryptography` / PyCryptodome modules → the (method, rule) pairs\n * reachable through them. Lets an aliased module import\n * (`from ... import rsa as _rsa` → `_rsa.generate_private_key(`) resolve back to\n * the same rule the direct `rsa.generate_private_key(` would fire, since the\n * detector's regexes are module-qualified and miss a renamed prefix.\n */\nconst PY_MODULE_RULES: Record<string, ReadonlyArray<{ method: string; rule: RuleMeta }>> = {\n rsa: [{ method: \"generate_private_key\", rule: RULE_PY_RSA_KEYGEN }],\n ec: [\n { method: \"generate_private_key\", rule: RULE_PY_EC_KEYGEN },\n { method: \"ECDSA\", rule: RULE_PY_ECDSA },\n { method: \"ECDH\", rule: RULE_PY_ECDH },\n ],\n dsa: [{ method: \"generate_private_key\", rule: RULE_PY_HAZMAT_DSA }],\n dh: [{ method: \"generate_parameters\", rule: RULE_PY_DH }],\n padding: [{ method: \"OAEP\", rule: RULE_PY_RSA_ENCRYPT }],\n // PyCryptodome factory modules (`.generate(`).\n RSA: [{ method: \"generate\", rule: RULE_PY_RSA_KEYGEN }],\n ECC: [{ method: \"generate\", rule: RULE_PY_EC_KEYGEN }],\n DSA: [{ method: \"generate\", rule: RULE_PY_DSA }],\n};\n\n/** Escape a string for interpolation into a dynamically-built RegExp. */\nfunction escapePyRe(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Collect module aliases for the aliasable crypto modules, so a later\n * `<alias>.<method>(` call still resolves. Handles both `from <path> import\n * <mod> as <alias>` (including comma-separated specifiers) and the bare\n * `import <path.mod> as <alias>`. Returns Map<module, alias[]>; an alias equal to\n * its own module name is skipped (matched directly already).\n */\nfunction collectPyModuleAliases(content: string): Map<string, string[]> {\n const out = new Map<string, string[]>();\n const add = (mod: string, alias: string): void => {\n if (!alias || alias === mod || !(mod in PY_MODULE_RULES)) return;\n const list = out.get(mod) ?? [];\n if (!list.includes(alias)) list.push(alias);\n out.set(mod, list);\n };\n // `from <path> import a as b, c as d` — scan the import list for `X as Y`.\n const fromRe = /(?:^|\\n)[ \\t]*from\\s+[\\w.]+\\s+import\\s+([^\\n#]+)/g;\n for (let m = fromRe.exec(content); m; m = fromRe.exec(content)) {\n const specRe = /([A-Za-z_]\\w*)\\s+as\\s+([A-Za-z_]\\w*)/g;\n for (let s = specRe.exec(m[1]); s; s = specRe.exec(m[1])) add(s[1], s[2]);\n }\n // `import <path.mod> as <alias>` — the aliased module is the last dotted segment.\n const impRe = /(?:^|\\n)[ \\t]*import\\s+([\\w.]+)\\s+as\\s+([A-Za-z_]\\w*)/g;\n for (let m = impRe.exec(content); m; m = impRe.exec(content)) {\n add(m[1].split(\".\").pop() ?? m[1], m[2]);\n }\n return out;\n}\n\n/** Detects classical asymmetric crypto in Python source. */\nexport const pythonDetector: Detector = {\n id: \"python-crypto\",\n description: \"Classical asymmetric crypto in Python (cryptography, PyCryptodome, paramiko)\",\n scope: \"source\",\n language: \"python\",\n rules: [\n RULE_PY_RSA_KEYGEN,\n RULE_PY_RSA_ENCRYPT,\n RULE_PY_EC_KEYGEN,\n RULE_PY_ECDSA,\n RULE_PY_ECDH,\n RULE_PY_DSA,\n RULE_PY_HAZMAT_DSA,\n RULE_PY_DH,\n RULE_PY_X25519,\n RULE_PY_X448,\n RULE_PY_EDDSA,\n RULE_PY_TLS_REJECT,\n RULE_PY_TLS_LEGACY,\n ],\n appliesTo: (f) => hasExtension(f, PYTHON_EXTENSIONS),\n detect({ file, content }): Finding[] {\n const findings: Finding[] = [];\n const add = (re: RegExp, rule: RuleMeta) =>\n eachMatch(re, content, (m) =>\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n ),\n );\n\n add(RE_PY_RSA_KEYGEN, RULE_PY_RSA_KEYGEN);\n add(RE_PY_RSA_ENCRYPT, RULE_PY_RSA_ENCRYPT);\n add(RE_PY_EC_KEYGEN, RULE_PY_EC_KEYGEN);\n add(RE_PY_ECDSA, RULE_PY_ECDSA);\n add(RE_PY_ECDH, RULE_PY_ECDH);\n add(RE_PY_DSA, RULE_PY_DSA);\n add(RE_PY_HAZMAT_DSA, RULE_PY_HAZMAT_DSA);\n add(RE_PY_DH, RULE_PY_DH);\n add(RE_PY_X25519, RULE_PY_X25519);\n add(RE_PY_X448, RULE_PY_X448);\n add(RE_PY_EDDSA, RULE_PY_EDDSA);\n add(RE_PY_TLS_REJECT, RULE_PY_TLS_REJECT);\n add(RE_PY_TLS_LEGACY, RULE_PY_TLS_LEGACY);\n\n // Module-alias resolution: `from ... import rsa as _rsa` then\n // `_rsa.generate_private_key(` — the direct regexes are module-qualified\n // (`\\brsa\\.`) and miss a renamed prefix. Runs on the ORIGINAL content so\n // locations stay exact; fires only for an alias explicitly bound to a known\n // crypto module, so precision is unaffected.\n for (const [mod, aliasList] of collectPyModuleAliases(content)) {\n for (const alias of aliasList) {\n const a = escapePyRe(alias);\n for (const { method, rule } of PY_MODULE_RULES[mod]) {\n add(new RegExp(`\\\\b${a}\\\\.${method}\\\\s*\\\\(`, \"g\"), rule);\n }\n }\n }\n\n return findings;\n },\n};\n"]}
|
package/dist/detectors/ruby.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Source-code detector for classical asymmetric cryptography in Ruby. Ruby's
|
|
3
3
|
* asymmetric crypto is almost entirely `OpenSSL::PKey::{RSA,EC,DSA,DH}`, which
|
|
4
|
-
* makes the signals precise. Lexical, same strategy as the other packs.
|
|
4
|
+
* makes the signals precise. Lexical, same strategy as the other packs. Beyond
|
|
5
|
+
* keygen it also covers RSA public-key encryption on a loaded key, DH key
|
|
6
|
+
* agreement, the type-agnostic `OpenSSL::PKey.read` loader, Ed25519 key
|
|
7
|
+
* generation, and disabled TLS peer verification (`VERIFY_NONE`).
|
|
5
8
|
*
|
|
6
9
|
* HNDL: RSA (keygen/encryption) and (EC)DH key agreement are harvest-now-
|
|
7
|
-
* decrypt-later exposed (hndl:true); DSA signatures are hndl:false but
|
|
8
|
-
* `OpenSSL::PKey::EC` is ambiguous (feeds ECDSA + ECDH), so it is
|
|
9
|
-
* conservatively as key-exchange-capable (hndl:true), like the other
|
|
10
|
-
* rules.
|
|
10
|
+
* decrypt-later exposed (hndl:true); DSA / Ed25519 signatures are hndl:false but
|
|
11
|
+
* forgeable. `OpenSSL::PKey::EC` is ambiguous (feeds ECDSA + ECDH), so it is
|
|
12
|
+
* classified conservatively as key-exchange-capable (hndl:true), like the other
|
|
13
|
+
* EC keygen rules; `OpenSSL::PKey.read` loads a key of unknown type and is
|
|
14
|
+
* likewise treated conservatively.
|
|
11
15
|
*/
|
|
12
16
|
import type { Detector } from "../types.js";
|
|
13
17
|
/** Detects classical asymmetric crypto in Ruby (OpenSSL::PKey). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruby.d.ts","sourceRoot":"","sources":["../../src/detectors/ruby.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ruby.d.ts","sourceRoot":"","sources":["../../src/detectors/ruby.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AA2K/D,mEAAmE;AACnE,eAAO,MAAM,YAAY,EAAE,QAwC1B,CAAC"}
|
package/dist/detectors/ruby.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { RUBY_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
|
|
2
|
-
import { CWE_BROKEN_CRYPTO } from "../cwe.js";
|
|
2
|
+
import { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION } from "../cwe.js";
|
|
3
3
|
const RE_RB_RSA = /\bOpenSSL::PKey::RSA\.(?:new|generate)\s*\(/g;
|
|
4
4
|
const RE_RB_EC = /\bOpenSSL::PKey::EC\.(?:new|generate)\s*\(/g;
|
|
5
5
|
const RE_RB_DSA = /\bOpenSSL::PKey::DSA\.(?:new|generate)\s*\(/g;
|
|
6
6
|
const RE_RB_DH = /\bOpenSSL::PKey::DH\.new\s*\(/g;
|
|
7
|
+
// RSA public-key encryption on an already-loaded key (audit F4-ruby / F9).
|
|
8
|
+
const RE_RB_RSA_CRYPT = /\.public_encrypt\b|\.private_decrypt\b/g;
|
|
9
|
+
// Finite-field DH shared-secret agreement.
|
|
10
|
+
const RE_RB_DH_AGREE = /\bdh_compute_key\s*\(/g;
|
|
11
|
+
// Type-agnostic key loader — could be RSA/EC/DSA/DH (conservative).
|
|
12
|
+
const RE_RB_PKEY_READ = /\bOpenSSL::PKey\.read\s*\(/g;
|
|
13
|
+
// Ed25519 signing key via the generic generate_key factory.
|
|
14
|
+
const RE_RB_ED25519 = /\bOpenSSL::PKey\.generate_key\s*\(\s*["']ED25519["']/g;
|
|
15
|
+
// `ed25519` gem — Ed25519::SigningKey / VerifyKey (signature keys).
|
|
16
|
+
const RE_RB_ED25519_GEM = /\bEd25519::(?:SigningKey|VerifyKey)\b/g;
|
|
17
|
+
// `rbnacl` (libsodium) — Curve25519/X25519 key agreement: PrivateKey, Box, GroupElement.
|
|
18
|
+
const RE_RB_RBNACL = /\bRbNaCl::(?:PrivateKey|Box|GroupElement)\b/g;
|
|
19
|
+
// TLS peer verification disabled (mirrors the JS tlsDetector rejectUnauthorized rule).
|
|
20
|
+
const RE_RB_TLS_VERIFY_NONE = /\bOpenSSL::SSL::VERIFY_NONE\b/g;
|
|
7
21
|
const RULE_RB_RSA = {
|
|
8
22
|
id: "ruby-rsa",
|
|
9
23
|
title: "Ruby RSA key/usage",
|
|
@@ -54,13 +68,112 @@ const RULE_RB_DH = {
|
|
|
54
68
|
cwe: CWE_BROKEN_CRYPTO,
|
|
55
69
|
message: "Finite-field Diffie-Hellman (Ruby/OpenSSL) is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
56
70
|
};
|
|
71
|
+
const RULE_RB_RSA_CRYPT = {
|
|
72
|
+
id: "ruby-rsa-crypt",
|
|
73
|
+
title: "Ruby RSA public-key encryption",
|
|
74
|
+
description: "OpenSSL::PKey::RSA#public_encrypt / #private_decrypt",
|
|
75
|
+
category: "kem",
|
|
76
|
+
severity: "high",
|
|
77
|
+
confidence: "high",
|
|
78
|
+
algorithm: "RSA",
|
|
79
|
+
hndl: true,
|
|
80
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
81
|
+
message: "RSA public-key encryption/decryption (Ruby/OpenSSL) is harvest-now-decrypt-later exposed.",
|
|
82
|
+
};
|
|
83
|
+
const RULE_RB_DH_AGREE = {
|
|
84
|
+
id: "ruby-dh-agree",
|
|
85
|
+
title: "Ruby Diffie-Hellman key agreement",
|
|
86
|
+
description: "OpenSSL DH compute_key shared-secret agreement",
|
|
87
|
+
category: "key-exchange",
|
|
88
|
+
severity: "high",
|
|
89
|
+
confidence: "high",
|
|
90
|
+
algorithm: "DH",
|
|
91
|
+
hndl: true,
|
|
92
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
93
|
+
message: "Finite-field Diffie-Hellman key agreement (Ruby/OpenSSL) is broken by Shor's algorithm (harvest-now-decrypt-later).",
|
|
94
|
+
};
|
|
95
|
+
const RULE_RB_PKEY_READ = {
|
|
96
|
+
id: "ruby-pkey-read",
|
|
97
|
+
title: "Ruby PKey loaded from serialized key",
|
|
98
|
+
description: "OpenSSL::PKey.read (type-agnostic key loader)",
|
|
99
|
+
category: "key-exchange",
|
|
100
|
+
severity: "high",
|
|
101
|
+
confidence: "medium",
|
|
102
|
+
algorithm: "unknown",
|
|
103
|
+
hndl: true,
|
|
104
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
105
|
+
message: "Loads a classical asymmetric key of unknown type (RSA/EC/DSA/DH) via OpenSSL::PKey.read. Treated conservatively as key-exchange-capable (harvest-now-decrypt-later).",
|
|
106
|
+
remediation: "For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
|
|
107
|
+
};
|
|
108
|
+
const RULE_RB_ED25519 = {
|
|
109
|
+
id: "ruby-ed25519",
|
|
110
|
+
title: "Ruby Ed25519 key generation",
|
|
111
|
+
description: 'OpenSSL::PKey.generate_key("ED25519")',
|
|
112
|
+
category: "signature",
|
|
113
|
+
severity: "low",
|
|
114
|
+
confidence: "high",
|
|
115
|
+
algorithm: "EdDSA",
|
|
116
|
+
hndl: false,
|
|
117
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
118
|
+
message: "Generates an Ed25519 signing key (Ruby/OpenSSL) — modern but classical, and forgeable by a quantum attacker.",
|
|
119
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
120
|
+
};
|
|
121
|
+
const RULE_RB_ED25519_GEM = {
|
|
122
|
+
id: "ruby-ed25519-gem",
|
|
123
|
+
title: "Ruby Ed25519 signature (ed25519 gem)",
|
|
124
|
+
description: "ed25519 gem Ed25519::SigningKey / Ed25519::VerifyKey",
|
|
125
|
+
category: "signature",
|
|
126
|
+
severity: "low",
|
|
127
|
+
confidence: "high",
|
|
128
|
+
algorithm: "EdDSA",
|
|
129
|
+
hndl: false,
|
|
130
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
131
|
+
message: "Ed25519 signing/verification via the `ed25519` gem — modern but classical, and forgeable by a quantum attacker.",
|
|
132
|
+
remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
|
|
133
|
+
};
|
|
134
|
+
const RULE_RB_RBNACL = {
|
|
135
|
+
id: "ruby-rbnacl",
|
|
136
|
+
title: "Ruby X25519 key agreement (rbnacl)",
|
|
137
|
+
description: "rbnacl (libsodium) RbNaCl::PrivateKey / Box / GroupElement",
|
|
138
|
+
category: "key-exchange",
|
|
139
|
+
severity: "medium",
|
|
140
|
+
confidence: "high",
|
|
141
|
+
algorithm: "X25519",
|
|
142
|
+
hndl: true,
|
|
143
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
144
|
+
message: "Curve25519/X25519 key agreement via the `rbnacl` gem (libsodium) — modern but classical key agreement, harvest-now-decrypt-later exposed.",
|
|
145
|
+
};
|
|
146
|
+
const RULE_RB_TLS_VERIFY_NONE = {
|
|
147
|
+
id: "ruby-tls-verify-none",
|
|
148
|
+
title: "Ruby TLS certificate verification disabled",
|
|
149
|
+
description: "OpenSSL::SSL::VERIFY_NONE",
|
|
150
|
+
category: "tls",
|
|
151
|
+
severity: "high",
|
|
152
|
+
confidence: "high",
|
|
153
|
+
hndl: false,
|
|
154
|
+
cwe: CWE_CERT_VALIDATION,
|
|
155
|
+
message: "OpenSSL::SSL::VERIFY_NONE disables TLS peer certificate verification (MITM risk).",
|
|
156
|
+
remediation: "Use OpenSSL::SSL::VERIFY_PEER and verify the certificate chain.",
|
|
157
|
+
};
|
|
57
158
|
/** Detects classical asymmetric crypto in Ruby (OpenSSL::PKey). */
|
|
58
159
|
export const rubyDetector = {
|
|
59
160
|
id: "ruby-crypto",
|
|
60
161
|
description: "Classical asymmetric crypto in Ruby (OpenSSL::PKey::{RSA,EC,DSA,DH})",
|
|
61
162
|
scope: "source",
|
|
62
163
|
language: "ruby",
|
|
63
|
-
rules: [
|
|
164
|
+
rules: [
|
|
165
|
+
RULE_RB_RSA,
|
|
166
|
+
RULE_RB_EC,
|
|
167
|
+
RULE_RB_DSA,
|
|
168
|
+
RULE_RB_DH,
|
|
169
|
+
RULE_RB_RSA_CRYPT,
|
|
170
|
+
RULE_RB_DH_AGREE,
|
|
171
|
+
RULE_RB_PKEY_READ,
|
|
172
|
+
RULE_RB_ED25519,
|
|
173
|
+
RULE_RB_ED25519_GEM,
|
|
174
|
+
RULE_RB_RBNACL,
|
|
175
|
+
RULE_RB_TLS_VERIFY_NONE,
|
|
176
|
+
],
|
|
64
177
|
appliesTo: (f) => hasExtension(f, RUBY_EXTENSIONS),
|
|
65
178
|
detect({ file, content }) {
|
|
66
179
|
const findings = [];
|
|
@@ -69,6 +182,13 @@ export const rubyDetector = {
|
|
|
69
182
|
add(RE_RB_EC, RULE_RB_EC);
|
|
70
183
|
add(RE_RB_DSA, RULE_RB_DSA);
|
|
71
184
|
add(RE_RB_DH, RULE_RB_DH);
|
|
185
|
+
add(RE_RB_RSA_CRYPT, RULE_RB_RSA_CRYPT);
|
|
186
|
+
add(RE_RB_DH_AGREE, RULE_RB_DH_AGREE);
|
|
187
|
+
add(RE_RB_PKEY_READ, RULE_RB_PKEY_READ);
|
|
188
|
+
add(RE_RB_ED25519, RULE_RB_ED25519);
|
|
189
|
+
add(RE_RB_ED25519_GEM, RULE_RB_ED25519_GEM);
|
|
190
|
+
add(RE_RB_RBNACL, RULE_RB_RBNACL);
|
|
191
|
+
add(RE_RB_TLS_VERIFY_NONE, RULE_RB_TLS_VERIFY_NONE);
|
|
72
192
|
return findings;
|
|
73
193
|
},
|
|
74
194
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruby.js","sourceRoot":"","sources":["../../src/detectors/ruby.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,SAAS,GAAG,8CAA8C,CAAC;AACjE,MAAM,QAAQ,GAAG,6CAA6C,CAAC;AAC/D,MAAM,SAAS,GAAG,8CAA8C,CAAC;AACjE,MAAM,QAAQ,GAAG,gCAAgC,CAAC;AAElD,MAAM,WAAW,GAAa;IAC5B,EAAE,EAAE,UAAU;IACd,KAAK,EAAE,oBAAoB;IAC3B,WAAW,EAAE,oCAAoC;IACjD,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,KAAK;IAChB,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,iBAAiB;IACtB,OAAO,EAAE,sFAAsF;CAChG,CAAC;AACF,MAAM,UAAU,GAAa;IAC3B,EAAE,EAAE,SAAS;IACb,KAAK,EAAE,wBAAwB;IAC/B,WAAW,EAAE,mCAAmC;IAChD,QAAQ,EAAE,cAAc;IACxB,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,IAAI;IACV,GAAG,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E,OAAO,EAAE;QACtB,MAAM,QAAQ,GAAc,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,IAAc,EAAE,EAAE,CACzC,SAAS,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAC3B,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CACnF,CACF,CAAC;QACJ,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC5B,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1B,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC5B,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1B,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACxC,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACtC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACxC,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;QACpC,GAAG,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;QAC5C,GAAG,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QAClC,GAAG,CAAC,qBAAqB,EAAE,uBAAuB,CAAC,CAAC;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical asymmetric cryptography in Ruby. Ruby's\n * asymmetric crypto is almost entirely `OpenSSL::PKey::{RSA,EC,DSA,DH}`, which\n * makes the signals precise. Lexical, same strategy as the other packs. Beyond\n * keygen it also covers RSA public-key encryption on a loaded key, DH key\n * agreement, the type-agnostic `OpenSSL::PKey.read` loader, Ed25519 key\n * generation, and disabled TLS peer verification (`VERIFY_NONE`).\n *\n * HNDL: RSA (keygen/encryption) and (EC)DH key agreement are harvest-now-\n * decrypt-later exposed (hndl:true); DSA / Ed25519 signatures are hndl:false but\n * forgeable. `OpenSSL::PKey::EC` is ambiguous (feeds ECDSA + ECDH), so it is\n * classified conservatively as key-exchange-capable (hndl:true), like the other\n * EC keygen rules; `OpenSSL::PKey.read` loads a key of unknown type and is\n * likewise treated conservatively.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { RUBY_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION } from \"../cwe.js\";\n\nconst RE_RB_RSA = /\\bOpenSSL::PKey::RSA\\.(?:new|generate)\\s*\\(/g;\nconst RE_RB_EC = /\\bOpenSSL::PKey::EC\\.(?:new|generate)\\s*\\(/g;\nconst RE_RB_DSA = /\\bOpenSSL::PKey::DSA\\.(?:new|generate)\\s*\\(/g;\nconst RE_RB_DH = /\\bOpenSSL::PKey::DH\\.new\\s*\\(/g;\n// RSA public-key encryption on an already-loaded key (audit F4-ruby / F9).\nconst RE_RB_RSA_CRYPT = /\\.public_encrypt\\b|\\.private_decrypt\\b/g;\n// Finite-field DH shared-secret agreement.\nconst RE_RB_DH_AGREE = /\\bdh_compute_key\\s*\\(/g;\n// Type-agnostic key loader — could be RSA/EC/DSA/DH (conservative).\nconst RE_RB_PKEY_READ = /\\bOpenSSL::PKey\\.read\\s*\\(/g;\n// Ed25519 signing key via the generic generate_key factory.\nconst RE_RB_ED25519 = /\\bOpenSSL::PKey\\.generate_key\\s*\\(\\s*[\"']ED25519[\"']/g;\n// `ed25519` gem — Ed25519::SigningKey / VerifyKey (signature keys).\nconst RE_RB_ED25519_GEM = /\\bEd25519::(?:SigningKey|VerifyKey)\\b/g;\n// `rbnacl` (libsodium) — Curve25519/X25519 key agreement: PrivateKey, Box, GroupElement.\nconst RE_RB_RBNACL = /\\bRbNaCl::(?:PrivateKey|Box|GroupElement)\\b/g;\n// TLS peer verification disabled (mirrors the JS tlsDetector rejectUnauthorized rule).\nconst RE_RB_TLS_VERIFY_NONE = /\\bOpenSSL::SSL::VERIFY_NONE\\b/g;\n\nconst RULE_RB_RSA: RuleMeta = {\n id: \"ruby-rsa\",\n title: \"Ruby RSA key/usage\",\n description: \"OpenSSL::PKey::RSA.new / .generate\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA (Ruby/OpenSSL) is not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_RB_EC: RuleMeta = {\n id: \"ruby-ec\",\n title: \"Ruby EC key generation\",\n description: \"OpenSSL::PKey::EC.new / .generate\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates a classical EC key pair (Ruby/OpenSSL). EC keys feed BOTH ECDSA signatures and ECDH key agreement; the ECDH path is harvest-now-decrypt-later exposed.\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_RB_DSA: RuleMeta = {\n id: \"ruby-dsa\",\n title: \"Ruby DSA key/signature\",\n description: \"OpenSSL::PKey::DSA.new / .generate\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (Ruby/OpenSSL) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_RB_DH: RuleMeta = {\n id: \"ruby-dh\",\n title: \"Ruby Diffie-Hellman key exchange\",\n description: \"OpenSSL::PKey::DH.new\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Finite-field Diffie-Hellman (Ruby/OpenSSL) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_RB_RSA_CRYPT: RuleMeta = {\n id: \"ruby-rsa-crypt\",\n title: \"Ruby RSA public-key encryption\",\n description: \"OpenSSL::PKey::RSA#public_encrypt / #private_decrypt\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"RSA public-key encryption/decryption (Ruby/OpenSSL) is harvest-now-decrypt-later exposed.\",\n};\nconst RULE_RB_DH_AGREE: RuleMeta = {\n id: \"ruby-dh-agree\",\n title: \"Ruby Diffie-Hellman key agreement\",\n description: \"OpenSSL DH compute_key shared-secret agreement\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Finite-field Diffie-Hellman key agreement (Ruby/OpenSSL) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_RB_PKEY_READ: RuleMeta = {\n id: \"ruby-pkey-read\",\n title: \"Ruby PKey loaded from serialized key\",\n description: \"OpenSSL::PKey.read (type-agnostic key loader)\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"medium\",\n algorithm: \"unknown\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Loads a classical asymmetric key of unknown type (RSA/EC/DSA/DH) via OpenSSL::PKey.read. Treated conservatively as key-exchange-capable (harvest-now-decrypt-later).\",\n remediation:\n \"For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_RB_ED25519: RuleMeta = {\n id: \"ruby-ed25519\",\n title: \"Ruby Ed25519 key generation\",\n description: 'OpenSSL::PKey.generate_key(\"ED25519\")',\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates an Ed25519 signing key (Ruby/OpenSSL) — modern but classical, and forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_RB_ED25519_GEM: RuleMeta = {\n id: \"ruby-ed25519-gem\",\n title: \"Ruby Ed25519 signature (ed25519 gem)\",\n description: \"ed25519 gem Ed25519::SigningKey / Ed25519::VerifyKey\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Ed25519 signing/verification via the `ed25519` gem — modern but classical, and forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_RB_RBNACL: RuleMeta = {\n id: \"ruby-rbnacl\",\n title: \"Ruby X25519 key agreement (rbnacl)\",\n description: \"rbnacl (libsodium) RbNaCl::PrivateKey / Box / GroupElement\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Curve25519/X25519 key agreement via the `rbnacl` gem (libsodium) — modern but classical key agreement, harvest-now-decrypt-later exposed.\",\n};\nconst RULE_RB_TLS_VERIFY_NONE: RuleMeta = {\n id: \"ruby-tls-verify-none\",\n title: \"Ruby TLS certificate verification disabled\",\n description: \"OpenSSL::SSL::VERIFY_NONE\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"OpenSSL::SSL::VERIFY_NONE disables TLS peer certificate verification (MITM risk).\",\n remediation: \"Use OpenSSL::SSL::VERIFY_PEER and verify the certificate chain.\",\n};\n\n/** Detects classical asymmetric crypto in Ruby (OpenSSL::PKey). */\nexport const rubyDetector: Detector = {\n id: \"ruby-crypto\",\n description: \"Classical asymmetric crypto in Ruby (OpenSSL::PKey::{RSA,EC,DSA,DH})\",\n scope: \"source\",\n language: \"ruby\",\n rules: [\n RULE_RB_RSA,\n RULE_RB_EC,\n RULE_RB_DSA,\n RULE_RB_DH,\n RULE_RB_RSA_CRYPT,\n RULE_RB_DH_AGREE,\n RULE_RB_PKEY_READ,\n RULE_RB_ED25519,\n RULE_RB_ED25519_GEM,\n RULE_RB_RBNACL,\n RULE_RB_TLS_VERIFY_NONE,\n ],\n appliesTo: (f) => hasExtension(f, RUBY_EXTENSIONS),\n detect({ file, content }): Finding[] {\n const findings: Finding[] = [];\n const add = (re: RegExp, rule: RuleMeta) =>\n eachMatch(re, content, (m) =>\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n ),\n );\n add(RE_RB_RSA, RULE_RB_RSA);\n add(RE_RB_EC, RULE_RB_EC);\n add(RE_RB_DSA, RULE_RB_DSA);\n add(RE_RB_DH, RULE_RB_DH);\n add(RE_RB_RSA_CRYPT, RULE_RB_RSA_CRYPT);\n add(RE_RB_DH_AGREE, RULE_RB_DH_AGREE);\n add(RE_RB_PKEY_READ, RULE_RB_PKEY_READ);\n add(RE_RB_ED25519, RULE_RB_ED25519);\n add(RE_RB_ED25519_GEM, RULE_RB_ED25519_GEM);\n add(RE_RB_RBNACL, RULE_RB_RBNACL);\n add(RE_RB_TLS_VERIFY_NONE, RULE_RB_TLS_VERIFY_NONE);\n return findings;\n },\n};\n"]}
|
package/dist/detectors/rust.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
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
15
|
import type { Detector } from "../types.js";
|
|
11
16
|
/** Detects classical asymmetric crypto in Rust (rsa, ring, dalek, p256/k256). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rust.d.ts","sourceRoot":"","sources":["../../src/detectors/rust.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"rust.d.ts","sourceRoot":"","sources":["../../src/detectors/rust.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAmB,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAwShF,iFAAiF;AACjF,eAAO,MAAM,YAAY,EAAE,QA2E1B,CAAC"}
|