@quantakrypto/core 0.4.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/README.md +76 -27
  2. package/dist/cbom-merge.d.ts.map +1 -1
  3. package/dist/cbom-merge.js +30 -8
  4. package/dist/cbom-merge.js.map +1 -1
  5. package/dist/cbom.d.ts +5 -0
  6. package/dist/cbom.d.ts.map +1 -1
  7. package/dist/cbom.js +132 -37
  8. package/dist/cbom.js.map +1 -1
  9. package/dist/comments.d.ts +2 -23
  10. package/dist/comments.d.ts.map +1 -1
  11. package/dist/comments.js +24 -5
  12. package/dist/comments.js.map +1 -1
  13. package/dist/crypto-agility.d.ts +158 -0
  14. package/dist/crypto-agility.d.ts.map +1 -0
  15. package/dist/crypto-agility.js +285 -0
  16. package/dist/crypto-agility.js.map +1 -0
  17. package/dist/dependencies.d.ts.map +1 -1
  18. package/dist/dependencies.js +180 -18
  19. package/dist/dependencies.js.map +1 -1
  20. package/dist/detect-utils.d.ts +55 -21
  21. package/dist/detect-utils.d.ts.map +1 -1
  22. package/dist/detect-utils.js +133 -7
  23. package/dist/detect-utils.js.map +1 -1
  24. package/dist/detectors/age.d.ts +16 -0
  25. package/dist/detectors/age.d.ts.map +1 -0
  26. package/dist/detectors/age.js +40 -0
  27. package/dist/detectors/age.js.map +1 -0
  28. package/dist/detectors/ansible.d.ts +13 -0
  29. package/dist/detectors/ansible.d.ts.map +1 -0
  30. package/dist/detectors/ansible.js +108 -0
  31. package/dist/detectors/ansible.js.map +1 -0
  32. package/dist/detectors/bicep.d.ts +20 -0
  33. package/dist/detectors/bicep.d.ts.map +1 -0
  34. package/dist/detectors/bicep.js +74 -0
  35. package/dist/detectors/bicep.js.map +1 -0
  36. package/dist/detectors/c.d.ts.map +1 -1
  37. package/dist/detectors/c.js +30 -3
  38. package/dist/detectors/c.js.map +1 -1
  39. package/dist/detectors/cicd.d.ts.map +1 -1
  40. package/dist/detectors/cicd.js +18 -5
  41. package/dist/detectors/cicd.js.map +1 -1
  42. package/dist/detectors/cloud-kms.d.ts +8 -5
  43. package/dist/detectors/cloud-kms.d.ts.map +1 -1
  44. package/dist/detectors/cloud-kms.js +62 -20
  45. package/dist/detectors/cloud-kms.js.map +1 -1
  46. package/dist/detectors/cloudformation.d.ts +8 -0
  47. package/dist/detectors/cloudformation.d.ts.map +1 -1
  48. package/dist/detectors/cloudformation.js +41 -10
  49. package/dist/detectors/cloudformation.js.map +1 -1
  50. package/dist/detectors/codesign.d.ts +50 -0
  51. package/dist/detectors/codesign.d.ts.map +1 -0
  52. package/dist/detectors/codesign.js +143 -0
  53. package/dist/detectors/codesign.js.map +1 -0
  54. package/dist/detectors/csharp.d.ts.map +1 -1
  55. package/dist/detectors/csharp.js +13 -3
  56. package/dist/detectors/csharp.js.map +1 -1
  57. package/dist/detectors/dart.d.ts +35 -0
  58. package/dist/detectors/dart.d.ts.map +1 -0
  59. package/dist/detectors/dart.js +177 -0
  60. package/dist/detectors/dart.js.map +1 -0
  61. package/dist/detectors/database.d.ts +5 -3
  62. package/dist/detectors/database.d.ts.map +1 -1
  63. package/dist/detectors/database.js +45 -8
  64. package/dist/detectors/database.js.map +1 -1
  65. package/dist/detectors/dkim.d.ts +54 -0
  66. package/dist/detectors/dkim.d.ts.map +1 -0
  67. package/dist/detectors/dkim.js +92 -0
  68. package/dist/detectors/dkim.js.map +1 -0
  69. package/dist/detectors/dnssec.d.ts.map +1 -1
  70. package/dist/detectors/dnssec.js +19 -10
  71. package/dist/detectors/dnssec.js.map +1 -1
  72. package/dist/detectors/elixir.d.ts.map +1 -1
  73. package/dist/detectors/elixir.js +34 -2
  74. package/dist/detectors/elixir.js.map +1 -1
  75. package/dist/detectors/java.d.ts.map +1 -1
  76. package/dist/detectors/java.js +33 -3
  77. package/dist/detectors/java.js.map +1 -1
  78. package/dist/detectors/jose.d.ts.map +1 -1
  79. package/dist/detectors/jose.js +13 -3
  80. package/dist/detectors/jose.js.map +1 -1
  81. package/dist/detectors/jwk.d.ts +7 -7
  82. package/dist/detectors/jwk.d.ts.map +1 -1
  83. package/dist/detectors/jwk.js +44 -8
  84. package/dist/detectors/jwk.js.map +1 -1
  85. package/dist/detectors/k8s.d.ts.map +1 -1
  86. package/dist/detectors/k8s.js +5 -2
  87. package/dist/detectors/k8s.js.map +1 -1
  88. package/dist/detectors/keystore.d.ts +19 -0
  89. package/dist/detectors/keystore.d.ts.map +1 -0
  90. package/dist/detectors/keystore.js +76 -0
  91. package/dist/detectors/keystore.js.map +1 -0
  92. package/dist/detectors/mesh.d.ts +7 -8
  93. package/dist/detectors/mesh.d.ts.map +1 -1
  94. package/dist/detectors/mesh.js +17 -35
  95. package/dist/detectors/mesh.js.map +1 -1
  96. package/dist/detectors/messaging.d.ts +2 -2
  97. package/dist/detectors/messaging.d.ts.map +1 -1
  98. package/dist/detectors/messaging.js +19 -12
  99. package/dist/detectors/messaging.js.map +1 -1
  100. package/dist/detectors/objc.d.ts +41 -0
  101. package/dist/detectors/objc.d.ts.map +1 -0
  102. package/dist/detectors/objc.js +146 -0
  103. package/dist/detectors/objc.js.map +1 -0
  104. package/dist/detectors/openpgp.d.ts +20 -0
  105. package/dist/detectors/openpgp.d.ts.map +1 -0
  106. package/dist/detectors/openpgp.js +151 -0
  107. package/dist/detectors/openpgp.js.map +1 -0
  108. package/dist/detectors/pem.d.ts.map +1 -1
  109. package/dist/detectors/pem.js +32 -0
  110. package/dist/detectors/pem.js.map +1 -1
  111. package/dist/detectors/php.d.ts +2 -1
  112. package/dist/detectors/php.d.ts.map +1 -1
  113. package/dist/detectors/php.js +7 -3
  114. package/dist/detectors/php.js.map +1 -1
  115. package/dist/detectors/pkcs11.d.ts +17 -0
  116. package/dist/detectors/pkcs11.d.ts.map +1 -0
  117. package/dist/detectors/pkcs11.js +87 -0
  118. package/dist/detectors/pkcs11.js.map +1 -0
  119. package/dist/detectors/proxy.d.ts +52 -0
  120. package/dist/detectors/proxy.d.ts.map +1 -0
  121. package/dist/detectors/proxy.js +157 -0
  122. package/dist/detectors/proxy.js.map +1 -0
  123. package/dist/detectors/pulumi.d.ts +19 -0
  124. package/dist/detectors/pulumi.d.ts.map +1 -0
  125. package/dist/detectors/pulumi.js +80 -0
  126. package/dist/detectors/pulumi.js.map +1 -0
  127. package/dist/detectors/rust.d.ts.map +1 -1
  128. package/dist/detectors/rust.js +5 -0
  129. package/dist/detectors/rust.js.map +1 -1
  130. package/dist/detectors/secrets.d.ts +4 -1
  131. package/dist/detectors/secrets.d.ts.map +1 -1
  132. package/dist/detectors/secrets.js +5 -21
  133. package/dist/detectors/secrets.js.map +1 -1
  134. package/dist/detectors/solidity.d.ts +50 -0
  135. package/dist/detectors/solidity.d.ts.map +1 -0
  136. package/dist/detectors/solidity.js +108 -0
  137. package/dist/detectors/solidity.js.map +1 -0
  138. package/dist/detectors/source.d.ts.map +1 -1
  139. package/dist/detectors/source.js +105 -6
  140. package/dist/detectors/source.js.map +1 -1
  141. package/dist/detectors/spire.d.ts +49 -0
  142. package/dist/detectors/spire.d.ts.map +1 -0
  143. package/dist/detectors/spire.js +77 -0
  144. package/dist/detectors/spire.js.map +1 -0
  145. package/dist/detectors/ssh-ca.d.ts +72 -0
  146. package/dist/detectors/ssh-ca.d.ts.map +1 -0
  147. package/dist/detectors/ssh-ca.js +119 -0
  148. package/dist/detectors/ssh-ca.js.map +1 -0
  149. package/dist/detectors/supply-chain.d.ts +17 -0
  150. package/dist/detectors/supply-chain.d.ts.map +1 -0
  151. package/dist/detectors/supply-chain.js +89 -0
  152. package/dist/detectors/supply-chain.js.map +1 -0
  153. package/dist/detectors/swift.d.ts +22 -0
  154. package/dist/detectors/swift.d.ts.map +1 -0
  155. package/dist/detectors/swift.js +120 -0
  156. package/dist/detectors/swift.js.map +1 -0
  157. package/dist/detectors/terraform.d.ts.map +1 -1
  158. package/dist/detectors/terraform.js +35 -8
  159. package/dist/detectors/terraform.js.map +1 -1
  160. package/dist/detectors/vault.d.ts +15 -0
  161. package/dist/detectors/vault.d.ts.map +1 -0
  162. package/dist/detectors/vault.js +97 -0
  163. package/dist/detectors/vault.js.map +1 -0
  164. package/dist/detectors/vpn.d.ts +8 -8
  165. package/dist/detectors/vpn.d.ts.map +1 -1
  166. package/dist/detectors/vpn.js +12 -38
  167. package/dist/detectors/vpn.js.map +1 -1
  168. package/dist/detectors/weak-hash.d.ts +71 -0
  169. package/dist/detectors/weak-hash.d.ts.map +1 -0
  170. package/dist/detectors/weak-hash.js +116 -0
  171. package/dist/detectors/weak-hash.js.map +1 -0
  172. package/dist/detectors/webauthn.d.ts +61 -0
  173. package/dist/detectors/webauthn.d.ts.map +1 -0
  174. package/dist/detectors/webauthn.js +109 -0
  175. package/dist/detectors/webauthn.js.map +1 -0
  176. package/dist/detectors/xmldsig.d.ts +23 -0
  177. package/dist/detectors/xmldsig.d.ts.map +1 -0
  178. package/dist/detectors/xmldsig.js +84 -0
  179. package/dist/detectors/xmldsig.js.map +1 -0
  180. package/dist/evidence.d.ts +74 -4
  181. package/dist/evidence.d.ts.map +1 -1
  182. package/dist/evidence.js +71 -0
  183. package/dist/evidence.js.map +1 -1
  184. package/dist/hndl.d.ts +241 -0
  185. package/dist/hndl.d.ts.map +1 -0
  186. package/dist/hndl.js +752 -0
  187. package/dist/hndl.js.map +1 -0
  188. package/dist/index.d.ts +18 -11
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +21 -11
  191. package/dist/index.js.map +1 -1
  192. package/dist/inventory.d.ts +0 -2
  193. package/dist/inventory.d.ts.map +1 -1
  194. package/dist/inventory.js +15 -6
  195. package/dist/inventory.js.map +1 -1
  196. package/dist/parallel.d.ts.map +1 -1
  197. package/dist/parallel.js +22 -23
  198. package/dist/parallel.js.map +1 -1
  199. package/dist/registry.d.ts +9 -4
  200. package/dist/registry.d.ts.map +1 -1
  201. package/dist/registry.js +51 -4
  202. package/dist/registry.js.map +1 -1
  203. package/dist/remediate-pipeline.d.ts +0 -3
  204. package/dist/remediate-pipeline.d.ts.map +1 -1
  205. package/dist/remediate-pipeline.js +1 -1
  206. package/dist/remediate-pipeline.js.map +1 -1
  207. package/dist/remediation.d.ts +10 -0
  208. package/dist/remediation.d.ts.map +1 -1
  209. package/dist/remediation.js +32 -0
  210. package/dist/remediation.js.map +1 -1
  211. package/dist/report.d.ts +17 -0
  212. package/dist/report.d.ts.map +1 -1
  213. package/dist/report.js +106 -20
  214. package/dist/report.js.map +1 -1
  215. package/dist/scan-worker.js +5 -3
  216. package/dist/scan-worker.js.map +1 -1
  217. package/dist/scan.d.ts.map +1 -1
  218. package/dist/scan.js +35 -6
  219. package/dist/scan.js.map +1 -1
  220. package/dist/standards-profiles.d.ts +58 -0
  221. package/dist/standards-profiles.d.ts.map +1 -0
  222. package/dist/standards-profiles.js +100 -0
  223. package/dist/standards-profiles.js.map +1 -0
  224. package/dist/types.d.ts +7 -6
  225. package/dist/types.d.ts.map +1 -1
  226. package/dist/types.js.map +1 -1
  227. package/dist/version.d.ts +1 -1
  228. package/dist/version.js +1 -1
  229. package/dist/version.js.map +1 -1
  230. package/dist/vex.d.ts +39 -0
  231. package/dist/vex.d.ts.map +1 -0
  232. package/dist/vex.js +87 -0
  233. package/dist/vex.js.map +1 -0
  234. package/dist/walk.d.ts +39 -4
  235. package/dist/walk.d.ts.map +1 -1
  236. package/dist/walk.js +62 -10
  237. package/dist/walk.js.map +1 -1
  238. package/package.json +1 -1
  239. package/src/cbom-merge.ts +38 -8
  240. package/src/cbom.ts +153 -39
  241. package/src/comments.ts +25 -6
  242. package/src/crypto-agility.ts +407 -0
  243. package/src/dependencies.ts +182 -16
  244. package/src/detect-utils.ts +133 -11
  245. package/src/detectors/age.ts +60 -0
  246. package/src/detectors/ansible.ts +140 -0
  247. package/src/detectors/bicep.ts +107 -0
  248. package/src/detectors/c.ts +31 -3
  249. package/src/detectors/cicd.ts +18 -5
  250. package/src/detectors/cloud-kms.ts +79 -25
  251. package/src/detectors/cloudformation.ts +45 -10
  252. package/src/detectors/codesign.ts +214 -0
  253. package/src/detectors/csharp.ts +13 -3
  254. package/src/detectors/dart.ts +237 -0
  255. package/src/detectors/database.ts +64 -11
  256. package/src/detectors/dkim.ts +172 -0
  257. package/src/detectors/dnssec.ts +19 -10
  258. package/src/detectors/elixir.ts +33 -2
  259. package/src/detectors/java.ts +37 -3
  260. package/src/detectors/jose.ts +19 -3
  261. package/src/detectors/jwk.ts +59 -17
  262. package/src/detectors/k8s.ts +5 -2
  263. package/src/detectors/keystore.ts +109 -0
  264. package/src/detectors/mesh.ts +21 -45
  265. package/src/detectors/messaging.ts +22 -14
  266. package/src/detectors/objc.ts +209 -0
  267. package/src/detectors/openpgp.ts +194 -0
  268. package/src/detectors/pem.ts +30 -0
  269. package/src/detectors/php.ts +9 -4
  270. package/src/detectors/pkcs11.ts +113 -0
  271. package/src/detectors/proxy.ts +236 -0
  272. package/src/detectors/pulumi.ts +106 -0
  273. package/src/detectors/rust.ts +5 -0
  274. package/src/detectors/secrets.ts +15 -26
  275. package/src/detectors/solidity.ts +176 -0
  276. package/src/detectors/source.ts +110 -5
  277. package/src/detectors/spire.ts +143 -0
  278. package/src/detectors/ssh-ca.ts +215 -0
  279. package/src/detectors/supply-chain.ts +117 -0
  280. package/src/detectors/swift.ts +149 -0
  281. package/src/detectors/terraform.ts +42 -8
  282. package/src/detectors/vault.ts +120 -0
  283. package/src/detectors/vpn.ts +20 -48
  284. package/src/detectors/weak-hash.ts +217 -0
  285. package/src/detectors/webauthn.ts +205 -0
  286. package/src/detectors/xmldsig.ts +115 -0
  287. package/src/evidence.ts +127 -4
  288. package/src/hndl.ts +1012 -0
  289. package/src/index.ts +93 -13
  290. package/src/inventory.ts +15 -7
  291. package/src/parallel.ts +21 -20
  292. package/src/registry.ts +51 -4
  293. package/src/remediate-pipeline.ts +1 -1
  294. package/src/remediation.ts +39 -0
  295. package/src/report.ts +120 -20
  296. package/src/scan-worker.ts +5 -3
  297. package/src/scan.ts +41 -6
  298. package/src/standards-profiles.ts +136 -0
  299. package/src/types.ts +18 -5
  300. package/src/version.ts +1 -1
  301. package/src/vex.ts +122 -0
  302. package/src/walk.ts +80 -12
