@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.
Files changed (223) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +38 -10
  3. package/dist/agent-types.js.map +1 -1
  4. package/dist/baseline.js.map +1 -1
  5. package/dist/cache.js.map +1 -1
  6. package/dist/cbom-merge.d.ts +9 -0
  7. package/dist/cbom-merge.d.ts.map +1 -0
  8. package/dist/cbom-merge.js +99 -0
  9. package/dist/cbom-merge.js.map +1 -0
  10. package/dist/cbom.js.map +1 -1
  11. package/dist/changed.js.map +1 -1
  12. package/dist/codemods/config-toggle.js.map +1 -1
  13. package/dist/codemods/registry.js.map +1 -1
  14. package/dist/comments.d.ts +29 -2
  15. package/dist/comments.d.ts.map +1 -1
  16. package/dist/comments.js +178 -18
  17. package/dist/comments.js.map +1 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/cwe.js.map +1 -1
  20. package/dist/dependencies.d.ts +3 -2
  21. package/dist/dependencies.d.ts.map +1 -1
  22. package/dist/dependencies.js +138 -2
  23. package/dist/dependencies.js.map +1 -1
  24. package/dist/detect-utils.d.ts +19 -4
  25. package/dist/detect-utils.d.ts.map +1 -1
  26. package/dist/detect-utils.js +43 -6
  27. package/dist/detect-utils.js.map +1 -1
  28. package/dist/detectors/c.d.ts +4 -2
  29. package/dist/detectors/c.d.ts.map +1 -1
  30. package/dist/detectors/c.js +382 -3
  31. package/dist/detectors/c.js.map +1 -1
  32. package/dist/detectors/cicd.d.ts +27 -0
  33. package/dist/detectors/cicd.d.ts.map +1 -0
  34. package/dist/detectors/cicd.js +116 -0
  35. package/dist/detectors/cicd.js.map +1 -0
  36. package/dist/detectors/cloud-kms.d.ts +21 -0
  37. package/dist/detectors/cloud-kms.d.ts.map +1 -0
  38. package/dist/detectors/cloud-kms.js +57 -0
  39. package/dist/detectors/cloud-kms.js.map +1 -0
  40. package/dist/detectors/cloudformation.d.ts +30 -0
  41. package/dist/detectors/cloudformation.d.ts.map +1 -0
  42. package/dist/detectors/cloudformation.js +170 -0
  43. package/dist/detectors/cloudformation.js.map +1 -0
  44. package/dist/detectors/csharp.d.ts.map +1 -1
  45. package/dist/detectors/csharp.js +141 -3
  46. package/dist/detectors/csharp.js.map +1 -1
  47. package/dist/detectors/database.d.ts +17 -0
  48. package/dist/detectors/database.d.ts.map +1 -0
  49. package/dist/detectors/database.js +60 -0
  50. package/dist/detectors/database.js.map +1 -0
  51. package/dist/detectors/dnssec.d.ts +55 -0
  52. package/dist/detectors/dnssec.d.ts.map +1 -0
  53. package/dist/detectors/dnssec.js +107 -0
  54. package/dist/detectors/dnssec.js.map +1 -0
  55. package/dist/detectors/elixir.d.ts +20 -0
  56. package/dist/detectors/elixir.d.ts.map +1 -0
  57. package/dist/detectors/elixir.js +195 -0
  58. package/dist/detectors/elixir.js.map +1 -0
  59. package/dist/detectors/go.d.ts +5 -3
  60. package/dist/detectors/go.d.ts.map +1 -1
  61. package/dist/detectors/go.js +187 -3
  62. package/dist/detectors/go.js.map +1 -1
  63. package/dist/detectors/java.d.ts.map +1 -1
  64. package/dist/detectors/java.js +169 -4
  65. package/dist/detectors/java.js.map +1 -1
  66. package/dist/detectors/jose.d.ts +20 -0
  67. package/dist/detectors/jose.d.ts.map +1 -0
  68. package/dist/detectors/jose.js +62 -0
  69. package/dist/detectors/jose.js.map +1 -0
  70. package/dist/detectors/jwk.d.ts +25 -0
  71. package/dist/detectors/jwk.d.ts.map +1 -0
  72. package/dist/detectors/jwk.js +95 -0
  73. package/dist/detectors/jwk.js.map +1 -0
  74. package/dist/detectors/k8s.d.ts +17 -0
  75. package/dist/detectors/k8s.d.ts.map +1 -0
  76. package/dist/detectors/k8s.js +85 -0
  77. package/dist/detectors/k8s.js.map +1 -0
  78. package/dist/detectors/mesh.d.ts +35 -0
  79. package/dist/detectors/mesh.d.ts.map +1 -0
  80. package/dist/detectors/mesh.js +109 -0
  81. package/dist/detectors/mesh.js.map +1 -0
  82. package/dist/detectors/messaging.d.ts +16 -0
  83. package/dist/detectors/messaging.d.ts.map +1 -0
  84. package/dist/detectors/messaging.js +72 -0
  85. package/dist/detectors/messaging.js.map +1 -0
  86. package/dist/detectors/pem.d.ts.map +1 -1
  87. package/dist/detectors/pem.js +50 -2
  88. package/dist/detectors/pem.js.map +1 -1
  89. package/dist/detectors/php.d.ts +24 -0
  90. package/dist/detectors/php.d.ts.map +1 -0
  91. package/dist/detectors/php.js +167 -0
  92. package/dist/detectors/php.js.map +1 -0
  93. package/dist/detectors/python.d.ts.map +1 -1
  94. package/dist/detectors/python.js +144 -3
  95. package/dist/detectors/python.js.map +1 -1
  96. package/dist/detectors/ruby.d.ts +9 -5
  97. package/dist/detectors/ruby.d.ts.map +1 -1
  98. package/dist/detectors/ruby.js +122 -2
  99. package/dist/detectors/ruby.js.map +1 -1
  100. package/dist/detectors/rust.d.ts +8 -3
  101. package/dist/detectors/rust.d.ts.map +1 -1
  102. package/dist/detectors/rust.js +253 -3
  103. package/dist/detectors/rust.js.map +1 -1
  104. package/dist/detectors/secrets.d.ts +21 -0
  105. package/dist/detectors/secrets.d.ts.map +1 -0
  106. package/dist/detectors/secrets.js +79 -0
  107. package/dist/detectors/secrets.js.map +1 -0
  108. package/dist/detectors/source.d.ts.map +1 -1
  109. package/dist/detectors/source.js +305 -52
  110. package/dist/detectors/source.js.map +1 -1
  111. package/dist/detectors/stateful-hbs.d.ts +22 -0
  112. package/dist/detectors/stateful-hbs.d.ts.map +1 -0
  113. package/dist/detectors/stateful-hbs.js +142 -0
  114. package/dist/detectors/stateful-hbs.js.map +1 -0
  115. package/dist/detectors/terraform.d.ts +21 -0
  116. package/dist/detectors/terraform.d.ts.map +1 -0
  117. package/dist/detectors/terraform.js +123 -0
  118. package/dist/detectors/terraform.js.map +1 -0
  119. package/dist/detectors/vpn.d.ts +22 -0
  120. package/dist/detectors/vpn.d.ts.map +1 -0
  121. package/dist/detectors/vpn.js +99 -0
  122. package/dist/detectors/vpn.js.map +1 -0
  123. package/dist/errors.js.map +1 -1
  124. package/dist/evidence.d.ts +53 -0
  125. package/dist/evidence.d.ts.map +1 -0
  126. package/dist/evidence.js +81 -0
  127. package/dist/evidence.js.map +1 -0
  128. package/dist/index.d.ts +9 -2
  129. package/dist/index.d.ts.map +1 -1
  130. package/dist/index.js +10 -2
  131. package/dist/index.js.map +1 -1
  132. package/dist/inventory.d.ts +2 -0
  133. package/dist/inventory.d.ts.map +1 -1
  134. package/dist/inventory.js +27 -1
  135. package/dist/inventory.js.map +1 -1
  136. package/dist/parallel.js.map +1 -1
  137. package/dist/patch-policy.js.map +1 -1
  138. package/dist/policy.d.ts +67 -0
  139. package/dist/policy.d.ts.map +1 -0
  140. package/dist/policy.js +115 -0
  141. package/dist/policy.js.map +1 -0
  142. package/dist/redact.d.ts.map +1 -1
  143. package/dist/redact.js +39 -0
  144. package/dist/redact.js.map +1 -1
  145. package/dist/registry.d.ts +2 -2
  146. package/dist/registry.d.ts.map +1 -1
  147. package/dist/registry.js +34 -2
  148. package/dist/registry.js.map +1 -1
  149. package/dist/remediate-pipeline.d.ts +3 -0
  150. package/dist/remediate-pipeline.d.ts.map +1 -1
  151. package/dist/remediate-pipeline.js +71 -0
  152. package/dist/remediate-pipeline.js.map +1 -1
  153. package/dist/remediate-request.js.map +1 -1
  154. package/dist/remediation.d.ts +9 -3
  155. package/dist/remediation.d.ts.map +1 -1
  156. package/dist/remediation.js +17 -5
  157. package/dist/remediation.js.map +1 -1
  158. package/dist/report.d.ts +9 -0
  159. package/dist/report.d.ts.map +1 -1
  160. package/dist/report.js +38 -0
  161. package/dist/report.js.map +1 -1
  162. package/dist/scan-worker.js.map +1 -1
  163. package/dist/scan.d.ts.map +1 -1
  164. package/dist/scan.js +8 -1
  165. package/dist/scan.js.map +1 -1
  166. package/dist/severity.js.map +1 -1
  167. package/dist/standards.d.ts +96 -0
  168. package/dist/standards.d.ts.map +1 -0
  169. package/dist/standards.js +107 -0
  170. package/dist/standards.js.map +1 -0
  171. package/dist/triage.js.map +1 -1
  172. package/dist/types.d.ts +2 -2
  173. package/dist/types.d.ts.map +1 -1
  174. package/dist/types.js.map +1 -1
  175. package/dist/verify.js.map +1 -1
  176. package/dist/version.d.ts +1 -1
  177. package/dist/version.js +1 -1
  178. package/dist/version.js.map +1 -1
  179. package/dist/walk.js.map +1 -1
  180. package/dist/worktree.js.map +1 -1
  181. package/package.json +1 -1
  182. package/src/cbom-merge.ts +116 -0
  183. package/src/comments.ts +183 -18
  184. package/src/dependencies.ts +144 -4
  185. package/src/detect-utils.ts +47 -6
  186. package/src/detectors/c.ts +411 -5
  187. package/src/detectors/cicd.ts +158 -0
  188. package/src/detectors/cloud-kms.ts +87 -0
  189. package/src/detectors/cloudformation.ts +215 -0
  190. package/src/detectors/csharp.ts +154 -3
  191. package/src/detectors/database.ts +88 -0
  192. package/src/detectors/dnssec.ts +186 -0
  193. package/src/detectors/elixir.ts +237 -0
  194. package/src/detectors/go.ts +209 -6
  195. package/src/detectors/java.ts +191 -4
  196. package/src/detectors/jose.ts +94 -0
  197. package/src/detectors/jwk.ts +128 -0
  198. package/src/detectors/k8s.ts +112 -0
  199. package/src/detectors/mesh.ts +154 -0
  200. package/src/detectors/messaging.ts +98 -0
  201. package/src/detectors/pem.ts +54 -2
  202. package/src/detectors/php.ts +225 -0
  203. package/src/detectors/python.ts +153 -3
  204. package/src/detectors/ruby.ts +138 -7
  205. package/src/detectors/rust.ts +282 -7
  206. package/src/detectors/secrets.ts +114 -0
  207. package/src/detectors/source.ts +382 -72
  208. package/src/detectors/stateful-hbs.ts +180 -0
  209. package/src/detectors/terraform.ts +154 -0
  210. package/src/detectors/vpn.ts +131 -0
  211. package/src/evidence.ts +135 -0
  212. package/src/index.ts +15 -1
  213. package/src/inventory.ts +31 -1
  214. package/src/policy.ts +180 -0
  215. package/src/redact.ts +41 -0
  216. package/src/registry.ts +34 -2
  217. package/src/remediate-pipeline.ts +78 -0
  218. package/src/remediation.ts +23 -8
  219. package/src/report.ts +48 -2
  220. package/src/scan.ts +13 -1
  221. package/src/standards.ts +186 -0
  222. package/src/types.ts +3 -1
  223. package/src/version.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  import { RUST_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
  // `rsa` crate + ring RsaKeyPair. `::` after the type marks an associated-fn call.
4
4
  const RE_RUST_RSA = /\b(?:RsaPrivateKey|RsaPublicKey|RsaKeyPair)::/g;
5
5
  // ECDSA: RustCrypto `p256::ecdsa::SigningKey` (contains `ecdsa::SigningKey`),
@@ -11,6 +11,31 @@ const RE_RUST_ECDH = /\becdh::EphemeralSecret\b|\bagreement::ECDH_P(?:256|384)\b
11
11
  const RE_RUST_ED25519 = /\bed25519_dalek::(?:SigningKey|Keypair|SecretKey)\b|\bEd25519KeyPair::/g;
12
12
  // X25519 key agreement (dalek).
13
13
  const RE_RUST_X25519 = /\bx25519_dalek::(?:EphemeralSecret|StaticSecret)\b/g;
14
+ // openssl crate bindings — the `Type::generate(` / `Dh::` call forms, distinct
15
+ // from the ring / RustCrypto path syntax above (audit F5/F9 false-negatives).
16
+ const RE_RUST_OPENSSL_RSA = /\bRsa::generate\s*\(/g;
17
+ const RE_RUST_OPENSSL_EC = /\bEcKey::generate\s*\(/g;
18
+ const RE_RUST_OPENSSL_DSA = /\bDsa::generate\s*\(/g;
19
+ const RE_RUST_OPENSSL_DH = /\bDh::/g;
20
+ // ring X25519 agreement (the ECDH_P* forms are handled by RE_RUST_ECDH above).
21
+ const RE_RUST_RING_X25519 = /\bagreement::X25519\b/g;
22
+ // Bare (unqualified) constructors: a braced `use x25519_dalek::{EphemeralSecret}`
23
+ // / `use ed25519_dalek::{SigningKey}` strips the `::` path prefix, defeating the
24
+ // path-qualified rules above. The `(?<![:\w])` lookbehind keeps these from
25
+ // double-matching the qualified forms (e.g. `p256::ecdsa::SigningKey::random`).
26
+ const RE_RUST_BARE_X25519 = /(?<![:\w])EphemeralSecret::new\s*\(/g;
27
+ const RE_RUST_BARE_SIGNINGKEY = /(?<![:\w])SigningKey::(?:generate|random)\s*\(/g;
28
+ // jsonwebtoken crate `Algorithm` enum variants selecting a classical JWT signer:
29
+ // RSASSA-PKCS1 (RS*), RSASSA-PSS (PS*), ECDSA (ES*), and Ed25519 (EdDSA). The
30
+ // `\s*` between `Algorithm` and `::` catches the variant split across lines /
31
+ // routed through a helper (audit token_policy false-negative); the required
32
+ // suffix keeps it off unrelated `Algorithm::` uses (e.g. `HS256` HMAC, which is
33
+ // symmetric and not quantum-vulnerable, or `Algorithm::new`).
34
+ const RE_RUST_JWT_ALG = /\bAlgorithm\s*::(RS|PS|ES)(?:256|384|512)\b|\bAlgorithm\s*::EdDSA\b/g;
35
+ // Rust TLS certificate-validation bypass: reqwest `danger_accept_invalid_certs`
36
+ // and the rustls `.dangerous()` escape hatch. Mirrors the JS tlsDetector.
37
+ const RE_RUST_TLS_ACCEPT_INVALID = /\bdanger_accept_invalid_certs\s*\(\s*true/g;
38
+ const RE_RUST_TLS_DANGEROUS = /\.dangerous\s*\(\s*\)/g;
14
39
  const RULE_RUST_RSA = {
15
40
  id: "rust-rsa",
16
41
  title: "Rust RSA key/usage",
@@ -65,20 +90,220 @@ const RULE_RUST_X25519 = {
65
90
  title: "Rust X25519 key agreement",
66
91
  description: "x25519-dalek EphemeralSecret/StaticSecret",
67
92
  category: "key-exchange",
68
- severity: "low",
93
+ severity: "medium",
69
94
  confidence: "high",
70
95
  algorithm: "X25519",
71
96
  hndl: true,
72
97
  cwe: CWE_BROKEN_CRYPTO,
73
98
  message: "X25519 (Rust) is modern but still classical key agreement — harvest-now-decrypt-later.",
74
99
  };
100
+ const RULE_RUST_X448 = {
101
+ id: "rust-x448",
102
+ title: "Rust X448 key agreement",
103
+ description: "the `x448` crate Secret key agreement",
104
+ category: "key-exchange",
105
+ severity: "medium",
106
+ confidence: "high",
107
+ algorithm: "X448",
108
+ hndl: true,
109
+ cwe: CWE_BROKEN_CRYPTO,
110
+ message: "X448 (Rust) is modern but still classical key agreement — harvest-now-decrypt-later.",
111
+ };
112
+ const RULE_RUST_OPENSSL_RSA = {
113
+ id: "rust-openssl-rsa",
114
+ title: "Rust openssl RSA key generation",
115
+ description: "openssl crate Rsa::generate",
116
+ category: "kem",
117
+ severity: "high",
118
+ confidence: "high",
119
+ algorithm: "RSA",
120
+ hndl: true,
121
+ cwe: CWE_BROKEN_CRYPTO,
122
+ message: "Generates a classical RSA key pair via the Rust `openssl` crate — not quantum-safe and RSA encryption is HNDL-exposed.",
123
+ };
124
+ const RULE_RUST_OPENSSL_EC = {
125
+ id: "rust-openssl-ec",
126
+ title: "Rust openssl EC key generation",
127
+ description: "openssl crate EcKey::generate",
128
+ category: "key-exchange",
129
+ severity: "high",
130
+ confidence: "high",
131
+ algorithm: "ECDH",
132
+ hndl: true,
133
+ cwe: CWE_BROKEN_CRYPTO,
134
+ message: "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.",
135
+ remediation: "For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
136
+ };
137
+ const RULE_RUST_OPENSSL_DSA = {
138
+ id: "rust-openssl-dsa",
139
+ title: "Rust openssl DSA key/usage",
140
+ description: "openssl crate Dsa::generate",
141
+ category: "signature",
142
+ severity: "high",
143
+ confidence: "high",
144
+ algorithm: "DSA",
145
+ hndl: false,
146
+ cwe: CWE_BROKEN_CRYPTO,
147
+ message: "Classical DSA via the Rust `openssl` crate is deprecated and forgeable by a quantum attacker.",
148
+ remediation: "Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).",
149
+ };
150
+ const RULE_RUST_OPENSSL_DH = {
151
+ id: "rust-openssl-dh",
152
+ title: "Rust openssl Diffie-Hellman key exchange",
153
+ description: "openssl crate Dh params / key generation",
154
+ category: "key-exchange",
155
+ severity: "high",
156
+ confidence: "high",
157
+ algorithm: "DH",
158
+ hndl: true,
159
+ cwe: CWE_BROKEN_CRYPTO,
160
+ message: "Finite-field Diffie-Hellman via the Rust `openssl` crate is broken by Shor's algorithm (harvest-now-decrypt-later).",
161
+ };
162
+ const RULE_RUST_RING_X25519 = {
163
+ id: "rust-ring-x25519",
164
+ title: "Rust ring X25519 key agreement",
165
+ description: "ring agreement::X25519",
166
+ category: "key-exchange",
167
+ severity: "medium",
168
+ confidence: "high",
169
+ algorithm: "X25519",
170
+ hndl: true,
171
+ cwe: CWE_BROKEN_CRYPTO,
172
+ message: "X25519 key agreement via ring (Rust) is modern but still classical — harvest-now-decrypt-later.",
173
+ };
174
+ const RULE_RUST_BARE_X25519 = {
175
+ id: "rust-x25519-bare",
176
+ title: "Rust X25519 key agreement (unqualified)",
177
+ description: "bare EphemeralSecret::new (x25519-dalek imported via `use`)",
178
+ category: "key-exchange",
179
+ severity: "medium",
180
+ confidence: "medium",
181
+ algorithm: "X25519",
182
+ hndl: true,
183
+ cwe: CWE_BROKEN_CRYPTO,
184
+ message: "X25519 key agreement (x25519-dalek, imported unqualified) is modern but still classical — harvest-now-decrypt-later.",
185
+ };
186
+ const RULE_RUST_BARE_SIGNINGKEY = {
187
+ id: "rust-signingkey-bare",
188
+ title: "Rust signature key (unqualified)",
189
+ description: "bare SigningKey::generate/random (ed25519-dalek / k256 via `use`)",
190
+ category: "signature",
191
+ severity: "medium",
192
+ confidence: "medium",
193
+ algorithm: "unknown",
194
+ hndl: false,
195
+ cwe: CWE_BROKEN_CRYPTO,
196
+ message: "Classical signature key from an unqualified `SigningKey` (ed25519-dalek Ed25519 / k256 ECDSA) — forgeable by a quantum attacker.",
197
+ remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
198
+ };
199
+ const RULE_RUST_JWT_ALGORITHM = {
200
+ id: "rust-jwt-algorithm",
201
+ title: "Rust jsonwebtoken classical signature algorithm",
202
+ description: "jsonwebtoken Algorithm::{RS,PS,ES}* / Algorithm::EdDSA enum variant",
203
+ category: "signature",
204
+ severity: "high",
205
+ confidence: "high",
206
+ // Representative family; refined per-finding (RS*/PS* → RSA, ES* → ECDSA, EdDSA).
207
+ algorithm: "RSA",
208
+ hndl: false,
209
+ cwe: CWE_BROKEN_CRYPTO,
210
+ message: "Selects a classical JWT signature algorithm (jsonwebtoken RS*/PS*/ES*/EdDSA), forgeable by a quantum attacker.",
211
+ remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)",
212
+ };
213
+ const RULE_RUST_TLS_ACCEPT_INVALID = {
214
+ id: "rust-tls-accept-invalid-certs",
215
+ title: "Rust TLS certificate verification disabled",
216
+ description: "reqwest danger_accept_invalid_certs(true)",
217
+ category: "tls",
218
+ severity: "high",
219
+ confidence: "high",
220
+ hndl: false,
221
+ cwe: CWE_CERT_VALIDATION,
222
+ message: "danger_accept_invalid_certs(true) disables TLS certificate verification in reqwest (MITM risk).",
223
+ remediation: "Remove danger_accept_invalid_certs(true); verify certificates properly.",
224
+ };
225
+ const RULE_RUST_TLS_DANGEROUS = {
226
+ id: "rust-tls-rustls-dangerous",
227
+ title: "Rust rustls dangerous certificate config",
228
+ description: "rustls ClientConfig .dangerous() escape hatch",
229
+ category: "tls",
230
+ severity: "high",
231
+ confidence: "medium",
232
+ hndl: false,
233
+ cwe: CWE_CERT_VALIDATION,
234
+ message: "rustls `.dangerous()` opts into disabling certificate verification (MITM risk).",
235
+ remediation: "Avoid the dangerous() escape hatch; keep the default certificate verifier.",
236
+ };
237
+ /**
238
+ * Aliasable Rust crypto types (`<crate>::<OrigType>` → rule). A renamed `use`
239
+ * (`use x25519_dalek::{EphemeralSecret as MontgomerySecret}`) binds the alias to a
240
+ * classical-key type; a later `MontgomerySecret::<ctor>(` is that key's
241
+ * construction. The `::`-qualified and braced rules above miss this because the
242
+ * call site uses the renamed identifier, not the original path.
243
+ */
244
+ const RUST_ALIASABLE = {
245
+ "x25519_dalek::EphemeralSecret": RULE_RUST_X25519,
246
+ "x25519_dalek::StaticSecret": RULE_RUST_X25519,
247
+ "x448::Secret": RULE_RUST_X448,
248
+ "ed25519_dalek::SigningKey": RULE_RUST_ED25519,
249
+ "ed25519_dalek::Keypair": RULE_RUST_ED25519,
250
+ "ed25519_dalek::SecretKey": RULE_RUST_ED25519,
251
+ };
252
+ /** Escape a string for interpolation into a dynamically-built RegExp. */
253
+ function escapeRustRe(s) {
254
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
255
+ }
256
+ /**
257
+ * Collect `use <crate>::<OrigType> as <Alias>` bindings (braced or single) that
258
+ * rename an aliasable crypto type, returning {alias, rule} pairs. An alias equal
259
+ * to its own type name is skipped (the qualified/bare rules already catch it).
260
+ */
261
+ function collectRustTypeAliases(content) {
262
+ const out = [];
263
+ const push = (crate, orig, alias) => {
264
+ if (!alias || alias === orig)
265
+ return;
266
+ const rule = RUST_ALIASABLE[`${crate}::${orig}`];
267
+ if (rule)
268
+ out.push({ alias, rule });
269
+ };
270
+ // Braced: `use <crate>::{ Orig as Alias, ... }`.
271
+ const braced = /\buse\s+([\w:]+)::\{([^}]*)\}/g;
272
+ for (let m = braced.exec(content); m; m = braced.exec(content)) {
273
+ const specRe = /([A-Za-z_]\w*)\s+as\s+([A-Za-z_]\w*)/g;
274
+ for (let s = specRe.exec(m[2]); s; s = specRe.exec(m[2]))
275
+ push(m[1], s[1], s[2]);
276
+ }
277
+ // Single: `use <crate>::Orig as Alias;`.
278
+ const single = /\buse\s+([\w:]+)::([A-Za-z_]\w*)\s+as\s+([A-Za-z_]\w*)/g;
279
+ for (let m = single.exec(content); m; m = single.exec(content))
280
+ push(m[1], m[2], m[3]);
281
+ return out;
282
+ }
75
283
  /** Detects classical asymmetric crypto in Rust (rsa, ring, dalek, p256/k256). */
76
284
  export const rustDetector = {
77
285
  id: "rust-crypto",
78
286
  description: "Classical asymmetric crypto in Rust (rsa, ring, *-dalek, p256/k256)",
79
287
  scope: "source",
80
288
  language: "rust",
81
- rules: [RULE_RUST_RSA, RULE_RUST_ECDSA, RULE_RUST_ECDH, RULE_RUST_ED25519, RULE_RUST_X25519],
289
+ rules: [
290
+ RULE_RUST_RSA,
291
+ RULE_RUST_ECDSA,
292
+ RULE_RUST_ECDH,
293
+ RULE_RUST_ED25519,
294
+ RULE_RUST_X25519,
295
+ RULE_RUST_X448,
296
+ RULE_RUST_OPENSSL_RSA,
297
+ RULE_RUST_OPENSSL_EC,
298
+ RULE_RUST_OPENSSL_DSA,
299
+ RULE_RUST_OPENSSL_DH,
300
+ RULE_RUST_RING_X25519,
301
+ RULE_RUST_BARE_X25519,
302
+ RULE_RUST_BARE_SIGNINGKEY,
303
+ RULE_RUST_JWT_ALGORITHM,
304
+ RULE_RUST_TLS_ACCEPT_INVALID,
305
+ RULE_RUST_TLS_DANGEROUS,
306
+ ],
82
307
  appliesTo: (f) => hasExtension(f, RUST_EXTENSIONS),
83
308
  detect({ file, content }) {
84
309
  const findings = [];
@@ -88,6 +313,31 @@ export const rustDetector = {
88
313
  add(RE_RUST_ECDH, RULE_RUST_ECDH);
89
314
  add(RE_RUST_ED25519, RULE_RUST_ED25519);
90
315
  add(RE_RUST_X25519, RULE_RUST_X25519);
316
+ add(RE_RUST_OPENSSL_RSA, RULE_RUST_OPENSSL_RSA);
317
+ add(RE_RUST_OPENSSL_EC, RULE_RUST_OPENSSL_EC);
318
+ add(RE_RUST_OPENSSL_DSA, RULE_RUST_OPENSSL_DSA);
319
+ add(RE_RUST_OPENSSL_DH, RULE_RUST_OPENSSL_DH);
320
+ add(RE_RUST_RING_X25519, RULE_RUST_RING_X25519);
321
+ add(RE_RUST_BARE_X25519, RULE_RUST_BARE_X25519);
322
+ add(RE_RUST_BARE_SIGNINGKEY, RULE_RUST_BARE_SIGNINGKEY);
323
+ // jsonwebtoken Algorithm enum variants — resolve the family per match: the
324
+ // RS*/PS* variants are RSASSA (RSA), ES* is ECDSA, EdDSA is Ed25519.
325
+ eachMatch(RE_RUST_JWT_ALG, content, (m) => {
326
+ const prefix = m[1];
327
+ const algorithm = prefix === undefined ? "EdDSA" : prefix === "ES" ? "ECDSA" : "RSA";
328
+ findings.push(findingFromRule(RULE_RUST_JWT_ALGORITHM, { file, content, index: m.index, matchLength: m[0].length }, { algorithm }));
329
+ });
330
+ add(RE_RUST_TLS_ACCEPT_INVALID, RULE_RUST_TLS_ACCEPT_INVALID);
331
+ add(RE_RUST_TLS_DANGEROUS, RULE_RUST_TLS_DANGEROUS);
332
+ // Type-alias resolution: `use x25519_dalek::{EphemeralSecret as MontgomerySecret}`
333
+ // then `MontgomerySecret::random_from_rng(` — the braced+renamed `use` defeats
334
+ // the `::`-qualified rules. Match the aliased type's construction calls; runs
335
+ // on the ORIGINAL content so locations stay exact, and fires only for an alias
336
+ // explicitly bound to a known crypto type (precision-safe).
337
+ for (const { alias, rule } of collectRustTypeAliases(content)) {
338
+ const a = escapeRustRe(alias);
339
+ add(new RegExp(`\\b${a}::(?:new|random|random_from_rng|generate|from_bytes)\\s*\\(`, "g"), rule);
340
+ }
91
341
  return findings;
92
342
  },
93
343
  };
@@ -1 +1 @@
1
- {"version":3,"file":"rust.js","sourceRoot":"","sources":["../../src/detectors/rust.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,kFAAkF;AAClF,MAAM,WAAW,GAAG,gDAAgD,CAAC;AACrE,8EAA8E;AAC9E,wDAAwD;AACxD,MAAM,aAAa,GAAG,yCAAyC,CAAC;AAChE,4EAA4E;AAC5E,MAAM,YAAY,GAAG,6DAA6D,CAAC;AACnF,qCAAqC;AACrC,MAAM,eAAe,GAAG,yEAAyE,CAAC;AAClG,gCAAgC;AAChC,MAAM,cAAc,GAAG,qDAAq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KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAC9B,GAAG,CACD,IAAI,MAAM,CAAC,MAAM,CAAC,6DAA6D,EAAE,GAAG,CAAC,EACrF,IAAI,CACL,CAAC;QACJ,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical asymmetric cryptography in Rust. Covers the\n * common crypto crates: `rsa`, `ring`, the `*-dalek` family (ed25519/x25519),\n * the RustCrypto elliptic-curve crates (`p256`/`p384`/`k256`), and the `openssl`\n * crate bindings. Lexical, same strategy as the other packs; the `::` path\n * syntax makes the signals precise.\n *\n * HNDL: RSA encryption and (EC/X)DH key agreement are harvest-now-decrypt-later\n * exposed (hndl:true); ECDSA / DSA / Ed25519 signatures are hndl:false but\n * forgeable. `openssl::EcKey` keygen is ambiguous (feeds ECDSA + ECDH),\n * classified conservatively as key-exchange-capable (hndl:true). Also flags\n * Rust TLS certificate-validation bypasses (reqwest / rustls) — not quantum but\n * mirrors the JS tlsDetector's cert-validation category.\n */\nimport type { AlgorithmFamily, Detector, Finding, RuleMeta } from \"../types.js\";\nimport { RUST_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION } from \"../cwe.js\";\n\n// `rsa` crate + ring RsaKeyPair. `::` after the type marks an associated-fn call.\nconst RE_RUST_RSA = /\\b(?:RsaPrivateKey|RsaPublicKey|RsaKeyPair)::/g;\n// ECDSA: RustCrypto `p256::ecdsa::SigningKey` (contains `ecdsa::SigningKey`),\n// ring `EcdsaKeyPair::`, or a bare `ecdsa::SigningKey`.\nconst RE_RUST_ECDSA = /\\becdsa::SigningKey\\b|\\bEcdsaKeyPair::/g;\n// ECDH: RustCrypto `p256::ecdh::EphemeralSecret`, ring agreement / ECDH_P*.\nconst RE_RUST_ECDH = /\\becdh::EphemeralSecret\\b|\\bagreement::ECDH_P(?:256|384)\\b/g;\n// Ed25519 signatures (dalek + ring).\nconst RE_RUST_ED25519 = /\\bed25519_dalek::(?:SigningKey|Keypair|SecretKey)\\b|\\bEd25519KeyPair::/g;\n// X25519 key agreement (dalek).\nconst RE_RUST_X25519 = /\\bx25519_dalek::(?:EphemeralSecret|StaticSecret)\\b/g;\n// openssl crate bindings — the `Type::generate(` / `Dh::` call forms, distinct\n// from the ring / RustCrypto path syntax above (audit F5/F9 false-negatives).\nconst RE_RUST_OPENSSL_RSA = /\\bRsa::generate\\s*\\(/g;\nconst RE_RUST_OPENSSL_EC = /\\bEcKey::generate\\s*\\(/g;\nconst RE_RUST_OPENSSL_DSA = /\\bDsa::generate\\s*\\(/g;\nconst RE_RUST_OPENSSL_DH = /\\bDh::/g;\n// ring X25519 agreement (the ECDH_P* forms are handled by RE_RUST_ECDH above).\nconst RE_RUST_RING_X25519 = /\\bagreement::X25519\\b/g;\n// Bare (unqualified) constructors: a braced `use x25519_dalek::{EphemeralSecret}`\n// / `use ed25519_dalek::{SigningKey}` strips the `::` path prefix, defeating the\n// path-qualified rules above. The `(?<![:\\w])` lookbehind keeps these from\n// double-matching the qualified forms (e.g. `p256::ecdsa::SigningKey::random`).\nconst RE_RUST_BARE_X25519 = /(?<![:\\w])EphemeralSecret::new\\s*\\(/g;\nconst RE_RUST_BARE_SIGNINGKEY = /(?<![:\\w])SigningKey::(?:generate|random)\\s*\\(/g;\n// jsonwebtoken crate `Algorithm` enum variants selecting a classical JWT signer:\n// RSASSA-PKCS1 (RS*), RSASSA-PSS (PS*), ECDSA (ES*), and Ed25519 (EdDSA). The\n// `\\s*` between `Algorithm` and `::` catches the variant split across lines /\n// routed through a helper (audit token_policy false-negative); the required\n// suffix keeps it off unrelated `Algorithm::` uses (e.g. `HS256` HMAC, which is\n// symmetric and not quantum-vulnerable, or `Algorithm::new`).\nconst RE_RUST_JWT_ALG = /\\bAlgorithm\\s*::(RS|PS|ES)(?:256|384|512)\\b|\\bAlgorithm\\s*::EdDSA\\b/g;\n// Rust TLS certificate-validation bypass: reqwest `danger_accept_invalid_certs`\n// and the rustls `.dangerous()` escape hatch. Mirrors the JS tlsDetector.\nconst RE_RUST_TLS_ACCEPT_INVALID = /\\bdanger_accept_invalid_certs\\s*\\(\\s*true/g;\nconst RE_RUST_TLS_DANGEROUS = /\\.dangerous\\s*\\(\\s*\\)/g;\n\nconst RULE_RUST_RSA: RuleMeta = {\n id: \"rust-rsa\",\n title: \"Rust RSA key/usage\",\n description: \"the `rsa` crate / ring RsaKeyPair\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA (Rust) is not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_RUST_ECDSA: RuleMeta = {\n id: \"rust-ecdsa\",\n title: \"Rust ECDSA signature\",\n description: \"p256/p384/k256 ecdsa::SigningKey / ring EcdsaKeyPair\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical ECDSA signing (Rust) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_RUST_ECDH: RuleMeta = {\n id: \"rust-ecdh\",\n title: \"Rust ECDH key agreement\",\n description: \"p256/p384 ecdh::EphemeralSecret / ring agreement\",\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 (Rust) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_RUST_ED25519: RuleMeta = {\n id: \"rust-ed25519\",\n title: \"Rust Ed25519 signature\",\n description: \"ed25519-dalek SigningKey/Keypair / ring Ed25519KeyPair\",\n category: \"signature\",\n severity: \"low\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Ed25519 (Rust) is a modern but still classical signature scheme.\",\n};\nconst RULE_RUST_X25519: RuleMeta = {\n id: \"rust-x25519\",\n title: \"Rust X25519 key agreement\",\n description: \"x25519-dalek EphemeralSecret/StaticSecret\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"X25519 (Rust) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_RUST_X448: RuleMeta = {\n id: \"rust-x448\",\n title: \"Rust X448 key agreement\",\n description: \"the `x448` crate Secret key agreement\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"X448\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"X448 (Rust) is modern but still classical key agreement — harvest-now-decrypt-later.\",\n};\nconst RULE_RUST_OPENSSL_RSA: RuleMeta = {\n id: \"rust-openssl-rsa\",\n title: \"Rust openssl RSA key generation\",\n description: \"openssl crate Rsa::generate\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Generates a classical RSA key pair via the Rust `openssl` crate — not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_RUST_OPENSSL_EC: RuleMeta = {\n id: \"rust-openssl-ec\",\n title: \"Rust openssl EC key generation\",\n description: \"openssl crate EcKey::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 via the Rust `openssl` crate. 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_RUST_OPENSSL_DSA: RuleMeta = {\n id: \"rust-openssl-dsa\",\n title: \"Rust openssl DSA key/usage\",\n description: \"openssl crate Dsa::generate\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Classical DSA via the Rust `openssl` crate is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_RUST_OPENSSL_DH: RuleMeta = {\n id: \"rust-openssl-dh\",\n title: \"Rust openssl Diffie-Hellman key exchange\",\n description: \"openssl crate Dh params / key generation\",\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 via the Rust `openssl` crate is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_RUST_RING_X25519: RuleMeta = {\n id: \"rust-ring-x25519\",\n title: \"Rust ring X25519 key agreement\",\n description: \"ring agreement::X25519\",\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 key agreement via ring (Rust) is modern but still classical — harvest-now-decrypt-later.\",\n};\nconst RULE_RUST_BARE_X25519: RuleMeta = {\n id: \"rust-x25519-bare\",\n title: \"Rust X25519 key agreement (unqualified)\",\n description: \"bare EphemeralSecret::new (x25519-dalek imported via `use`)\",\n category: \"key-exchange\",\n severity: \"medium\",\n confidence: \"medium\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519 key agreement (x25519-dalek, imported unqualified) is modern but still classical — harvest-now-decrypt-later.\",\n};\nconst RULE_RUST_BARE_SIGNINGKEY: RuleMeta = {\n id: \"rust-signingkey-bare\",\n title: \"Rust signature key (unqualified)\",\n description: \"bare SigningKey::generate/random (ed25519-dalek / k256 via `use`)\",\n category: \"signature\",\n severity: \"medium\",\n confidence: \"medium\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Classical signature key from an unqualified `SigningKey` (ed25519-dalek Ed25519 / k256 ECDSA) — forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_RUST_JWT_ALGORITHM: RuleMeta = {\n id: \"rust-jwt-algorithm\",\n title: \"Rust jsonwebtoken classical signature algorithm\",\n description: \"jsonwebtoken Algorithm::{RS,PS,ES}* / Algorithm::EdDSA enum variant\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n // Representative family; refined per-finding (RS*/PS* → RSA, ES* → ECDSA, EdDSA).\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Selects a classical JWT signature algorithm (jsonwebtoken RS*/PS*/ES*/EdDSA), forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_RUST_TLS_ACCEPT_INVALID: RuleMeta = {\n id: \"rust-tls-accept-invalid-certs\",\n title: \"Rust TLS certificate verification disabled\",\n description: \"reqwest danger_accept_invalid_certs(true)\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message:\n \"danger_accept_invalid_certs(true) disables TLS certificate verification in reqwest (MITM risk).\",\n remediation: \"Remove danger_accept_invalid_certs(true); verify certificates properly.\",\n};\nconst RULE_RUST_TLS_DANGEROUS: RuleMeta = {\n id: \"rust-tls-rustls-dangerous\",\n title: \"Rust rustls dangerous certificate config\",\n description: \"rustls ClientConfig .dangerous() escape hatch\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"medium\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"rustls `.dangerous()` opts into disabling certificate verification (MITM risk).\",\n remediation: \"Avoid the dangerous() escape hatch; keep the default certificate verifier.\",\n};\n\n/**\n * Aliasable Rust crypto types (`<crate>::<OrigType>` → rule). A renamed `use`\n * (`use x25519_dalek::{EphemeralSecret as MontgomerySecret}`) binds the alias to a\n * classical-key type; a later `MontgomerySecret::<ctor>(` is that key's\n * construction. The `::`-qualified and braced rules above miss this because the\n * call site uses the renamed identifier, not the original path.\n */\nconst RUST_ALIASABLE: Record<string, RuleMeta> = {\n \"x25519_dalek::EphemeralSecret\": RULE_RUST_X25519,\n \"x25519_dalek::StaticSecret\": RULE_RUST_X25519,\n \"x448::Secret\": RULE_RUST_X448,\n \"ed25519_dalek::SigningKey\": RULE_RUST_ED25519,\n \"ed25519_dalek::Keypair\": RULE_RUST_ED25519,\n \"ed25519_dalek::SecretKey\": RULE_RUST_ED25519,\n};\n\n/** Escape a string for interpolation into a dynamically-built RegExp. */\nfunction escapeRustRe(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Collect `use <crate>::<OrigType> as <Alias>` bindings (braced or single) that\n * rename an aliasable crypto type, returning {alias, rule} pairs. An alias equal\n * to its own type name is skipped (the qualified/bare rules already catch it).\n */\nfunction collectRustTypeAliases(content: string): Array<{ alias: string; rule: RuleMeta }> {\n const out: Array<{ alias: string; rule: RuleMeta }> = [];\n const push = (crate: string, orig: string, alias: string): void => {\n if (!alias || alias === orig) return;\n const rule = RUST_ALIASABLE[`${crate}::${orig}`];\n if (rule) out.push({ alias, rule });\n };\n // Braced: `use <crate>::{ Orig as Alias, ... }`.\n const braced = /\\buse\\s+([\\w:]+)::\\{([^}]*)\\}/g;\n for (let m = braced.exec(content); m; m = braced.exec(content)) {\n const specRe = /([A-Za-z_]\\w*)\\s+as\\s+([A-Za-z_]\\w*)/g;\n for (let s = specRe.exec(m[2]); s; s = specRe.exec(m[2])) push(m[1], s[1], s[2]);\n }\n // Single: `use <crate>::Orig as Alias;`.\n const single = /\\buse\\s+([\\w:]+)::([A-Za-z_]\\w*)\\s+as\\s+([A-Za-z_]\\w*)/g;\n for (let m = single.exec(content); m; m = single.exec(content)) push(m[1], m[2], m[3]);\n return out;\n}\n\n/** Detects classical asymmetric crypto in Rust (rsa, ring, dalek, p256/k256). */\nexport const rustDetector: Detector = {\n id: \"rust-crypto\",\n description: \"Classical asymmetric crypto in Rust (rsa, ring, *-dalek, p256/k256)\",\n scope: \"source\",\n language: \"rust\",\n rules: [\n RULE_RUST_RSA,\n RULE_RUST_ECDSA,\n RULE_RUST_ECDH,\n RULE_RUST_ED25519,\n RULE_RUST_X25519,\n RULE_RUST_X448,\n RULE_RUST_OPENSSL_RSA,\n RULE_RUST_OPENSSL_EC,\n RULE_RUST_OPENSSL_DSA,\n RULE_RUST_OPENSSL_DH,\n RULE_RUST_RING_X25519,\n RULE_RUST_BARE_X25519,\n RULE_RUST_BARE_SIGNINGKEY,\n RULE_RUST_JWT_ALGORITHM,\n RULE_RUST_TLS_ACCEPT_INVALID,\n RULE_RUST_TLS_DANGEROUS,\n ],\n appliesTo: (f) => hasExtension(f, RUST_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_RUST_RSA, RULE_RUST_RSA);\n add(RE_RUST_ECDSA, RULE_RUST_ECDSA);\n add(RE_RUST_ECDH, RULE_RUST_ECDH);\n add(RE_RUST_ED25519, RULE_RUST_ED25519);\n add(RE_RUST_X25519, RULE_RUST_X25519);\n add(RE_RUST_OPENSSL_RSA, RULE_RUST_OPENSSL_RSA);\n add(RE_RUST_OPENSSL_EC, RULE_RUST_OPENSSL_EC);\n add(RE_RUST_OPENSSL_DSA, RULE_RUST_OPENSSL_DSA);\n add(RE_RUST_OPENSSL_DH, RULE_RUST_OPENSSL_DH);\n add(RE_RUST_RING_X25519, RULE_RUST_RING_X25519);\n add(RE_RUST_BARE_X25519, RULE_RUST_BARE_X25519);\n add(RE_RUST_BARE_SIGNINGKEY, RULE_RUST_BARE_SIGNINGKEY);\n // jsonwebtoken Algorithm enum variants — resolve the family per match: the\n // RS*/PS* variants are RSASSA (RSA), ES* is ECDSA, EdDSA is Ed25519.\n eachMatch(RE_RUST_JWT_ALG, content, (m) => {\n const prefix = m[1];\n const algorithm: AlgorithmFamily =\n prefix === undefined ? \"EdDSA\" : prefix === \"ES\" ? \"ECDSA\" : \"RSA\";\n findings.push(\n findingFromRule(\n RULE_RUST_JWT_ALGORITHM,\n { file, content, index: m.index, matchLength: m[0].length },\n { algorithm },\n ),\n );\n });\n add(RE_RUST_TLS_ACCEPT_INVALID, RULE_RUST_TLS_ACCEPT_INVALID);\n add(RE_RUST_TLS_DANGEROUS, RULE_RUST_TLS_DANGEROUS);\n\n // Type-alias resolution: `use x25519_dalek::{EphemeralSecret as MontgomerySecret}`\n // then `MontgomerySecret::random_from_rng(` — the braced+renamed `use` defeats\n // the `::`-qualified rules. Match the aliased type's construction calls; runs\n // on the ORIGINAL content so locations stay exact, and fires only for an alias\n // explicitly bound to a known crypto type (precision-safe).\n for (const { alias, rule } of collectRustTypeAliases(content)) {\n const a = escapeRustRe(alias);\n add(\n new RegExp(`\\\\b${a}::(?:new|random|random_from_rng|generate|from_bytes)\\\\s*\\\\(`, \"g\"),\n rule,\n );\n }\n return findings;\n },\n};\n"]}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Config detector: secrets encrypted at rest with classical asymmetric key
3
+ * wrapping. This is the purest "harvest now, decrypt later" surface — the
4
+ * ciphertext is often committed to a git repository, which means it is already
5
+ * replicated, effectively immortal, and retroactively un-fixable (you can
6
+ * re-encrypt HEAD, not history). Every recipient key here is classical.
7
+ *
8
+ * Covered:
9
+ * - Mozilla SOPS / age recipients: `age1…` bech32 public keys (X25519 key
10
+ * agreement wrapping the data key).
11
+ * - PGP-encrypted payloads: `-----BEGIN PGP MESSAGE-----` (RSA/ElGamal ESK).
12
+ * - Bitnami Sealed Secrets: `kind: SealedSecret` (controller wraps with RSA-OAEP).
13
+ *
14
+ * Symmetric-only schemes (ansible-vault AES, age with a scrypt passphrase) are
15
+ * intentionally NOT flagged: a strong symmetric key is only Grover-weakened, not
16
+ * broken, so it is out of scope for a *classical-asymmetric* readiness signal.
17
+ */
18
+ import type { Detector } from "../types.js";
19
+ /** Detects secrets encrypted at rest with classical asymmetric key wrapping. */
20
+ export declare const secretsDetector: Detector;
21
+ //# sourceMappingURL=secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/detectors/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAmE/D,gFAAgF;AAChF,eAAO,MAAM,eAAe,EAAE,QA4B7B,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { DOC_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
2
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
3
+ const SECRET_RULES = [
4
+ {
5
+ // age/SOPS recipient: `age1` + 58 bech32 chars. Distinctive enough for any file.
6
+ re: /\bage1[0-9a-z]{58}\b/g,
7
+ meta: {
8
+ id: "secrets-age-recipient",
9
+ title: "age / SOPS recipient (X25519)",
10
+ description: "An age (SOPS) recipient public key wraps secrets with classical X25519",
11
+ category: "key-exchange",
12
+ severity: "high",
13
+ confidence: "high",
14
+ algorithm: "X25519",
15
+ hndl: true,
16
+ cwe: CWE_BROKEN_CRYPTO,
17
+ message: "Secrets are wrapped to an age/SOPS X25519 recipient (classical key agreement); harvest-now-decrypt-later exposed, and if committed to git the ciphertext is retroactively un-fixable.",
18
+ remediation: "Track a post-quantum age recipient / KMS (ML-KEM) and re-encrypt; rotate any secret whose ciphertext has left your control.",
19
+ },
20
+ },
21
+ {
22
+ re: /-----BEGIN PGP MESSAGE-----/g,
23
+ meta: {
24
+ id: "secrets-pgp-message",
25
+ title: "PGP-encrypted secret (RSA/ElGamal)",
26
+ description: "A PGP MESSAGE block: the session key is wrapped with classical RSA/ElGamal",
27
+ category: "kem",
28
+ severity: "high",
29
+ confidence: "high",
30
+ algorithm: "RSA",
31
+ hndl: true,
32
+ cwe: CWE_BROKEN_CRYPTO,
33
+ message: "A PGP-encrypted secret whose session key is wrapped with classical RSA/ElGamal; harvest-now-decrypt-later exposed.",
34
+ remediation: "Re-encrypt with a post-quantum KEM (ML-KEM-768) once available; rotate the underlying secret.",
35
+ },
36
+ },
37
+ {
38
+ re: /\bkind:\s*["']?SealedSecret\b/g,
39
+ meta: {
40
+ id: "secrets-sealed-secret",
41
+ title: "Bitnami Sealed Secret (RSA-OAEP)",
42
+ description: "A SealedSecret is wrapped by the controller's classical RSA-OAEP key",
43
+ category: "kem",
44
+ severity: "high",
45
+ confidence: "high",
46
+ algorithm: "RSA",
47
+ hndl: true,
48
+ cwe: CWE_BROKEN_CRYPTO,
49
+ message: "A Bitnami SealedSecret is wrapped with the controller's classical RSA-OAEP key; harvest-now-decrypt-later exposed, and typically committed to git.",
50
+ remediation: "Plan migration as sealed-secrets adds PQC support; rotate the sealing key and secrets when it does.",
51
+ },
52
+ },
53
+ ];
54
+ /** Detects secrets encrypted at rest with classical asymmetric key wrapping. */
55
+ export const secretsDetector = {
56
+ id: "secrets-at-rest",
57
+ description: "Secrets wrapped at rest with classical asymmetric crypto (SOPS/age, PGP, Sealed Secrets)",
58
+ scope: "config",
59
+ language: "any",
60
+ rules: SECRET_RULES.map((r) => r.meta),
61
+ // Skip prose/docs: a tutorial showing an example age recipient is not a secret store.
62
+ appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
63
+ detect({ file, content }) {
64
+ // Fast reject: none of the distinctive markers present.
65
+ if (!content.includes("age1") &&
66
+ !content.includes("BEGIN PGP MESSAGE") &&
67
+ !content.includes("SealedSecret")) {
68
+ return [];
69
+ }
70
+ const findings = [];
71
+ for (const rule of SECRET_RULES) {
72
+ eachMatch(rule.re, content, (m) => {
73
+ findings.push(findingFromRule(rule.meta, { file, content, index: m.index, matchLength: m[0].length }));
74
+ });
75
+ }
76
+ return findings;
77
+ },
78
+ };
79
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/detectors/secrets.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAO9C,MAAM,YAAY,GAAiB;IACjC;QACE,iFAAiF;QACjF,EAAE,EAAE,uBAAuB;QAC3B,IAAI,EAAE;YACJ,EAAE,EAAE,uBAAuB;YAC3B,KAAK,EAAE,+BAA+B;YACtC,WAAW,EAAE,wEAAwE;YACrF,QAAQ,EAAE,cAAc;YACxB,QAAQ,EAAE,MAAM;YAChB,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,iBAAiB;YACtB,OAAO,EACL,uLAAuL;YACzL,WAAW,EACT,6HAA6H;SAChI;KACF;IACD;QACE,EAAE,EAAE,8BAA8B;QAClC,IAAI,EAAE;YACJ,EAAE,EAAE,qBAAqB;YACzB,KAAK,EAAE,oCAAoC;YAC3C,WAAW,EAAE,4EAA4E;YACzF,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,MAAM;YAChB,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,iBAAiB;YACtB,OAAO,EACL,oHAAoH;YACtH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AE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CACxF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Config detector: secrets encrypted at rest with classical asymmetric key\n * wrapping. This is the purest \"harvest now, decrypt later\" surface — the\n * ciphertext is often committed to a git repository, which means it is already\n * replicated, effectively immortal, and retroactively un-fixable (you can\n * re-encrypt HEAD, not history). Every recipient key here is classical.\n *\n * Covered:\n * - Mozilla SOPS / age recipients: `age1…` bech32 public keys (X25519 key\n * agreement wrapping the data key).\n * - PGP-encrypted payloads: `-----BEGIN PGP MESSAGE-----` (RSA/ElGamal ESK).\n * - Bitnami Sealed Secrets: `kind: SealedSecret` (controller wraps with RSA-OAEP).\n *\n * Symmetric-only schemes (ansible-vault AES, age with a scrypt passphrase) are\n * intentionally NOT flagged: a strong symmetric key is only Grover-weakened, not\n * broken, so it is out of scope for a *classical-asymmetric* readiness signal.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { DOC_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO } from \"../cwe.js\";\n\ninterface SecretRule {\n re: RegExp;\n meta: RuleMeta;\n}\n\nconst SECRET_RULES: SecretRule[] = [\n {\n // age/SOPS recipient: `age1` + 58 bech32 chars. Distinctive enough for any file.\n re: /\\bage1[0-9a-z]{58}\\b/g,\n meta: {\n id: \"secrets-age-recipient\",\n title: \"age / SOPS recipient (X25519)\",\n description: \"An age (SOPS) recipient public key wraps secrets with classical X25519\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"Secrets are wrapped to an age/SOPS X25519 recipient (classical key agreement); harvest-now-decrypt-later exposed, and if committed to git the ciphertext is retroactively un-fixable.\",\n remediation:\n \"Track a post-quantum age recipient / KMS (ML-KEM) and re-encrypt; rotate any secret whose ciphertext has left your control.\",\n },\n },\n {\n re: /-----BEGIN PGP MESSAGE-----/g,\n meta: {\n id: \"secrets-pgp-message\",\n title: \"PGP-encrypted secret (RSA/ElGamal)\",\n description: \"A PGP MESSAGE block: the session key is wrapped with classical RSA/ElGamal\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"A PGP-encrypted secret whose session key is wrapped with classical RSA/ElGamal; harvest-now-decrypt-later exposed.\",\n remediation:\n \"Re-encrypt with a post-quantum KEM (ML-KEM-768) once available; rotate the underlying secret.\",\n },\n },\n {\n re: /\\bkind:\\s*[\"']?SealedSecret\\b/g,\n meta: {\n id: \"secrets-sealed-secret\",\n title: \"Bitnami Sealed Secret (RSA-OAEP)\",\n description: \"A SealedSecret is wrapped by the controller's classical RSA-OAEP key\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"A Bitnami SealedSecret is wrapped with the controller's classical RSA-OAEP key; harvest-now-decrypt-later exposed, and typically committed to git.\",\n remediation:\n \"Plan migration as sealed-secrets adds PQC support; rotate the sealing key and secrets when it does.\",\n },\n },\n];\n\n/** Detects secrets encrypted at rest with classical asymmetric key wrapping. */\nexport const secretsDetector: Detector = {\n id: \"secrets-at-rest\",\n description:\n \"Secrets wrapped at rest with classical asymmetric crypto (SOPS/age, PGP, Sealed Secrets)\",\n scope: \"config\",\n language: \"any\",\n rules: SECRET_RULES.map((r) => r.meta),\n // Skip prose/docs: a tutorial showing an example age recipient is not a secret store.\n appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),\n detect({ file, content }): Finding[] {\n // Fast reject: none of the distinctive markers present.\n if (\n !content.includes(\"age1\") &&\n !content.includes(\"BEGIN PGP MESSAGE\") &&\n !content.includes(\"SealedSecret\")\n ) {\n return [];\n }\n const findings: Finding[] = [];\n for (const rule of SECRET_RULES) {\n eachMatch(rule.re, content, (m) => {\n findings.push(\n findingFromRule(rule.meta, { file, content, index: m.index, matchLength: m[0].length }),\n );\n });\n }\n return findings;\n },\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/detectors/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AA82B/D,0DAA0D;AAC1D,eAAO,MAAM,eAAe,EAAE,QAAQ,EAOrC,CAAC"}
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/detectors/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAmqC/D,0DAA0D;AAC1D,eAAO,MAAM,eAAe,EAAE,QAAQ,EAQrC,CAAC"}