@@ -1,4 +1,4 @@
1
- import { eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
1
+ import { eachMatch, findingFromRule, hasExtension, maskCommentLines } from "../detect-utils.js";
2
2
  import { CWE_BROKEN_CRYPTO, CWE_WEAK_STRENGTH } from "../cwe.js";
3
3
  const CFN_EXTENSIONS = [".json", ".yaml", ".yml"];
4
4
  // Fast-reject markers: at least one must appear before any rule regex runs, so
@@ -10,22 +10,44 @@ const CFN_MARKERS = [
10
10
  "AWSTemplateFormatVersion",
11
11
  "MinimumProtocolVersion",
12
12
  "Microsoft.KeyVault",
13
- '"SslPolicy"',
13
+ "SslPolicy", // unquoted so a YAML `SslPolicy:` key also gates the file in, not just JSON
14
14
  ];
15
+ /**
16
+ * True when the content looks like a CloudFormation / ARM deployment template (one
17
+ * of the {@link CFN_MARKERS} is present).
18
+ */
19
+ function isCloudTemplate(content) {
20
+ return CFN_MARKERS.some((marker) => content.includes(marker));
21
+ }
22
+ /**
23
+ * True when a file is one THIS detector actually scans (a `.json`/`.yaml`/`.yml`
24
+ * template). The `cloud-kms` and `jwk` detectors defer to this detector ONLY on
25
+ * such files — deferring on any extension that merely contains a marker string
26
+ * (e.g. a `.ts` with an `AWS::KMS` comment) would drop a real finding, since this
27
+ * detector never runs there.
28
+ */
29
+ export function isCloudTemplateFile(file, content) {
30
+ return hasExtension(file, CFN_EXTENSIONS) && isCloudTemplate(content);
31
+ }
15
32
  // Each attribute is matched with an optional quote around the key and `:` as
16
33
  // the separator (both plain-JSON and YAML-block-scalar forms use `:`). The
17
34
  // `(?<![\w"-])` lookbehind stops a longer/prefixed attribute name from
18
35
  // matching on its suffix.
19
- const RE_CFN_KMS_RSA = /(?<![\w"-])"?KeySpec"?\s*:\s*"?RSA_\d+"?/g;
20
- const RE_CFN_KMS_EC = /(?<![\w"-])"?KeySpec"?\s*:\s*"?ECC_[A-Z0-9_]+"?/g;
36
+ // Match all three AWS KMS spec-key spellings so this detector fully owns KMS keys
37
+ // inside a template (KeySpec, the KeyPair variant, and the legacy CustomerMasterKeySpec).
38
+ const RE_CFN_KMS_RSA = /(?<![\w"-])"?(?:KeySpec|KeyPairSpec|CustomerMasterKeySpec)"?\s*:\s*"?RSA_\d+"?/g;
39
+ const RE_CFN_KMS_EC = /(?<![\w"-])"?(?:KeySpec|KeyPairSpec|CustomerMasterKeySpec)"?\s*:\s*"?ECC_[A-Z0-9_]+"?/g;
21
40
  const RE_CFN_ACM_RSA = /(?<![\w"-])"?KeyAlgorithm"?\s*:\s*"?RSA_\d+"?/g;
22
41
  const RE_CFN_ACM_EC = /(?<![\w"-])"?KeyAlgorithm"?\s*:\s*"?EC_[A-Za-z0-9]+"?/g;
23
42
  // CloudFront: only the pre-2018 "TLSv1" / "TLSv1_2016" / "TLSv1.1_2016"
24
43
  // values are legacy; the lookahead delimiter stops this from matching a
25
44
  // "TLSv1.2_2018"-style value that merely starts with the same prefix.
26
- const RE_CFN_CLOUDFRONT_TLS = /(?<![\w"-])"?MinimumProtocolVersion"?\s*:\s*"?(?:TLSv1(?:\.1)?_2016|TLSv1)(?=["'\s,}]|$)/gm;
27
- // ELB/ALB legacy SSL negotiation policies (named, dated policy strings).
28
- const RE_CFN_ELB_TLS = /(?<![\w"-])"?SslPolicy"?\s*:\s*"ELBSecurityPolicy-(?:2016-08|TLS-1-0-\d{4}-\d{2}|TLS-1-1-\d{4}-\d{2})"/g;
45
+ const RE_CFN_CLOUDFRONT_TLS = /(?<![\w"-])"?MinimumProtocolVersion"?\s*:\s*"?(?:TLSv1(?:\.1)?_2016|TLSv1|SSLv3)(?=["'\s,}]|$)/gm;
46
+ // ELB/ALB legacy SSL negotiation policies (named, dated policy strings). The value
47
+ // quote is optional (`"?`) so YAML block scalars (`SslPolicy: ELBSecurityPolicy-...`)
48
+ // match too, with a delimiter lookahead so a longer/newer policy name that merely
49
+ // shares the prefix is not matched.
50
+ const RE_CFN_ELB_TLS = /(?<![\w"-])"?SslPolicy"?\s*:\s*"?ELBSecurityPolicy-(?:2016-08|TLS-1-0-\d{4}-\d{2}|TLS-1-1-\d{4}-\d{2})(?=["'\s,}]|$)/g;
29
51
  // Azure ARM Microsoft.KeyVault key resource `properties.kty`.
30
52
  const RE_CFN_ARM_KV_RSA = /(?<![\w"-])"?kty"?\s*:\s*"?RSA"?(?!\w)/g;
31
53
  const RE_CFN_ARM_KV_EC = /(?<![\w"-])"?kty"?\s*:\s*"?EC"?(?!\w)/g;
@@ -154,16 +176,25 @@ export const cloudformationDetector = {
154
176
  detect({ file, content }) {
155
177
  if (!CFN_MARKERS.some((marker) => content.includes(marker)))
156
178
  return [];
179
+ // Mask whole `#` comment lines (YAML CFN/ARM templates ship large commented-out
180
+ // blocks); harmless for JSON, which has no comments. Offsets preserved so finding
181
+ // locations stay exact. `.yaml`/`.json` are not centrally comment-stripped.
182
+ const scan = maskCommentLines(content, ["#"]);
157
183
  const findings = [];
158
- const add = (re, rule) => eachMatch(re, content, (m) => findings.push(findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length })));
184
+ const add = (re, rule) => eachMatch(re, scan, (m) => findings.push(findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length })));
159
185
  add(RE_CFN_KMS_RSA, RULE_CFN_KMS_RSA);
160
186
  add(RE_CFN_KMS_EC, RULE_CFN_KMS_EC);
161
187
  add(RE_CFN_ACM_RSA, RULE_CFN_ACM_RSA);
162
188
  add(RE_CFN_ACM_EC, RULE_CFN_ACM_EC);
163
189
  add(RE_CFN_CLOUDFRONT_TLS, RULE_CFN_CLOUDFRONT_TLS);
164
190
  add(RE_CFN_ELB_TLS, RULE_CFN_ELB_TLS);
165
- add(RE_CFN_ARM_KV_RSA, RULE_CFN_ARM_KV_RSA);
166
- add(RE_CFN_ARM_KV_EC, RULE_CFN_ARM_KV_EC);
191
+ // The bare `kty` attribute is generic (every JWK has it), so only treat it as
192
+ // an ARM Key Vault key when the ARM resource type is actually present — otherwise
193
+ // a JWK in a file gated in by another marker (e.g. SslPolicy) would misfire here.
194
+ if (content.includes("Microsoft.KeyVault")) {
195
+ add(RE_CFN_ARM_KV_RSA, RULE_CFN_ARM_KV_RSA);
196
+ add(RE_CFN_ARM_KV_EC, RULE_CFN_ARM_KV_EC);
197
+ }
167
198
  return findings;
168
199
  },
169
200
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cloudformation.js","sourceRoot":"","sources":["../../src/detectors/cloudformation.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,cAAc,GAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAErE,+EAA+E;AAC/E,6EAA6E;AAC7E,oEAAoE;AACpE,MAAM,WAAW,GAAsB;IACrC,UAAU;IACV,yBAAyB;IACzB,0BAA0B;IAC1B,wBAAwB;IACxB,oBAAoB;IACpB,aAAa;CACd,CAAC;AAEF,6EAA6E;AAC7E,2EAA2E;AAC3E,uEAAuE;AACvE,0BAA0B;AAC1B,MAAM,cAAc,GAAG,2CAA2C,CAAC;AACnE,MAAM,aAAa,GAAG,kDAAkD,CAAC;AACzE,MAAM,cAAc,GAAG,gDAAgD,CAAC;AACxE,MAAM,aAAa,GAAG,wDAAwD,CAAC;AAC/E,wEAAwE;AACxE,wEAAwE;AACxE,sEAAsE;AACtE,MAAM,qBAAqB,GACzB,4FAA4F,CAAC;AAC/F,yEAAyE;AACzE,MAAM,cAAc,GAClB,yGAAyG,CAAC;AAC5G,8DAA8D;AAC9D,MAAM,iBAAiB,GAAG,yCAAyC,CAAC;AACpE,MAAM,gBAAgB,GAAG,wCAAwC,CAAC;AAElE,MAAM,gBAAgB,GAAa;IACjC,EAAE,EAAE,aAAa;IACjB,KAAK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C,CAAC;QAC5C,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * IaC detector: classical asymmetric cryptography (and legacy TLS config)\n * declared in AWS CloudFormation / Azure ARM (incl. Bicep-compiled JSON)\n * templates — plus CDK `cdk synth` output, which is plain CloudFormation\n * JSON. This is a distinct surface from `terraform.ts`: CloudFormation/ARM\n * use PascalCase JSON/YAML property names, never Terraform's snake_case HCL\n * attributes, so the two detectors never collide on the same file.\n *\n * Covered:\n * - AWS::KMS::Key `KeySpec`: `\"RSA_…\"` (kem) / `\"ECC_…\"` (key-exchange)\n * - AWS::CertificateManager::Certificate\n * `KeyAlgorithm`: `\"RSA_…\"` / `\"EC_…\"` (certificate)\n * - CloudFront distribution `MinimumProtocolVersion`: legacy `TLSv1` / `TLSv1.1` (tls)\n * - ELB/ALB listener `SslPolicy`: legacy `ELBSecurityPolicy-2016-08` /\n * `-TLS-1-0-…` / `-TLS-1-1-…` (tls)\n * - Azure ARM `Microsoft.KeyVault` key `kty`: `\"RSA\"` (kem) / `\"EC\"` (key-exchange)\n *\n * `KeySpec` is PascalCase and case-sensitive, so it never matches Terraform's\n * snake_case `customer_master_key_spec` (same underlying AWS API, different\n * authoring surface). A fast-reject on a CFN/ARM marker keeps this detector\n * from ever firing on arbitrary JSON/YAML that happens to contain one of\n * these property names in an unrelated context.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\nconst CFN_EXTENSIONS: readonly string[] = [\".json\", \".yaml\", \".yml\"];\n\n// Fast-reject markers: at least one must appear before any rule regex runs, so\n// this detector never scans arbitrary JSON/YAML that merely happens to share\n// an attribute name (`KeySpec`, `kty`, …) with an unrelated schema.\nconst CFN_MARKERS: readonly string[] = [\n \"AWS::KMS\",\n \"AWS::CertificateManager\",\n \"AWSTemplateFormatVersion\",\n \"MinimumProtocolVersion\",\n \"Microsoft.KeyVault\",\n '\"SslPolicy\"',\n];\n\n// Each attribute is matched with an optional quote around the key and `:` as\n// the separator (both plain-JSON and YAML-block-scalar forms use `:`). The\n// `(?<![\\w\"-])` lookbehind stops a longer/prefixed attribute name from\n// matching on its suffix.\nconst RE_CFN_KMS_RSA = /(?<![\\w\"-])\"?KeySpec\"?\\s*:\\s*\"?RSA_\\d+\"?/g;\nconst RE_CFN_KMS_EC = /(?<![\\w\"-])\"?KeySpec\"?\\s*:\\s*\"?ECC_[A-Z0-9_]+\"?/g;\nconst RE_CFN_ACM_RSA = /(?<![\\w\"-])\"?KeyAlgorithm\"?\\s*:\\s*\"?RSA_\\d+\"?/g;\nconst RE_CFN_ACM_EC = /(?<![\\w\"-])\"?KeyAlgorithm\"?\\s*:\\s*\"?EC_[A-Za-z0-9]+\"?/g;\n// CloudFront: only the pre-2018 \"TLSv1\" / \"TLSv1_2016\" / \"TLSv1.1_2016\"\n// values are legacy; the lookahead delimiter stops this from matching a\n// \"TLSv1.2_2018\"-style value that merely starts with the same prefix.\nconst RE_CFN_CLOUDFRONT_TLS =\n /(?<![\\w\"-])\"?MinimumProtocolVersion\"?\\s*:\\s*\"?(?:TLSv1(?:\\.1)?_2016|TLSv1)(?=[\"'\\s,}]|$)/gm;\n// ELB/ALB legacy SSL negotiation policies (named, dated policy strings).\nconst RE_CFN_ELB_TLS =\n /(?<![\\w\"-])\"?SslPolicy\"?\\s*:\\s*\"ELBSecurityPolicy-(?:2016-08|TLS-1-0-\\d{4}-\\d{2}|TLS-1-1-\\d{4}-\\d{2})\"/g;\n// Azure ARM Microsoft.KeyVault key resource `properties.kty`.\nconst RE_CFN_ARM_KV_RSA = /(?<![\\w\"-])\"?kty\"?\\s*:\\s*\"?RSA\"?(?!\\w)/g;\nconst RE_CFN_ARM_KV_EC = /(?<![\\w\"-])\"?kty\"?\\s*:\\s*\"?EC\"?(?!\\w)/g;\n\nconst RULE_CFN_KMS_RSA: RuleMeta = {\n id: \"cfn-kms-rsa\",\n title: \"CloudFormation KMS RSA key\",\n description: 'AWS::KMS::Key KeySpec = \"RSA_*\"',\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions a classical RSA KMS key (harvest-now-decrypt-later exposed for encryption CMKs).\",\n remediation: \"Plan migration to PQC as cloud KMS adds ML-KEM / ML-DSA key specs.\",\n};\nconst RULE_CFN_KMS_EC: RuleMeta = {\n id: \"cfn-kms-ec\",\n title: \"CloudFormation KMS EC key\",\n description: 'AWS::KMS::Key KeySpec = \"ECC_*\"',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions a classical EC KMS key; EC keys feed 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_CFN_ACM_RSA: RuleMeta = {\n id: \"cfn-acm-rsa\",\n title: \"CloudFormation ACM RSA certificate\",\n description: 'AWS::CertificateManager::Certificate KeyAlgorithm = \"RSA_*\"',\n category: \"certificate\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions an ACM certificate with a classical RSA key, which is not quantum-safe.\",\n remediation: \"Plan migration to PQC (ML-KEM-768 for encryption, ML-DSA-65 for signatures).\",\n};\nconst RULE_CFN_ACM_EC: RuleMeta = {\n id: \"cfn-acm-ec\",\n title: \"CloudFormation ACM EC certificate\",\n description: 'AWS::CertificateManager::Certificate KeyAlgorithm = \"EC_*\"',\n category: \"certificate\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions an ACM certificate with a classical EC key, forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205).\",\n};\nconst RULE_CFN_CLOUDFRONT_TLS: RuleMeta = {\n id: \"cfn-cloudfront-legacy-tls\",\n title: \"CloudFormation CloudFront legacy TLS\",\n description: 'CloudFront Distribution MinimumProtocolVersion = \"TLSv1\" / \"TLSv1.1\"',\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"CloudFront distribution permits TLS 1.0/1.1, which are deprecated and insecure.\",\n remediation:\n \"Set MinimumProtocolVersion to TLSv1.2_2021 (or later) and prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CFN_ELB_TLS: RuleMeta = {\n id: \"cfn-elb-legacy-tls\",\n title: \"CloudFormation ELB/ALB legacy TLS policy\",\n description: \"Elastic Load Balancer SslPolicy naming a pre-2017 legacy policy\",\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"Load balancer listener uses a legacy SSL negotiation policy permitting TLS 1.0/1.1.\",\n remediation: \"Use ELBSecurityPolicy-TLS13-1-2-2021-06 (or the latest FS+TLS1.2/1.3 policy).\",\n};\nconst RULE_CFN_ARM_KV_RSA: RuleMeta = {\n id: \"cfn-arm-keyvault-rsa\",\n title: \"ARM template Key Vault RSA key\",\n description: 'Microsoft.KeyVault key resource kty = \"RSA\"',\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"ARM template provisions a classical RSA Azure Key Vault key, which is not quantum-safe.\",\n remediation: \"Plan migration to PQC (ML-KEM-768 / ML-DSA-65).\",\n};\nconst RULE_CFN_ARM_KV_EC: RuleMeta = {\n id: \"cfn-arm-keyvault-ec\",\n title: \"ARM template Key Vault EC key\",\n description: 'Microsoft.KeyVault key resource kty = \"EC\"',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"ARM template provisions a classical EC Azure Key Vault key; EC keys feed 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};\n\n/**\n * Detects classical asymmetric crypto and legacy TLS config declared in\n * AWS CloudFormation / Azure ARM (incl. Bicep-compiled JSON) templates.\n */\nexport const cloudformationDetector: Detector = {\n id: \"cloudformation-crypto\",\n description:\n \"Classical asymmetric crypto and legacy TLS config declared in CloudFormation / ARM templates (IaC)\",\n scope: \"config\",\n language: \"any\",\n rules: [\n RULE_CFN_KMS_RSA,\n RULE_CFN_KMS_EC,\n RULE_CFN_ACM_RSA,\n RULE_CFN_ACM_EC,\n RULE_CFN_CLOUDFRONT_TLS,\n RULE_CFN_ELB_TLS,\n RULE_CFN_ARM_KV_RSA,\n RULE_CFN_ARM_KV_EC,\n ],\n appliesTo: (f) => hasExtension(f, CFN_EXTENSIONS),\n detect({ file, content }): Finding[] {\n if (!CFN_MARKERS.some((marker) => content.includes(marker))) return [];\n\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_CFN_KMS_RSA, RULE_CFN_KMS_RSA);\n add(RE_CFN_KMS_EC, RULE_CFN_KMS_EC);\n add(RE_CFN_ACM_RSA, RULE_CFN_ACM_RSA);\n add(RE_CFN_ACM_EC, RULE_CFN_ACM_EC);\n add(RE_CFN_CLOUDFRONT_TLS, RULE_CFN_CLOUDFRONT_TLS);\n add(RE_CFN_ELB_TLS, RULE_CFN_ELB_TLS);\n add(RE_CFN_ARM_KV_RSA, RULE_CFN_ARM_KV_RSA);\n add(RE_CFN_ARM_KV_EC, RULE_CFN_ARM_KV_EC);\n return findings;\n },\n};\n"]}
1
+ {"version":3,"file":"cloudformation.js","sourceRoot":"","sources":["../../src/detectors/cloudformation.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,cAAc,GAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAErE,+EAA+E;AAC/E,6EAA6E;AAC7E,oEAAoE;AACpE,MAAM,WAAW,GAAsB;IACrC,UAAU;IACV,yBAAyB;IACzB,0BAA0B;IAC1B,wBAAwB;IACxB,oBAAoB;IACpB,WAAW,EAAE,4EAA4E;CAC1F,CAAC;AAEF;;;GAGG;AACH,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,OAAe;IAC/D,OAAO,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,6EAA6E;AAC7E,2EAA2E;AAC3E,uEAAuE;AACvE,0BAA0B;AAC1B,kFAAkF;AAClF,0FAA0F;AAC1F,MAAM,cAAc,GAClB,iFAAiF,CAAC;AACpF,MAAM,aAAa,GACjB,wFAAwF,CAAC;AAC3F,MAAM,cAAc,GAAG,gDAAgD,CAAC;AACxE,MAAM,aAAa,GAAG,wDAAwD,CAAC;AAC/E,w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KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CACnF,CACF,CAAC;QACJ,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACtC,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;QACpC,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACtC,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;QACpC,GAAG,CAAC,qBAAqB,EAAE,uBAAuB,CAAC,CAAC;QACpD,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACtC,8EAA8E;QAC9E,kFAAkF;QAClF,kFAAkF;QAClF,IAAI,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAC3C,GAAG,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;YAC5C,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * IaC detector: classical asymmetric cryptography (and legacy TLS config)\n * declared in AWS CloudFormation / Azure ARM (incl. Bicep-compiled JSON)\n * templates — plus CDK `cdk synth` output, which is plain CloudFormation\n * JSON. This is a distinct surface from `terraform.ts`: CloudFormation/ARM\n * use PascalCase JSON/YAML property names, never Terraform's snake_case HCL\n * attributes, so the two detectors never collide on the same file.\n *\n * Covered:\n * - AWS::KMS::Key `KeySpec`: `\"RSA_…\"` (kem) / `\"ECC_…\"` (key-exchange)\n * - AWS::CertificateManager::Certificate\n * `KeyAlgorithm`: `\"RSA_…\"` / `\"EC_…\"` (certificate)\n * - CloudFront distribution `MinimumProtocolVersion`: legacy `TLSv1` / `TLSv1.1` (tls)\n * - ELB/ALB listener `SslPolicy`: legacy `ELBSecurityPolicy-2016-08` /\n * `-TLS-1-0-…` / `-TLS-1-1-…` (tls)\n * - Azure ARM `Microsoft.KeyVault` key `kty`: `\"RSA\"` (kem) / `\"EC\"` (key-exchange)\n *\n * `KeySpec` is PascalCase and case-sensitive, so it never matches Terraform's\n * snake_case `customer_master_key_spec` (same underlying AWS API, different\n * authoring surface). A fast-reject on a CFN/ARM marker keeps this detector\n * from ever firing on arbitrary JSON/YAML that happens to contain one of\n * these property names in an unrelated context.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { eachMatch, findingFromRule, hasExtension, maskCommentLines } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\nconst CFN_EXTENSIONS: readonly string[] = [\".json\", \".yaml\", \".yml\"];\n\n// Fast-reject markers: at least one must appear before any rule regex runs, so\n// this detector never scans arbitrary JSON/YAML that merely happens to share\n// an attribute name (`KeySpec`, `kty`, …) with an unrelated schema.\nconst CFN_MARKERS: readonly string[] = [\n \"AWS::KMS\",\n \"AWS::CertificateManager\",\n \"AWSTemplateFormatVersion\",\n \"MinimumProtocolVersion\",\n \"Microsoft.KeyVault\",\n \"SslPolicy\", // unquoted so a YAML `SslPolicy:` key also gates the file in, not just JSON\n];\n\n/**\n * True when the content looks like a CloudFormation / ARM deployment template (one\n * of the {@link CFN_MARKERS} is present).\n */\nfunction isCloudTemplate(content: string): boolean {\n return CFN_MARKERS.some((marker) => content.includes(marker));\n}\n\n/**\n * True when a file is one THIS detector actually scans (a `.json`/`.yaml`/`.yml`\n * template). The `cloud-kms` and `jwk` detectors defer to this detector ONLY on\n * such files — deferring on any extension that merely contains a marker string\n * (e.g. a `.ts` with an `AWS::KMS` comment) would drop a real finding, since this\n * detector never runs there.\n */\nexport function isCloudTemplateFile(file: string, content: string): boolean {\n return hasExtension(file, CFN_EXTENSIONS) && isCloudTemplate(content);\n}\n\n// Each attribute is matched with an optional quote around the key and `:` as\n// the separator (both plain-JSON and YAML-block-scalar forms use `:`). The\n// `(?<![\\w\"-])` lookbehind stops a longer/prefixed attribute name from\n// matching on its suffix.\n// Match all three AWS KMS spec-key spellings so this detector fully owns KMS keys\n// inside a template (KeySpec, the KeyPair variant, and the legacy CustomerMasterKeySpec).\nconst RE_CFN_KMS_RSA =\n /(?<![\\w\"-])\"?(?:KeySpec|KeyPairSpec|CustomerMasterKeySpec)\"?\\s*:\\s*\"?RSA_\\d+\"?/g;\nconst RE_CFN_KMS_EC =\n /(?<![\\w\"-])\"?(?:KeySpec|KeyPairSpec|CustomerMasterKeySpec)\"?\\s*:\\s*\"?ECC_[A-Z0-9_]+\"?/g;\nconst RE_CFN_ACM_RSA = /(?<![\\w\"-])\"?KeyAlgorithm\"?\\s*:\\s*\"?RSA_\\d+\"?/g;\nconst RE_CFN_ACM_EC = /(?<![\\w\"-])\"?KeyAlgorithm\"?\\s*:\\s*\"?EC_[A-Za-z0-9]+\"?/g;\n// CloudFront: only the pre-2018 \"TLSv1\" / \"TLSv1_2016\" / \"TLSv1.1_2016\"\n// values are legacy; the lookahead delimiter stops this from matching a\n// \"TLSv1.2_2018\"-style value that merely starts with the same prefix.\nconst RE_CFN_CLOUDFRONT_TLS =\n /(?<![\\w\"-])\"?MinimumProtocolVersion\"?\\s*:\\s*\"?(?:TLSv1(?:\\.1)?_2016|TLSv1|SSLv3)(?=[\"'\\s,}]|$)/gm;\n// ELB/ALB legacy SSL negotiation policies (named, dated policy strings). The value\n// quote is optional (`\"?`) so YAML block scalars (`SslPolicy: ELBSecurityPolicy-...`)\n// match too, with a delimiter lookahead so a longer/newer policy name that merely\n// shares the prefix is not matched.\nconst RE_CFN_ELB_TLS =\n /(?<![\\w\"-])\"?SslPolicy\"?\\s*:\\s*\"?ELBSecurityPolicy-(?:2016-08|TLS-1-0-\\d{4}-\\d{2}|TLS-1-1-\\d{4}-\\d{2})(?=[\"'\\s,}]|$)/g;\n// Azure ARM Microsoft.KeyVault key resource `properties.kty`.\nconst RE_CFN_ARM_KV_RSA = /(?<![\\w\"-])\"?kty\"?\\s*:\\s*\"?RSA\"?(?!\\w)/g;\nconst RE_CFN_ARM_KV_EC = /(?<![\\w\"-])\"?kty\"?\\s*:\\s*\"?EC\"?(?!\\w)/g;\n\nconst RULE_CFN_KMS_RSA: RuleMeta = {\n id: \"cfn-kms-rsa\",\n title: \"CloudFormation KMS RSA key\",\n description: 'AWS::KMS::Key KeySpec = \"RSA_*\"',\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions a classical RSA KMS key (harvest-now-decrypt-later exposed for encryption CMKs).\",\n remediation: \"Plan migration to PQC as cloud KMS adds ML-KEM / ML-DSA key specs.\",\n};\nconst RULE_CFN_KMS_EC: RuleMeta = {\n id: \"cfn-kms-ec\",\n title: \"CloudFormation KMS EC key\",\n description: 'AWS::KMS::Key KeySpec = \"ECC_*\"',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions a classical EC KMS key; EC keys feed 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_CFN_ACM_RSA: RuleMeta = {\n id: \"cfn-acm-rsa\",\n title: \"CloudFormation ACM RSA certificate\",\n description: 'AWS::CertificateManager::Certificate KeyAlgorithm = \"RSA_*\"',\n category: \"certificate\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions an ACM certificate with a classical RSA key, which is not quantum-safe.\",\n remediation: \"Plan migration to PQC (ML-KEM-768 for encryption, ML-DSA-65 for signatures).\",\n};\nconst RULE_CFN_ACM_EC: RuleMeta = {\n id: \"cfn-acm-ec\",\n title: \"CloudFormation ACM EC certificate\",\n description: 'AWS::CertificateManager::Certificate KeyAlgorithm = \"EC_*\"',\n category: \"certificate\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"CloudFormation provisions an ACM certificate with a classical EC key, forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205).\",\n};\nconst RULE_CFN_CLOUDFRONT_TLS: RuleMeta = {\n id: \"cfn-cloudfront-legacy-tls\",\n title: \"CloudFormation CloudFront legacy TLS\",\n description: 'CloudFront Distribution MinimumProtocolVersion = \"TLSv1\" / \"TLSv1.1\"',\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"CloudFront distribution permits TLS 1.0/1.1, which are deprecated and insecure.\",\n remediation:\n \"Set MinimumProtocolVersion to TLSv1.2_2021 (or later) and prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CFN_ELB_TLS: RuleMeta = {\n id: \"cfn-elb-legacy-tls\",\n title: \"CloudFormation ELB/ALB legacy TLS policy\",\n description: \"Elastic Load Balancer SslPolicy naming a pre-2017 legacy policy\",\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message: \"Load balancer listener uses a legacy SSL negotiation policy permitting TLS 1.0/1.1.\",\n remediation: \"Use ELBSecurityPolicy-TLS13-1-2-2021-06 (or the latest FS+TLS1.2/1.3 policy).\",\n};\nconst RULE_CFN_ARM_KV_RSA: RuleMeta = {\n id: \"cfn-arm-keyvault-rsa\",\n title: \"ARM template Key Vault RSA key\",\n description: 'Microsoft.KeyVault key resource kty = \"RSA\"',\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"ARM template provisions a classical RSA Azure Key Vault key, which is not quantum-safe.\",\n remediation: \"Plan migration to PQC (ML-KEM-768 / ML-DSA-65).\",\n};\nconst RULE_CFN_ARM_KV_EC: RuleMeta = {\n id: \"cfn-arm-keyvault-ec\",\n title: \"ARM template Key Vault EC key\",\n description: 'Microsoft.KeyVault key resource kty = \"EC\"',\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"ECDH\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"ARM template provisions a classical EC Azure Key Vault key; EC keys feed 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};\n\n/**\n * Detects classical asymmetric crypto and legacy TLS config declared in\n * AWS CloudFormation / Azure ARM (incl. Bicep-compiled JSON) templates.\n */\nexport const cloudformationDetector: Detector = {\n id: \"cloudformation-crypto\",\n description:\n \"Classical asymmetric crypto and legacy TLS config declared in CloudFormation / ARM templates (IaC)\",\n scope: \"config\",\n language: \"any\",\n rules: [\n RULE_CFN_KMS_RSA,\n RULE_CFN_KMS_EC,\n RULE_CFN_ACM_RSA,\n RULE_CFN_ACM_EC,\n RULE_CFN_CLOUDFRONT_TLS,\n RULE_CFN_ELB_TLS,\n RULE_CFN_ARM_KV_RSA,\n RULE_CFN_ARM_KV_EC,\n ],\n appliesTo: (f) => hasExtension(f, CFN_EXTENSIONS),\n detect({ file, content }): Finding[] {\n if (!CFN_MARKERS.some((marker) => content.includes(marker))) return [];\n\n // Mask whole `#` comment lines (YAML CFN/ARM templates ship large commented-out\n // blocks); harmless for JSON, which has no comments. Offsets preserved so finding\n // locations stay exact. `.yaml`/`.json` are not centrally comment-stripped.\n const scan = maskCommentLines(content, [\"#\"]);\n const findings: Finding[] = [];\n const add = (re: RegExp, rule: RuleMeta) =>\n eachMatch(re, scan, (m) =>\n findings.push(\n findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),\n ),\n );\n add(RE_CFN_KMS_RSA, RULE_CFN_KMS_RSA);\n add(RE_CFN_KMS_EC, RULE_CFN_KMS_EC);\n add(RE_CFN_ACM_RSA, RULE_CFN_ACM_RSA);\n add(RE_CFN_ACM_EC, RULE_CFN_ACM_EC);\n add(RE_CFN_CLOUDFRONT_TLS, RULE_CFN_CLOUDFRONT_TLS);\n add(RE_CFN_ELB_TLS, RULE_CFN_ELB_TLS);\n // The bare `kty` attribute is generic (every JWK has it), so only treat it as\n // an ARM Key Vault key when the ARM resource type is actually present — otherwise\n // a JWK in a file gated in by another marker (e.g. SslPolicy) would misfire here.\n if (content.includes(\"Microsoft.KeyVault\")) {\n add(RE_CFN_ARM_KV_RSA, RULE_CFN_ARM_KV_RSA);\n add(RE_CFN_ARM_KV_EC, RULE_CFN_ARM_KV_EC);\n }\n return findings;\n },\n};\n"]}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Config detector: classical **code-signing CLI** invocations in build scripts —
3
+ * the tools that sign long-lived, distributable artifacts (Windows installers,
4
+ * Android APKs, RPM/deb packages, NuGet packages, macOS apps) with a classical
5
+ * RSA/ECDSA signing identity.
6
+ *
7
+ * Why this is quantum-migration debt: a code signature produced today keeps
8
+ * verifying against its classical public key for the life of the artifact
9
+ * (installers and packages linger on mirrors and machines for years). Once a
10
+ * cryptographically-relevant quantum computer (CRQC) can recover the signing
11
+ * key from that public key, every such signature becomes *forgeable* — an
12
+ * attacker can mint a validly-signed trojaned installer. This is the
13
+ * signature-side analogue of harvest-now-decrypt-later: there is no
14
+ * confidentiality to harvest, so findings are `category:"signature"`,
15
+ * `hndl:false`, but they are real debt to inventory now.
16
+ *
17
+ * How this differs from the two neighbouring signing detectors — kept
18
+ * deliberately non-overlapping:
19
+ *
20
+ * - `cicd.ts` (cicdDetector) is gated to CI *pipeline* files
21
+ * (`.github/workflows/*.yml`, `.gitlab-ci.yml`, Jenkinsfile, azure-pipelines,
22
+ * CircleCI) and matches the release-automation signers there
23
+ * (cosign / gpg / jarsigner / codesign / minisign). It intentionally does
24
+ * NOT fire on a plain `build.sh`, `build.ps1`, `build.gradle`, or Makefile.
25
+ * - `supply-chain.ts` (supplyChainDetector) covers container/artifact signing
26
+ * (Docker Content Trust, CNCF Notation, in-toto) in CI files, Dockerfiles,
27
+ * and shell scripts.
28
+ *
29
+ * This detector fills the gap: the *native platform* code-signing CLIs
30
+ * (`signtool`, `osslsigncode`, `Set-AuthenticodeSignature`, `apksigner`, Gradle
31
+ * `signingConfigs`, `rpmsign`/`dpkg-sig`, `nuget sign`, `notarytool`) as they
32
+ * appear in a build script of ANY extension — because that is where developers
33
+ * actually run them. It applies everywhere except documentation
34
+ * (a README showing `signtool sign` is prose, not a build step). One token
35
+ * (`codesign`) can also be matched by `cicd.ts` when it appears inside a CI
36
+ * file; a duplicate finding across the two detectors is acceptable, and keeping
37
+ * `codesign` here means a `codesign --sign` in a hand-written `build.sh` — which
38
+ * `cicd.ts`'s CI-file gate deliberately skips — is still caught.
39
+ *
40
+ * Precision comes from two gates, mirroring `dnssec.ts`: a cheap file-level
41
+ * fast-reject (bail unless some signing-command marker is present) and
42
+ * comment-line masking (`#` for shell/PowerShell/Makefile/Gradle, `//` for
43
+ * Gradle/Groovy) so a commented-out signing step never fires. The rule regexes
44
+ * themselves key on distinctive `<tool> sign` command shapes, so the residual
45
+ * false-positive risk is low and confidence is `high`.
46
+ */
47
+ import type { Detector } from "../types.js";
48
+ /** Detects classical code-signing CLI invocations in build scripts. */
49
+ export declare const codesignDetector: Detector;
50
+ //# sourceMappingURL=codesign.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codesign.d.ts","sourceRoot":"","sources":["../../src/detectors/codesign.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAwI/D,uEAAuE;AACvE,eAAO,MAAM,gBAAgB,EAAE,QA8B9B,CAAC"}
@@ -0,0 +1,143 @@
1
+ import { eachMatch, findingFromRule, hasExtension, maskCommentLines, DOC_EXTENSIONS, } from "../detect-utils.js";
2
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
3
+ /** Shared one-line explanation, parameterised by the signing tool named in the finding. */
4
+ function signMessage(tool) {
5
+ return (`${tool} signs an artifact with a classical RSA/ECDSA key; the signature is ` +
6
+ `forgeable once a CRQC can recover the signing key — inventory the signing ` +
7
+ `identity and plan PQC migration.`);
8
+ }
9
+ /** Shared remediation: no PQC code-signing format is broadly standardized yet. */
10
+ const REMEDIATION = "No PQC code-signing format is broadly standardized yet; track platform roadmaps " +
11
+ "(e.g. Sigstore/PQC, Authenticode); keep signing-key rotation ready.";
12
+ /**
13
+ * Distinctive markers for the file-level fast-reject. Kept as a SUPERSET of the
14
+ * rule tokens below so the cheap gate can never exclude a file one of the rules
15
+ * would match: it includes every rule's trigger token (`--addsign`, `%_gpg_name`,
16
+ * `codesign`, `nuget`, …), not only the headline command names.
17
+ */
18
+ const MARKER_RE = /signtool|osslsigncode|AuthenticodeSignature|apksigner|signingConfigs|rpmsign|--addsign|%_gpg_name|dpkg-sig|nuget|notarytool|codesign/;
19
+ const CS_RULES = [
20
+ {
21
+ // Windows Authenticode: `signtool sign …` (optionally `signtool.exe`),
22
+ // `osslsigncode sign …`, or the PowerShell `Set-AuthenticodeSignature` cmdlet.
23
+ re: /\bsigntool(?:\.exe)?\s+sign\b|\bosslsigncode\s+sign\b|\bSet-AuthenticodeSignature\b/g,
24
+ meta: {
25
+ id: "codesign-authenticode",
26
+ title: "Windows Authenticode code signing (RSA)",
27
+ description: "signtool / osslsigncode / Set-AuthenticodeSignature Authenticode signing",
28
+ category: "signature",
29
+ severity: "medium",
30
+ confidence: "high",
31
+ algorithm: "RSA",
32
+ hndl: false,
33
+ cwe: CWE_BROKEN_CRYPTO,
34
+ message: signMessage("Windows Authenticode (signtool/osslsigncode/Set-AuthenticodeSignature)"),
35
+ remediation: REMEDIATION,
36
+ },
37
+ },
38
+ {
39
+ // Android: `apksigner sign …` (covers `--ks` / `--ks-key-alias` forms), or a
40
+ // Gradle `signingConfigs { … }` block (which carries `storeFile`/`keyAlias`).
41
+ re: /\bapksigner\s+sign\b|\bsigningConfigs\s*\{/g,
42
+ meta: {
43
+ id: "codesign-apk",
44
+ title: "Android APK signing (RSA)",
45
+ description: "apksigner / Gradle signingConfigs APK signing",
46
+ category: "signature",
47
+ severity: "medium",
48
+ confidence: "high",
49
+ algorithm: "RSA",
50
+ hndl: false,
51
+ cwe: CWE_BROKEN_CRYPTO,
52
+ message: signMessage("Android APK signing (apksigner/Gradle signingConfigs)"),
53
+ remediation: REMEDIATION,
54
+ },
55
+ },
56
+ {
57
+ // RPM/deb: `rpmsign --addsign`, `rpm --addsign`, the `%_gpg_name` rpmmacro, or
58
+ // `dpkg-sig --sign`. All ultimately GPG (classically RSA) signatures.
59
+ re: /\brpmsign\s+--addsign\b|\brpm\s+--addsign\b|%_gpg_name\b|\bdpkg-sig\s+--sign\b/g,
60
+ meta: {
61
+ id: "codesign-rpm",
62
+ title: "RPM/deb package signing (RSA)",
63
+ description: "rpmsign / rpm --addsign / %_gpg_name / dpkg-sig package signing",
64
+ category: "signature",
65
+ severity: "medium",
66
+ confidence: "high",
67
+ algorithm: "RSA",
68
+ hndl: false,
69
+ cwe: CWE_BROKEN_CRYPTO,
70
+ message: signMessage("RPM/deb package signing (rpmsign/rpm --addsign/dpkg-sig, GPG)"),
71
+ remediation: REMEDIATION,
72
+ },
73
+ },
74
+ {
75
+ // NuGet: `nuget sign …` — also matches `dotnet nuget sign …` (the `nuget sign`
76
+ // token is a substring of it), typically paired with `--certificate-*` flags.
77
+ re: /\bnuget\s+sign\b/g,
78
+ meta: {
79
+ id: "codesign-nuget",
80
+ title: "NuGet package signing (RSA)",
81
+ description: "nuget sign / dotnet nuget sign package signing",
82
+ category: "signature",
83
+ severity: "medium",
84
+ confidence: "high",
85
+ algorithm: "RSA",
86
+ hndl: false,
87
+ cwe: CWE_BROKEN_CRYPTO,
88
+ message: signMessage("NuGet package signing (nuget sign/dotnet nuget sign)"),
89
+ remediation: REMEDIATION,
90
+ },
91
+ },
92
+ {
93
+ // Apple: `xcrun notarytool submit …`, or `codesign --sign` / `codesign -s`.
94
+ // Allow intervening flags before `--sign`/`-s`, bounded to the codesign
95
+ // invocation so it can't latch onto a later command's flag across `&&`/`|`/`;`
96
+ // (same shape as cicd.ts's codesign rule). Algorithm is "unknown": an Apple
97
+ // signing identity may be RSA or ECDSA.
98
+ re: /\bnotarytool\s+submit\b|\bcodesign\b[^\n&|;]{0,120}?\s(?:-s\b|--sign\b)/g,
99
+ meta: {
100
+ id: "codesign-apple",
101
+ title: "Apple code signing / notarization",
102
+ description: "codesign --sign / xcrun notarytool submit macOS signing",
103
+ category: "signature",
104
+ severity: "medium",
105
+ confidence: "high",
106
+ algorithm: "unknown",
107
+ hndl: false,
108
+ cwe: CWE_BROKEN_CRYPTO,
109
+ message: signMessage("Apple code signing (codesign/notarytool)"),
110
+ remediation: REMEDIATION,
111
+ },
112
+ },
113
+ ];
114
+ /** Detects classical code-signing CLI invocations in build scripts. */
115
+ export const codesignDetector = {
116
+ id: "codesign-signing",
117
+ description: "Classical code-signing CLIs in build scripts (Authenticode, APK, RPM, NuGet, Apple)",
118
+ scope: "config",
119
+ language: "any",
120
+ rules: CS_RULES.map((r) => r.meta),
121
+ // Applies to build scripts of any extension EXCEPT documentation: a README that
122
+ // shows `signtool sign` in an example is prose, not a build step.
123
+ appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
124
+ detect({ file, content }) {
125
+ // Cheap fast-reject: bail unless some signing-command marker is present, so
126
+ // the per-rule regexes never run on the overwhelming majority of files.
127
+ if (!MARKER_RE.test(content))
128
+ return [];
129
+ // Mask whole comment lines so a commented-out signing step can't fire.
130
+ // `#` covers shell / PowerShell / Makefile / Gradle(Groovy & Kotlin DSL);
131
+ // `//` covers Gradle/Groovy. Offsets are preserved so finding locations stay
132
+ // exact (see maskCommentLines).
133
+ const scan = maskCommentLines(content, ["#", "//"]);
134
+ const findings = [];
135
+ for (const rule of CS_RULES) {
136
+ eachMatch(rule.re, scan, (m) => {
137
+ findings.push(findingFromRule(rule.meta, { file, content, index: m.index, matchLength: m[0].length }));
138
+ });
139
+ }
140
+ return findings;
141
+ },
142
+ };
143
+ //# sourceMappingURL=codesign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codesign.js","sourceRoot":"","sources":["../../src/detectors/codesign.ts"],"names":[],"mappings":"AA+CA,OAAO,EACL,SAAS,EACT,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,cAAc,GACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,2FAA2F;AAC3F,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,CACL,GAAG,IAAI,sEAAsE;QAC7E,4EAA4E;QAC5E,kCAAkC,CACnC,CAAC;AACJ,CAAC;AAED,kFAAkF;AAClF,MAAM,WAAW,GACf,kFAAkF;IAClF,qEAAqE,CAAC;AAExE;;;;;GAKG;AACH,MAAM,SAAS,GACb,sIAAsI,CAAC;AAOzI,MAAM,QAAQ,GAAa;IACzB;QACE,uEAAuE;QACvE,+EAA+E;QAC/E,EAAE,EAAE,sFAAsF;QAC1F,IAAI,EAAE;YACJ,EAAE,EAAE,uBAAuB;YAC3B,KAAK,EAAE,yCAAyC;YAChD,WAAW,EAAE,0EAA0E;YACvF,QAAQ,EAAE,WAAW;YACrB,QAAQ,EAAE,QAAQ;YAClB,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,iBAAiB;YACtB,OAAO,EAAE,WAAW,CAClB,wEAAwE,CACzE;YACD,WAAW,EAAE,WAAW;SACzB;KACF;IACD;QACE,6EAA6E;QAC7E,8EAA8E;QAC9E,EAAE,EAAE,6CAA6C;QACjD,IAA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AAE,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: classical **code-signing CLI** invocations in build scripts —\n * the tools that sign long-lived, distributable artifacts (Windows installers,\n * Android APKs, RPM/deb packages, NuGet packages, macOS apps) with a classical\n * RSA/ECDSA signing identity.\n *\n * Why this is quantum-migration debt: a code signature produced today keeps\n * verifying against its classical public key for the life of the artifact\n * (installers and packages linger on mirrors and machines for years). Once a\n * cryptographically-relevant quantum computer (CRQC) can recover the signing\n * key from that public key, every such signature becomes *forgeable* — an\n * attacker can mint a validly-signed trojaned installer. This is the\n * signature-side analogue of harvest-now-decrypt-later: there is no\n * confidentiality to harvest, so findings are `category:\"signature\"`,\n * `hndl:false`, but they are real debt to inventory now.\n *\n * How this differs from the two neighbouring signing detectors — kept\n * deliberately non-overlapping:\n *\n * - `cicd.ts` (cicdDetector) is gated to CI *pipeline* files\n * (`.github/workflows/*.yml`, `.gitlab-ci.yml`, Jenkinsfile, azure-pipelines,\n * CircleCI) and matches the release-automation signers there\n * (cosign / gpg / jarsigner / codesign / minisign). It intentionally does\n * NOT fire on a plain `build.sh`, `build.ps1`, `build.gradle`, or Makefile.\n * - `supply-chain.ts` (supplyChainDetector) covers container/artifact signing\n * (Docker Content Trust, CNCF Notation, in-toto) in CI files, Dockerfiles,\n * and shell scripts.\n *\n * This detector fills the gap: the *native platform* code-signing CLIs\n * (`signtool`, `osslsigncode`, `Set-AuthenticodeSignature`, `apksigner`, Gradle\n * `signingConfigs`, `rpmsign`/`dpkg-sig`, `nuget sign`, `notarytool`) as they\n * appear in a build script of ANY extension — because that is where developers\n * actually run them. It applies everywhere except documentation\n * (a README showing `signtool sign` is prose, not a build step). One token\n * (`codesign`) can also be matched by `cicd.ts` when it appears inside a CI\n * file; a duplicate finding across the two detectors is acceptable, and keeping\n * `codesign` here means a `codesign --sign` in a hand-written `build.sh` — which\n * `cicd.ts`'s CI-file gate deliberately skips — is still caught.\n *\n * Precision comes from two gates, mirroring `dnssec.ts`: a cheap file-level\n * fast-reject (bail unless some signing-command marker is present) and\n * comment-line masking (`#` for shell/PowerShell/Makefile/Gradle, `//` for\n * Gradle/Groovy) so a commented-out signing step never fires. The rule regexes\n * themselves key on distinctive `<tool> sign` command shapes, so the residual\n * false-positive risk is low and confidence is `high`.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport {\n eachMatch,\n findingFromRule,\n hasExtension,\n maskCommentLines,\n DOC_EXTENSIONS,\n} from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO } from \"../cwe.js\";\n\n/** Shared one-line explanation, parameterised by the signing tool named in the finding. */\nfunction signMessage(tool: string): string {\n return (\n `${tool} signs an artifact with a classical RSA/ECDSA key; the signature is ` +\n `forgeable once a CRQC can recover the signing key — inventory the signing ` +\n `identity and plan PQC migration.`\n );\n}\n\n/** Shared remediation: no PQC code-signing format is broadly standardized yet. */\nconst REMEDIATION =\n \"No PQC code-signing format is broadly standardized yet; track platform roadmaps \" +\n \"(e.g. Sigstore/PQC, Authenticode); keep signing-key rotation ready.\";\n\n/**\n * Distinctive markers for the file-level fast-reject. Kept as a SUPERSET of the\n * rule tokens below so the cheap gate can never exclude a file one of the rules\n * would match: it includes every rule's trigger token (`--addsign`, `%_gpg_name`,\n * `codesign`, `nuget`, …), not only the headline command names.\n */\nconst MARKER_RE =\n /signtool|osslsigncode|AuthenticodeSignature|apksigner|signingConfigs|rpmsign|--addsign|%_gpg_name|dpkg-sig|nuget|notarytool|codesign/;\n\ninterface CsRule {\n re: RegExp;\n meta: RuleMeta;\n}\n\nconst CS_RULES: CsRule[] = [\n {\n // Windows Authenticode: `signtool sign …` (optionally `signtool.exe`),\n // `osslsigncode sign …`, or the PowerShell `Set-AuthenticodeSignature` cmdlet.\n re: /\\bsigntool(?:\\.exe)?\\s+sign\\b|\\bosslsigncode\\s+sign\\b|\\bSet-AuthenticodeSignature\\b/g,\n meta: {\n id: \"codesign-authenticode\",\n title: \"Windows Authenticode code signing (RSA)\",\n description: \"signtool / osslsigncode / Set-AuthenticodeSignature Authenticode signing\",\n category: \"signature\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: signMessage(\n \"Windows Authenticode (signtool/osslsigncode/Set-AuthenticodeSignature)\",\n ),\n remediation: REMEDIATION,\n },\n },\n {\n // Android: `apksigner sign …` (covers `--ks` / `--ks-key-alias` forms), or a\n // Gradle `signingConfigs { … }` block (which carries `storeFile`/`keyAlias`).\n re: /\\bapksigner\\s+sign\\b|\\bsigningConfigs\\s*\\{/g,\n meta: {\n id: \"codesign-apk\",\n title: \"Android APK signing (RSA)\",\n description: \"apksigner / Gradle signingConfigs APK signing\",\n category: \"signature\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: signMessage(\"Android APK signing (apksigner/Gradle signingConfigs)\"),\n remediation: REMEDIATION,\n },\n },\n {\n // RPM/deb: `rpmsign --addsign`, `rpm --addsign`, the `%_gpg_name` rpmmacro, or\n // `dpkg-sig --sign`. All ultimately GPG (classically RSA) signatures.\n re: /\\brpmsign\\s+--addsign\\b|\\brpm\\s+--addsign\\b|%_gpg_name\\b|\\bdpkg-sig\\s+--sign\\b/g,\n meta: {\n id: \"codesign-rpm\",\n title: \"RPM/deb package signing (RSA)\",\n description: \"rpmsign / rpm --addsign / %_gpg_name / dpkg-sig package signing\",\n category: \"signature\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: signMessage(\"RPM/deb package signing (rpmsign/rpm --addsign/dpkg-sig, GPG)\"),\n remediation: REMEDIATION,\n },\n },\n {\n // NuGet: `nuget sign …` — also matches `dotnet nuget sign …` (the `nuget sign`\n // token is a substring of it), typically paired with `--certificate-*` flags.\n re: /\\bnuget\\s+sign\\b/g,\n meta: {\n id: \"codesign-nuget\",\n title: \"NuGet package signing (RSA)\",\n description: \"nuget sign / dotnet nuget sign package signing\",\n category: \"signature\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: signMessage(\"NuGet package signing (nuget sign/dotnet nuget sign)\"),\n remediation: REMEDIATION,\n },\n },\n {\n // Apple: `xcrun notarytool submit …`, or `codesign --sign` / `codesign -s`.\n // Allow intervening flags before `--sign`/`-s`, bounded to the codesign\n // invocation so it can't latch onto a later command's flag across `&&`/`|`/`;`\n // (same shape as cicd.ts's codesign rule). Algorithm is \"unknown\": an Apple\n // signing identity may be RSA or ECDSA.\n re: /\\bnotarytool\\s+submit\\b|\\bcodesign\\b[^\\n&|;]{0,120}?\\s(?:-s\\b|--sign\\b)/g,\n meta: {\n id: \"codesign-apple\",\n title: \"Apple code signing / notarization\",\n description: \"codesign --sign / xcrun notarytool submit macOS signing\",\n category: \"signature\",\n severity: \"medium\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: signMessage(\"Apple code signing (codesign/notarytool)\"),\n remediation: REMEDIATION,\n },\n },\n];\n\n/** Detects classical code-signing CLI invocations in build scripts. */\nexport const codesignDetector: Detector = {\n id: \"codesign-signing\",\n description:\n \"Classical code-signing CLIs in build scripts (Authenticode, APK, RPM, NuGet, Apple)\",\n scope: \"config\",\n language: \"any\",\n rules: CS_RULES.map((r) => r.meta),\n // Applies to build scripts of any extension EXCEPT documentation: a README that\n // shows `signtool sign` in an example is prose, not a build step.\n appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),\n detect({ file, content }): Finding[] {\n // Cheap fast-reject: bail unless some signing-command marker is present, so\n // the per-rule regexes never run on the overwhelming majority of files.\n if (!MARKER_RE.test(content)) return [];\n\n // Mask whole comment lines so a commented-out signing step can't fire.\n // `#` covers shell / PowerShell / Makefile / Gradle(Groovy & Kotlin DSL);\n // `//` covers Gradle/Groovy. Offsets are preserved so finding locations stay\n // exact (see maskCommentLines).\n const scan = maskCommentLines(content, [\"#\", \"//\"]);\n const findings: Finding[] = [];\n for (const rule of CS_RULES) {\n eachMatch(rule.re, scan, (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":"csharp.d.ts","sourceRoot":"","sources":["../../src/detectors/csharp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AA8L/D,gFAAgF;AAChF,eAAO,MAAM,cAAc,EAAE,QA8C5B,CAAC"}
1
+ {"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/detectors/csharp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAwM/D,gFAAgF;AAChF,eAAO,MAAM,cAAc,EAAE,QA8C5B,CAAC"}
@@ -12,13 +12,23 @@ const RE_CS_DSA = /\bDSA\.Create\s*\(|\bnew\s+DSACryptoServiceProvider\s*\(|\bne
12
12
  // - SslProtocols.Ssl3 / .Tls / .Tls11 → deprecated SSL 3.0 / TLS 1.0 / 1.1.
13
13
  // `SslProtocols.Tls` (no suffix) is the legacy TLS 1.0 constant; `Tls12`/`Tls13`
14
14
  // are excluded by the trailing \b (the following digit is a word char).
15
- const RE_CS_TLS_CERT_VALIDATION = /\bDangerousAcceptAnyServerCertificateValidator\b|ServerCertificateCustomValidationCallback\s*=/g;
15
+ // Only the genuinely-permissive forms: the built-in accept-any validator, or a
16
+ // callback assigned an always-`true` lambda. A callback assigned a NAMED validator
17
+ // method is typically certificate PINNING (stricter than default) and must NOT fire.
18
+ // An accept-any server-certificate callback: the BouncyCastle helper, or a
19
+ // ServerCertificateCustomValidationCallback that unconditionally yields `true` — as an
20
+ // expression lambda (`=> true`), a block-body lambda (`=> { return true; }`), or a
21
+ // `delegate { return true; }`. Requiring a literal `true` (not just any `=>`) keeps
22
+ // certificate PINNING — which returns a comparison, `=> cert.Thumbprint == pinned` —
23
+ // from being flagged as a disabled validator.
24
+ const RE_CS_TLS_CERT_VALIDATION = /\bDangerousAcceptAnyServerCertificateValidator\b|ServerCertificateCustomValidationCallback\s*=\s*(?:[^;\n]{0,80}=>\s*(?:true\b|\{\s*return\s+true\b)|delegate\s*(?:\([^)]{0,80}\))?\s*\{\s*return\s+true\b)/g;
16
25
  const RE_CS_TLS_LEGACY_VERSION = /\bSslProtocols\.(?:Tls|Tls11|Ssl3)\b/g;
17
26
  // Identifier-form JWT/JOSE signature algorithms (audit F7). The quoted-string
18
27
  // alg token ("RS256") is caught by the language-agnostic jwt-jose detector, but
19
28
  // Microsoft.IdentityModel passes the alg as an IDENTIFIER, not a string literal:
20
- // SecurityAlgorithms.RsaSha256 / SecurityAlgorithms.EcdsaSha256.
21
- const RE_CS_JWT_ALG = /\bSecurityAlgorithms\.(?:Rsa|Ecdsa)Sha(?:256|384|512)\b/g;
29
+ // SecurityAlgorithms.RsaSha256 / SecurityAlgorithms.EcdsaSha256, and the
30
+ // `…Signature`-suffixed constants used in SigningCredentials (RsaSha256Signature).
31
+ const RE_CS_JWT_ALG = /\bSecurityAlgorithms\.(?:Rsa|Ecdsa)Sha(?:256|384|512)(?:Signature)?\b/g;
22
32
  // BouncyCastle (Org.BouncyCastle) modern-curve and finite-field DH primitives,
23
33
  // which System.Security.Cryptography does not expose directly. Each regex is
24
34
  // anchored to the distinctive BouncyCastle class names for one family so it
@@ -1 +1 @@
1
- {"version":3,"file":"csharp.js","sourceRoot":"","sources":["../../src/detectors/csharp.ts"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EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CACnF,CACF,CAAC;QACJ,gEAAgE;QAChE,GAAG,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QAChC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAC9B,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC5B,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC5B,yEAAyE;QACzE,GAAG,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,CAAC;QACjD,GAAG,CAAC,wBAAwB,EAAE,kBAAkB,CAAC,CAAC;QAClD,2EAA2E;QAC3E,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;QACpC,0EAA0E;QAC1E,yDAAyD;QACzD,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,WAAW,EAAE,aAAa,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical asymmetric cryptography in C# / .NET\n * (`System.Security.Cryptography`). Same lexical strategy as the other packs.\n * .NET exposes each algorithm through a factory (`RSA.Create()`,\n * `ECDsa.Create()`, `ECDiffieHellman.Create()`) or a concrete CSP/CNG class\n * (`RSACryptoServiceProvider`, `ECDsaCng`, …), all of which are precise signals.\n *\n * HNDL: RSA (keygen/encryption) and (EC)DH key agreement are harvest-now-\n * decrypt-later exposed (hndl:true); ECDSA/DSA signatures are hndl:false but\n * forgeable by a quantum attacker.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { CSHARP_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\nconst RE_CS_RSA =\n /\\bRSA\\.Create\\s*\\(|\\bnew\\s+RSACryptoServiceProvider\\s*\\(|\\bnew\\s+RSACng\\s*\\(|\\bnew\\s+RSAOpenSsl\\s*\\(/g;\nconst RE_CS_ECDSA = /\\bECDsa\\.Create\\s*\\(|\\bnew\\s+ECDsaCng\\s*\\(|\\bnew\\s+ECDsaOpenSsl\\s*\\(/g;\nconst RE_CS_ECDH =\n /\\bECDiffieHellman\\.Create\\s*\\(|\\bnew\\s+ECDiffieHellmanCng\\s*\\(|\\bnew\\s+ECDiffieHellmanOpenSsl\\s*\\(/g;\nconst RE_CS_DSA = /\\bDSA\\.Create\\s*\\(|\\bnew\\s+DSACryptoServiceProvider\\s*\\(|\\bnew\\s+DSACng\\s*\\(/g;\n// Insecure TLS configuration (.NET). Mirrors source.ts's tlsDetector split of a\n// cert-verification-disabled rule (tls-reject-unauthorized) and a legacy-version\n// rule (tls-legacy-version) for the equivalent C# idioms:\n// - DangerousAcceptAnyServerCertificateValidator / a custom\n// ServerCertificateCustomValidationCallback → accepts any cert (MITM).\n// - SslProtocols.Ssl3 / .Tls / .Tls11 → deprecated SSL 3.0 / TLS 1.0 / 1.1.\n// `SslProtocols.Tls` (no suffix) is the legacy TLS 1.0 constant; `Tls12`/`Tls13`\n// are excluded by the trailing \\b (the following digit is a word char).\nconst RE_CS_TLS_CERT_VALIDATION =\n /\\bDangerousAcceptAnyServerCertificateValidator\\b|ServerCertificateCustomValidationCallback\\s*=/g;\nconst RE_CS_TLS_LEGACY_VERSION = /\\bSslProtocols\\.(?:Tls|Tls11|Ssl3)\\b/g;\n// Identifier-form JWT/JOSE signature algorithms (audit F7). The quoted-string\n// alg token (\"RS256\") is caught by the language-agnostic jwt-jose detector, but\n// Microsoft.IdentityModel passes the alg as an IDENTIFIER, not a string literal:\n// SecurityAlgorithms.RsaSha256 / SecurityAlgorithms.EcdsaSha256.\nconst RE_CS_JWT_ALG = /\\bSecurityAlgorithms\\.(?:Rsa|Ecdsa)Sha(?:256|384|512)\\b/g;\n// BouncyCastle (Org.BouncyCastle) modern-curve and finite-field DH primitives,\n// which System.Security.Cryptography does not expose directly. Each regex is\n// anchored to the distinctive BouncyCastle class names for one family so it\n// can't misfire on unrelated identifiers:\n// - Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters → EdDSA\n// - X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters → X25519\n// - X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters → X448\n// - DHParametersGenerator / DHBasicAgreement / DH(Basic)KeyPairGenerator / DHParameters → DH\n// The trailing \\b keeps each token whole (e.g. Ed25519KeyGenerationParameters,\n// X25519PublicKeyParameters and DHKeyGenerationParameters are NOT matched).\nconst RE_CS_BC_EDDSA = /\\bEd25519(?:KeyPairGenerator|Signer|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_X25519 = /\\bX25519(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_X448 = /\\bX448(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_DH =\n /\\bDH(?:ParametersGenerator|BasicAgreement|BasicKeyPairGenerator|KeyPairGenerator|Parameters)\\b/g;\n\nconst RULE_CS_RSA: RuleMeta = {\n id: \"csharp-rsa\",\n title: \"C# RSA key/usage\",\n description: \"System.Security.Cryptography RSA.Create / RSACryptoServiceProvider / RSACng\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA (.NET) is not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_CS_ECDSA: RuleMeta = {\n id: \"csharp-ecdsa\",\n title: \"C# ECDSA signature\",\n description: \"System.Security.Cryptography ECDsa.Create / ECDsaCng\",\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 (.NET) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_CS_ECDH: RuleMeta = {\n id: \"csharp-ecdh\",\n title: \"C# ECDH key agreement\",\n description: \"System.Security.Cryptography ECDiffieHellman.Create / ECDiffieHellmanCng\",\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 (.NET) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_DSA: RuleMeta = {\n id: \"csharp-dsa\",\n title: \"C# DSA key/signature\",\n description: \"System.Security.Cryptography DSA.Create / DSACryptoServiceProvider\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (.NET) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_CS_TLS_CERT: RuleMeta = {\n id: \"csharp-tls-cert-validation\",\n title: \"C# TLS certificate verification disabled\",\n description:\n \"DangerousAcceptAnyServerCertificateValidator / ServerCertificateCustomValidationCallback override\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"Accepting any server certificate disables TLS certificate verification (MITM risk).\",\n remediation:\n \"Remove the custom validator and verify certificates properly; prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CS_TLS_LEGACY: RuleMeta = {\n id: \"csharp-tls-legacy-version\",\n title: \"C# legacy TLS/SSL version pinned\",\n description: \"SslProtocols pinned to Ssl3 / TLS 1.0 / TLS 1.1\",\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message:\n \"SSL 3.0 / TLS 1.0 / TLS 1.1 are deprecated and insecure; require TLS 1.2+ (prefer 1.3).\",\n remediation: \"Use SslProtocols.Tls13 (or Tls12) and prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CS_JWT_ALG: RuleMeta = {\n id: \"csharp-jwt-alg\",\n title: \"C# identifier-form JWT/JOSE algorithm\",\n description: \"Microsoft.IdentityModel SecurityAlgorithms.RsaSha* / EcdsaSha*\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"A classical JWT/JOSE signature algorithm (.NET, identifier form) is used, forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204); track IETF PQC JOSE/COSE algorithms\",\n};\nconst RULE_CS_BC_EDDSA: RuleMeta = {\n id: \"csharp-bouncycastle-eddsa\",\n title: \"C# Ed25519 signature (BouncyCastle)\",\n description:\n \"Org.BouncyCastle Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical Ed25519 signing (BouncyCastle) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_CS_BC_X25519: RuleMeta = {\n id: \"csharp-bouncycastle-x25519\",\n title: \"C# X25519 key agreement (BouncyCastle)\",\n description:\n \"Org.BouncyCastle X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_BC_X448: RuleMeta = {\n id: \"csharp-bouncycastle-x448\",\n title: \"C# X448 key agreement (BouncyCastle)\",\n description: \"Org.BouncyCastle X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"X448\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X448 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_BC_DH: RuleMeta = {\n id: \"csharp-bouncycastle-dh\",\n title: \"C# finite-field Diffie-Hellman (BouncyCastle)\",\n description:\n \"Org.BouncyCastle DHParametersGenerator / DHBasicAgreement / DHKeyPairGenerator / DHParameters\",\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 (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\n\n/** Detects classical asymmetric crypto in C# (System.Security.Cryptography). */\nexport const csharpDetector: Detector = {\n id: \"csharp-crypto\",\n description:\n \"Classical asymmetric crypto (System.Security.Cryptography) and insecure TLS config in C#/.NET\",\n scope: \"source\",\n language: \"csharp\",\n rules: [\n RULE_CS_RSA,\n RULE_CS_ECDSA,\n RULE_CS_ECDH,\n RULE_CS_DSA,\n RULE_CS_TLS_CERT,\n RULE_CS_TLS_LEGACY,\n RULE_CS_JWT_ALG,\n RULE_CS_BC_EDDSA,\n RULE_CS_BC_X25519,\n RULE_CS_BC_X448,\n RULE_CS_BC_DH,\n ],\n appliesTo: (f) => hasExtension(f, CSHARP_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 // ECDSA / ECDH before RSA/DSA so the specific EC factories win.\n add(RE_CS_ECDSA, RULE_CS_ECDSA);\n add(RE_CS_ECDH, RULE_CS_ECDH);\n add(RE_CS_RSA, RULE_CS_RSA);\n add(RE_CS_DSA, RULE_CS_DSA);\n // Insecure TLS configuration (disjoint from the crypto factories above).\n add(RE_CS_TLS_CERT_VALIDATION, RULE_CS_TLS_CERT);\n add(RE_CS_TLS_LEGACY_VERSION, RULE_CS_TLS_LEGACY);\n // Identifier-form JWT/JOSE signature algorithms (Microsoft.IdentityModel).\n add(RE_CS_JWT_ALG, RULE_CS_JWT_ALG);\n // BouncyCastle (Org.BouncyCastle) curve / finite-field DH primitives that\n // System.Security.Cryptography does not expose directly.\n add(RE_CS_BC_EDDSA, RULE_CS_BC_EDDSA);\n add(RE_CS_BC_X25519, RULE_CS_BC_X25519);\n add(RE_CS_BC_X448, RULE_CS_BC_X448);\n add(RE_CS_BC_DH, RULE_CS_BC_DH);\n return findings;\n },\n};\n"]}
1
+ {"version":3,"file":"csharp.js","sourceRoot":"","sources":["../../src/detectors/csharp.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEtF,MAAM,SAAS,GACb,uGAAuG,CAAC;AAC1G,MAAM,WAAW,GAAG,uEAAuE,CAAC;AAC5F,MAAM,UAAU,GACd,qGAAqG,CAAC;AACxG,MAAM,SAAS,GAAG,+EAA+E,CAAC;AAClG,gFAAgF;AAChF,iFAAiF;AACjF,0DAA0D;AAC1D,8DAA8D;AAC9D,2EAA2E;AAC3E,8EAA8E;AAC9E,iFAAiF;AACjF,wEAAwE;AACxE,+EAA+E;AAC/E,mFAAmF;AACnF,qFAAqF;AACrF,2EAA2E;AAC3E,uFAAuF;AACvF,mFA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gB,CAAC,CAAC;QACjD,GAAG,CAAC,wBAAwB,EAAE,kBAAkB,CAAC,CAAC;QAClD,2EAA2E;QAC3E,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;QACpC,0EAA0E;QAC1E,yDAAyD;QACzD,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,WAAW,EAAE,aAAa,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC","sourcesContent":["/**\n * Source-code detector for classical asymmetric cryptography in C# / .NET\n * (`System.Security.Cryptography`). Same lexical strategy as the other packs.\n * .NET exposes each algorithm through a factory (`RSA.Create()`,\n * `ECDsa.Create()`, `ECDiffieHellman.Create()`) or a concrete CSP/CNG class\n * (`RSACryptoServiceProvider`, `ECDsaCng`, …), all of which are precise signals.\n *\n * HNDL: RSA (keygen/encryption) and (EC)DH key agreement are harvest-now-\n * decrypt-later exposed (hndl:true); ECDSA/DSA signatures are hndl:false but\n * forgeable by a quantum attacker.\n */\nimport type { Detector, Finding, RuleMeta } from \"../types.js\";\nimport { CSHARP_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from \"../detect-utils.js\";\nimport { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION, CWE_WEAK_STRENGTH } from \"../cwe.js\";\n\nconst RE_CS_RSA =\n /\\bRSA\\.Create\\s*\\(|\\bnew\\s+RSACryptoServiceProvider\\s*\\(|\\bnew\\s+RSACng\\s*\\(|\\bnew\\s+RSAOpenSsl\\s*\\(/g;\nconst RE_CS_ECDSA = /\\bECDsa\\.Create\\s*\\(|\\bnew\\s+ECDsaCng\\s*\\(|\\bnew\\s+ECDsaOpenSsl\\s*\\(/g;\nconst RE_CS_ECDH =\n /\\bECDiffieHellman\\.Create\\s*\\(|\\bnew\\s+ECDiffieHellmanCng\\s*\\(|\\bnew\\s+ECDiffieHellmanOpenSsl\\s*\\(/g;\nconst RE_CS_DSA = /\\bDSA\\.Create\\s*\\(|\\bnew\\s+DSACryptoServiceProvider\\s*\\(|\\bnew\\s+DSACng\\s*\\(/g;\n// Insecure TLS configuration (.NET). Mirrors source.ts's tlsDetector split of a\n// cert-verification-disabled rule (tls-reject-unauthorized) and a legacy-version\n// rule (tls-legacy-version) for the equivalent C# idioms:\n// - DangerousAcceptAnyServerCertificateValidator / a custom\n// ServerCertificateCustomValidationCallback → accepts any cert (MITM).\n// - SslProtocols.Ssl3 / .Tls / .Tls11 → deprecated SSL 3.0 / TLS 1.0 / 1.1.\n// `SslProtocols.Tls` (no suffix) is the legacy TLS 1.0 constant; `Tls12`/`Tls13`\n// are excluded by the trailing \\b (the following digit is a word char).\n// Only the genuinely-permissive forms: the built-in accept-any validator, or a\n// callback assigned an always-`true` lambda. A callback assigned a NAMED validator\n// method is typically certificate PINNING (stricter than default) and must NOT fire.\n// An accept-any server-certificate callback: the BouncyCastle helper, or a\n// ServerCertificateCustomValidationCallback that unconditionally yields `true` — as an\n// expression lambda (`=> true`), a block-body lambda (`=> { return true; }`), or a\n// `delegate { return true; }`. Requiring a literal `true` (not just any `=>`) keeps\n// certificate PINNING — which returns a comparison, `=> cert.Thumbprint == pinned` —\n// from being flagged as a disabled validator.\nconst RE_CS_TLS_CERT_VALIDATION =\n /\\bDangerousAcceptAnyServerCertificateValidator\\b|ServerCertificateCustomValidationCallback\\s*=\\s*(?:[^;\\n]{0,80}=>\\s*(?:true\\b|\\{\\s*return\\s+true\\b)|delegate\\s*(?:\\([^)]{0,80}\\))?\\s*\\{\\s*return\\s+true\\b)/g;\nconst RE_CS_TLS_LEGACY_VERSION = /\\bSslProtocols\\.(?:Tls|Tls11|Ssl3)\\b/g;\n// Identifier-form JWT/JOSE signature algorithms (audit F7). The quoted-string\n// alg token (\"RS256\") is caught by the language-agnostic jwt-jose detector, but\n// Microsoft.IdentityModel passes the alg as an IDENTIFIER, not a string literal:\n// SecurityAlgorithms.RsaSha256 / SecurityAlgorithms.EcdsaSha256, and the\n// `…Signature`-suffixed constants used in SigningCredentials (RsaSha256Signature).\nconst RE_CS_JWT_ALG = /\\bSecurityAlgorithms\\.(?:Rsa|Ecdsa)Sha(?:256|384|512)(?:Signature)?\\b/g;\n// BouncyCastle (Org.BouncyCastle) modern-curve and finite-field DH primitives,\n// which System.Security.Cryptography does not expose directly. Each regex is\n// anchored to the distinctive BouncyCastle class names for one family so it\n// can't misfire on unrelated identifiers:\n// - Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters → EdDSA\n// - X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters → X25519\n// - X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters → X448\n// - DHParametersGenerator / DHBasicAgreement / DH(Basic)KeyPairGenerator / DHParameters → DH\n// The trailing \\b keeps each token whole (e.g. Ed25519KeyGenerationParameters,\n// X25519PublicKeyParameters and DHKeyGenerationParameters are NOT matched).\nconst RE_CS_BC_EDDSA = /\\bEd25519(?:KeyPairGenerator|Signer|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_X25519 = /\\bX25519(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_X448 = /\\bX448(?:KeyPairGenerator|Agreement|PrivateKeyParameters)\\b/g;\nconst RE_CS_BC_DH =\n /\\bDH(?:ParametersGenerator|BasicAgreement|BasicKeyPairGenerator|KeyPairGenerator|Parameters)\\b/g;\n\nconst RULE_CS_RSA: RuleMeta = {\n id: \"csharp-rsa\",\n title: \"C# RSA key/usage\",\n description: \"System.Security.Cryptography RSA.Create / RSACryptoServiceProvider / RSACng\",\n category: \"kem\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"RSA\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical RSA (.NET) is not quantum-safe and RSA encryption is HNDL-exposed.\",\n};\nconst RULE_CS_ECDSA: RuleMeta = {\n id: \"csharp-ecdsa\",\n title: \"C# ECDSA signature\",\n description: \"System.Security.Cryptography ECDsa.Create / ECDsaCng\",\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 (.NET) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_CS_ECDH: RuleMeta = {\n id: \"csharp-ecdh\",\n title: \"C# ECDH key agreement\",\n description: \"System.Security.Cryptography ECDiffieHellman.Create / ECDiffieHellmanCng\",\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 (.NET) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_DSA: RuleMeta = {\n id: \"csharp-dsa\",\n title: \"C# DSA key/signature\",\n description: \"System.Security.Cryptography DSA.Create / DSACryptoServiceProvider\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"DSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical DSA (.NET) is deprecated and forgeable by a quantum attacker.\",\n remediation: \"Rotate off DSA and migrate to ML-DSA-65 (FIPS 204).\",\n};\nconst RULE_CS_TLS_CERT: RuleMeta = {\n id: \"csharp-tls-cert-validation\",\n title: \"C# TLS certificate verification disabled\",\n description:\n \"DangerousAcceptAnyServerCertificateValidator / ServerCertificateCustomValidationCallback override\",\n category: \"tls\",\n severity: \"high\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_CERT_VALIDATION,\n message: \"Accepting any server certificate disables TLS certificate verification (MITM risk).\",\n remediation:\n \"Remove the custom validator and verify certificates properly; prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CS_TLS_LEGACY: RuleMeta = {\n id: \"csharp-tls-legacy-version\",\n title: \"C# legacy TLS/SSL version pinned\",\n description: \"SslProtocols pinned to Ssl3 / TLS 1.0 / TLS 1.1\",\n category: \"tls\",\n severity: \"medium\",\n confidence: \"high\",\n hndl: false,\n cwe: CWE_WEAK_STRENGTH,\n message:\n \"SSL 3.0 / TLS 1.0 / TLS 1.1 are deprecated and insecure; require TLS 1.2+ (prefer 1.3).\",\n remediation: \"Use SslProtocols.Tls13 (or Tls12) and prefer PQC-hybrid key exchange.\",\n};\nconst RULE_CS_JWT_ALG: RuleMeta = {\n id: \"csharp-jwt-alg\",\n title: \"C# identifier-form JWT/JOSE algorithm\",\n description: \"Microsoft.IdentityModel SecurityAlgorithms.RsaSha* / EcdsaSha*\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"unknown\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"A classical JWT/JOSE signature algorithm (.NET, identifier form) is used, forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204); track IETF PQC JOSE/COSE algorithms\",\n};\nconst RULE_CS_BC_EDDSA: RuleMeta = {\n id: \"csharp-bouncycastle-eddsa\",\n title: \"C# Ed25519 signature (BouncyCastle)\",\n description:\n \"Org.BouncyCastle Ed25519KeyPairGenerator / Ed25519Signer / Ed25519PrivateKeyParameters\",\n category: \"signature\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"EdDSA\",\n hndl: false,\n cwe: CWE_BROKEN_CRYPTO,\n message: \"Classical Ed25519 signing (BouncyCastle) is forgeable by a quantum attacker.\",\n remediation: \"ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205)\",\n};\nconst RULE_CS_BC_X25519: RuleMeta = {\n id: \"csharp-bouncycastle-x25519\",\n title: \"C# X25519 key agreement (BouncyCastle)\",\n description:\n \"Org.BouncyCastle X25519KeyPairGenerator / X25519Agreement / X25519PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"X25519\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X25519 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_BC_X448: RuleMeta = {\n id: \"csharp-bouncycastle-x448\",\n title: \"C# X448 key agreement (BouncyCastle)\",\n description: \"Org.BouncyCastle X448KeyPairGenerator / X448Agreement / X448PrivateKeyParameters\",\n category: \"key-exchange\",\n severity: \"high\",\n confidence: \"high\",\n algorithm: \"X448\",\n hndl: true,\n cwe: CWE_BROKEN_CRYPTO,\n message:\n \"X448 Diffie-Hellman key agreement (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\nconst RULE_CS_BC_DH: RuleMeta = {\n id: \"csharp-bouncycastle-dh\",\n title: \"C# finite-field Diffie-Hellman (BouncyCastle)\",\n description:\n \"Org.BouncyCastle DHParametersGenerator / DHBasicAgreement / DHKeyPairGenerator / DHParameters\",\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 (BouncyCastle) is broken by Shor's algorithm (harvest-now-decrypt-later).\",\n};\n\n/** Detects classical asymmetric crypto in C# (System.Security.Cryptography). */\nexport const csharpDetector: Detector = {\n id: \"csharp-crypto\",\n description:\n \"Classical asymmetric crypto (System.Security.Cryptography) and insecure TLS config in C#/.NET\",\n scope: \"source\",\n language: \"csharp\",\n rules: [\n RULE_CS_RSA,\n RULE_CS_ECDSA,\n RULE_CS_ECDH,\n RULE_CS_DSA,\n RULE_CS_TLS_CERT,\n RULE_CS_TLS_LEGACY,\n RULE_CS_JWT_ALG,\n RULE_CS_BC_EDDSA,\n RULE_CS_BC_X25519,\n RULE_CS_BC_X448,\n RULE_CS_BC_DH,\n ],\n appliesTo: (f) => hasExtension(f, CSHARP_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 // ECDSA / ECDH before RSA/DSA so the specific EC factories win.\n add(RE_CS_ECDSA, RULE_CS_ECDSA);\n add(RE_CS_ECDH, RULE_CS_ECDH);\n add(RE_CS_RSA, RULE_CS_RSA);\n add(RE_CS_DSA, RULE_CS_DSA);\n // Insecure TLS configuration (disjoint from the crypto factories above).\n add(RE_CS_TLS_CERT_VALIDATION, RULE_CS_TLS_CERT);\n add(RE_CS_TLS_LEGACY_VERSION, RULE_CS_TLS_LEGACY);\n // Identifier-form JWT/JOSE signature algorithms (Microsoft.IdentityModel).\n add(RE_CS_JWT_ALG, RULE_CS_JWT_ALG);\n // BouncyCastle (Org.BouncyCastle) curve / finite-field DH primitives that\n // System.Security.Cryptography does not expose directly.\n add(RE_CS_BC_EDDSA, RULE_CS_BC_EDDSA);\n add(RE_CS_BC_X25519, RULE_CS_BC_X25519);\n add(RE_CS_BC_X448, RULE_CS_BC_X448);\n add(RE_CS_BC_DH, RULE_CS_BC_DH);\n return findings;\n },\n};\n"]}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Source detector for classical asymmetric cryptography in Dart / Flutter.
3
+ *
4
+ * Dart has no asymmetric crypto in its standard library, so real-world code
5
+ * reaches for one of the two dominant pub.dev packages, and both expose their
6
+ * primitives through distinctive class names — which makes a lexical scan (the
7
+ * same zero-dependency strategy as every other language pack here) precise:
8
+ *
9
+ * - package:pointycastle (a Bouncy Castle port). RSA via `RSAKeyGenerator`,
10
+ * `RSAEngine`, `RSASigner`, `PSSSigner`; EC via `ECKeyGenerator`,
11
+ * `ECDSASigner`, `ECDHBasicAgreement`; Edwards via `Ed25519`.
12
+ * - package:cryptography (Dart-native). RSA via `RsaPss`, `RsaSsaPkcs1v15`;
13
+ * EC via `Ecdsa`, `Ecdh`; modern curves via `Ed25519`, `X25519`.
14
+ *
15
+ * HNDL (harvest-now-decrypt-later) reasoning — the field that drives urgency:
16
+ * - RSA encryption (`RSAEngine`) and RSA key generation (`RSAKeyGenerator`,
17
+ * which yields keys that can decrypt) are confidentiality surfaces → hndl:true.
18
+ * - (EC)DH key agreement (`ECDHBasicAgreement`, `Ecdh`, `X25519`) is the classic
19
+ * HNDL target — recorded ciphertext is decryptable once the curve falls → hndl:true.
20
+ * - Signatures (`RSASigner`/`PSSSigner`/`RsaPss`/`RsaSsaPkcs1v15`, `ECDSASigner`/
21
+ * `Ecdsa`, `Ed25519`) are forgeable by a quantum attacker but not retroactively
22
+ * breakable → hndl:false.
23
+ * - `ECKeyGenerator` is ambiguous (an EC key can feed either ECDSA or ECDH); it is
24
+ * classified conservatively as an ECDSA signing key (hndl:false), the Dart default.
25
+ *
26
+ * Comment suppression is C-style (`//` line + `/* … *\/` block), matching Dart's
27
+ * lexer, so commented-out crypto is not reported. The regexes are `\b`-anchored on
28
+ * the library-specific identifiers above; none matches a bare `RSA`/`EC` substring,
29
+ * keeping false positives low. A cheap substring fast-reject skips the regex work on
30
+ * the overwhelming majority of `.dart` files that touch no asymmetric crypto.
31
+ */
32
+ import type { Detector } from "../types.js";
33
+ /** Detects classical asymmetric crypto in Dart / Flutter (pointycastle, cryptography). */
34
+ export declare const dartDetector: Detector;
35
+ //# sourceMappingURL=dart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dart.d.ts","sourceRoot":"","sources":["../../src/detectors/dart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AA8J/D,0FAA0F;AAC1F,eAAO,MAAM,YAAY,EAAE,QA8C1B,CAAC"}