@quantakrypto/core 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/cbom-merge.d.ts +9 -0
  2. package/dist/cbom-merge.d.ts.map +1 -0
  3. package/dist/cbom-merge.js +99 -0
  4. package/dist/cbom-merge.js.map +1 -0
  5. package/dist/comments.d.ts +4 -3
  6. package/dist/comments.d.ts.map +1 -1
  7. package/dist/comments.js +53 -33
  8. package/dist/comments.js.map +1 -1
  9. package/dist/dependencies.d.ts.map +1 -1
  10. package/dist/dependencies.js +1 -1
  11. package/dist/dependencies.js.map +1 -1
  12. package/dist/detect-utils.d.ts +5 -1
  13. package/dist/detect-utils.d.ts.map +1 -1
  14. package/dist/detect-utils.js +11 -2
  15. package/dist/detect-utils.js.map +1 -1
  16. package/dist/detectors/c.d.ts +4 -2
  17. package/dist/detectors/c.d.ts.map +1 -1
  18. package/dist/detectors/c.js +192 -1
  19. package/dist/detectors/c.js.map +1 -1
  20. package/dist/detectors/cicd.d.ts +27 -0
  21. package/dist/detectors/cicd.d.ts.map +1 -0
  22. package/dist/detectors/cicd.js +116 -0
  23. package/dist/detectors/cicd.js.map +1 -0
  24. package/dist/detectors/cloud-kms.d.ts +21 -0
  25. package/dist/detectors/cloud-kms.d.ts.map +1 -0
  26. package/dist/detectors/cloud-kms.js +57 -0
  27. package/dist/detectors/cloud-kms.js.map +1 -0
  28. package/dist/detectors/cloudformation.d.ts +30 -0
  29. package/dist/detectors/cloudformation.d.ts.map +1 -0
  30. package/dist/detectors/cloudformation.js +170 -0
  31. package/dist/detectors/cloudformation.js.map +1 -0
  32. package/dist/detectors/database.d.ts +17 -0
  33. package/dist/detectors/database.d.ts.map +1 -0
  34. package/dist/detectors/database.js +60 -0
  35. package/dist/detectors/database.js.map +1 -0
  36. package/dist/detectors/dnssec.d.ts +55 -0
  37. package/dist/detectors/dnssec.d.ts.map +1 -0
  38. package/dist/detectors/dnssec.js +107 -0
  39. package/dist/detectors/dnssec.js.map +1 -0
  40. package/dist/detectors/elixir.d.ts +20 -0
  41. package/dist/detectors/elixir.d.ts.map +1 -0
  42. package/dist/detectors/elixir.js +195 -0
  43. package/dist/detectors/elixir.js.map +1 -0
  44. package/dist/detectors/java.d.ts.map +1 -1
  45. package/dist/detectors/java.js +1 -1
  46. package/dist/detectors/java.js.map +1 -1
  47. package/dist/detectors/jose.d.ts +20 -0
  48. package/dist/detectors/jose.d.ts.map +1 -0
  49. package/dist/detectors/jose.js +62 -0
  50. package/dist/detectors/jose.js.map +1 -0
  51. package/dist/detectors/jwk.d.ts +25 -0
  52. package/dist/detectors/jwk.d.ts.map +1 -0
  53. package/dist/detectors/jwk.js +95 -0
  54. package/dist/detectors/jwk.js.map +1 -0
  55. package/dist/detectors/k8s.d.ts +17 -0
  56. package/dist/detectors/k8s.d.ts.map +1 -0
  57. package/dist/detectors/k8s.js +85 -0
  58. package/dist/detectors/k8s.js.map +1 -0
  59. package/dist/detectors/mesh.d.ts +35 -0
  60. package/dist/detectors/mesh.d.ts.map +1 -0
  61. package/dist/detectors/mesh.js +109 -0
  62. package/dist/detectors/mesh.js.map +1 -0
  63. package/dist/detectors/messaging.d.ts +16 -0
  64. package/dist/detectors/messaging.d.ts.map +1 -0
  65. package/dist/detectors/messaging.js +72 -0
  66. package/dist/detectors/messaging.js.map +1 -0
  67. package/dist/detectors/pem.js +1 -1
  68. package/dist/detectors/pem.js.map +1 -1
  69. package/dist/detectors/php.d.ts +24 -0
  70. package/dist/detectors/php.d.ts.map +1 -0
  71. package/dist/detectors/php.js +167 -0
  72. package/dist/detectors/php.js.map +1 -0
  73. package/dist/detectors/python.d.ts.map +1 -1
  74. package/dist/detectors/python.js +70 -0
  75. package/dist/detectors/python.js.map +1 -1
  76. package/dist/detectors/rust.d.ts.map +1 -1
  77. package/dist/detectors/rust.js +68 -0
  78. package/dist/detectors/rust.js.map +1 -1
  79. package/dist/detectors/secrets.d.ts +21 -0
  80. package/dist/detectors/secrets.d.ts.map +1 -0
  81. package/dist/detectors/secrets.js +79 -0
  82. package/dist/detectors/secrets.js.map +1 -0
  83. package/dist/detectors/source.d.ts.map +1 -1
  84. package/dist/detectors/source.js +190 -47
  85. package/dist/detectors/source.js.map +1 -1
  86. package/dist/detectors/stateful-hbs.d.ts.map +1 -1
  87. package/dist/detectors/stateful-hbs.js +9 -6
  88. package/dist/detectors/stateful-hbs.js.map +1 -1
  89. package/dist/detectors/terraform.d.ts +21 -0
  90. package/dist/detectors/terraform.d.ts.map +1 -0
  91. package/dist/detectors/terraform.js +123 -0
  92. package/dist/detectors/terraform.js.map +1 -0
  93. package/dist/detectors/vpn.d.ts +22 -0
  94. package/dist/detectors/vpn.d.ts.map +1 -0
  95. package/dist/detectors/vpn.js +99 -0
  96. package/dist/detectors/vpn.js.map +1 -0
  97. package/dist/evidence.d.ts +5 -0
  98. package/dist/evidence.d.ts.map +1 -1
  99. package/dist/evidence.js +5 -0
  100. package/dist/evidence.js.map +1 -1
  101. package/dist/index.d.ts +5 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +6 -0
  104. package/dist/index.js.map +1 -1
  105. package/dist/policy.d.ts +67 -0
  106. package/dist/policy.d.ts.map +1 -0
  107. package/dist/policy.js +115 -0
  108. package/dist/policy.js.map +1 -0
  109. package/dist/registry.d.ts.map +1 -1
  110. package/dist/registry.js +30 -0
  111. package/dist/registry.js.map +1 -1
  112. package/dist/remediate-pipeline.d.ts.map +1 -1
  113. package/dist/remediate-pipeline.js +22 -1
  114. package/dist/remediate-pipeline.js.map +1 -1
  115. package/dist/report.d.ts.map +1 -1
  116. package/dist/report.js +7 -0
  117. package/dist/report.js.map +1 -1
  118. package/dist/standards.d.ts +96 -0
  119. package/dist/standards.d.ts.map +1 -0
  120. package/dist/standards.js +107 -0
  121. package/dist/standards.js.map +1 -0
  122. package/dist/types.d.ts +1 -1
  123. package/dist/types.d.ts.map +1 -1
  124. package/dist/types.js.map +1 -1
  125. package/dist/version.d.ts +1 -1
  126. package/dist/version.js +1 -1
  127. package/dist/version.js.map +1 -1
  128. package/package.json +1 -1
  129. package/src/cbom-merge.ts +116 -0
  130. package/src/comments.ts +59 -33
  131. package/src/dependencies.ts +2 -1
  132. package/src/detect-utils.ts +14 -2
  133. package/src/detectors/c.ts +209 -3
  134. package/src/detectors/cicd.ts +158 -0
  135. package/src/detectors/cloud-kms.ts +87 -0
  136. package/src/detectors/cloudformation.ts +215 -0
  137. package/src/detectors/database.ts +88 -0
  138. package/src/detectors/dnssec.ts +186 -0
  139. package/src/detectors/elixir.ts +237 -0
  140. package/src/detectors/java.ts +2 -1
  141. package/src/detectors/jose.ts +94 -0
  142. package/src/detectors/jwk.ts +128 -0
  143. package/src/detectors/k8s.ts +112 -0
  144. package/src/detectors/mesh.ts +154 -0
  145. package/src/detectors/messaging.ts +98 -0
  146. package/src/detectors/pem.ts +1 -1
  147. package/src/detectors/php.ts +225 -0
  148. package/src/detectors/python.ts +71 -0
  149. package/src/detectors/rust.ts +71 -0
  150. package/src/detectors/secrets.ts +114 -0
  151. package/src/detectors/source.ts +235 -68
  152. package/src/detectors/stateful-hbs.ts +9 -6
  153. package/src/detectors/terraform.ts +154 -0
  154. package/src/detectors/vpn.ts +131 -0
  155. package/src/evidence.ts +11 -0
  156. package/src/index.ts +10 -0
  157. package/src/policy.ts +180 -0
  158. package/src/registry.ts +30 -0
  159. package/src/remediate-pipeline.ts +25 -2
  160. package/src/report.ts +7 -0
  161. package/src/standards.ts +186 -0
  162. package/src/types.ts +2 -0
  163. package/src/version.ts +1 -1
@@ -0,0 +1,215 @@
1
+ /**
2
+ * IaC detector: classical asymmetric cryptography (and legacy TLS config)
3
+ * declared in AWS CloudFormation / Azure ARM (incl. Bicep-compiled JSON)
4
+ * templates — plus CDK `cdk synth` output, which is plain CloudFormation
5
+ * JSON. This is a distinct surface from `terraform.ts`: CloudFormation/ARM
6
+ * use PascalCase JSON/YAML property names, never Terraform's snake_case HCL
7
+ * attributes, so the two detectors never collide on the same file.
8
+ *
9
+ * Covered:
10
+ * - AWS::KMS::Key `KeySpec`: `"RSA_…"` (kem) / `"ECC_…"` (key-exchange)
11
+ * - AWS::CertificateManager::Certificate
12
+ * `KeyAlgorithm`: `"RSA_…"` / `"EC_…"` (certificate)
13
+ * - CloudFront distribution `MinimumProtocolVersion`: legacy `TLSv1` / `TLSv1.1` (tls)
14
+ * - ELB/ALB listener `SslPolicy`: legacy `ELBSecurityPolicy-2016-08` /
15
+ * `-TLS-1-0-…` / `-TLS-1-1-…` (tls)
16
+ * - Azure ARM `Microsoft.KeyVault` key `kty`: `"RSA"` (kem) / `"EC"` (key-exchange)
17
+ *
18
+ * `KeySpec` is PascalCase and case-sensitive, so it never matches Terraform's
19
+ * snake_case `customer_master_key_spec` (same underlying AWS API, different
20
+ * authoring surface). A fast-reject on a CFN/ARM marker keeps this detector
21
+ * from ever firing on arbitrary JSON/YAML that happens to contain one of
22
+ * these property names in an unrelated context.
23
+ */
24
+ import type { Detector, Finding, RuleMeta } from "../types.js";
25
+ import { eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
26
+ import { CWE_BROKEN_CRYPTO, CWE_WEAK_STRENGTH } from "../cwe.js";
27
+
28
+ const CFN_EXTENSIONS: readonly string[] = [".json", ".yaml", ".yml"];
29
+
30
+ // Fast-reject markers: at least one must appear before any rule regex runs, so
31
+ // this detector never scans arbitrary JSON/YAML that merely happens to share
32
+ // an attribute name (`KeySpec`, `kty`, …) with an unrelated schema.
33
+ const CFN_MARKERS: readonly string[] = [
34
+ "AWS::KMS",
35
+ "AWS::CertificateManager",
36
+ "AWSTemplateFormatVersion",
37
+ "MinimumProtocolVersion",
38
+ "Microsoft.KeyVault",
39
+ '"SslPolicy"',
40
+ ];
41
+
42
+ // Each attribute is matched with an optional quote around the key and `:` as
43
+ // the separator (both plain-JSON and YAML-block-scalar forms use `:`). The
44
+ // `(?<![\w"-])` lookbehind stops a longer/prefixed attribute name from
45
+ // matching on its suffix.
46
+ const RE_CFN_KMS_RSA = /(?<![\w"-])"?KeySpec"?\s*:\s*"?RSA_\d+"?/g;
47
+ const RE_CFN_KMS_EC = /(?<![\w"-])"?KeySpec"?\s*:\s*"?ECC_[A-Z0-9_]+"?/g;
48
+ const RE_CFN_ACM_RSA = /(?<![\w"-])"?KeyAlgorithm"?\s*:\s*"?RSA_\d+"?/g;
49
+ const RE_CFN_ACM_EC = /(?<![\w"-])"?KeyAlgorithm"?\s*:\s*"?EC_[A-Za-z0-9]+"?/g;
50
+ // CloudFront: only the pre-2018 "TLSv1" / "TLSv1_2016" / "TLSv1.1_2016"
51
+ // values are legacy; the lookahead delimiter stops this from matching a
52
+ // "TLSv1.2_2018"-style value that merely starts with the same prefix.
53
+ const RE_CFN_CLOUDFRONT_TLS =
54
+ /(?<![\w"-])"?MinimumProtocolVersion"?\s*:\s*"?(?:TLSv1(?:\.1)?_2016|TLSv1)(?=["'\s,}]|$)/gm;
55
+ // ELB/ALB legacy SSL negotiation policies (named, dated policy strings).
56
+ const RE_CFN_ELB_TLS =
57
+ /(?<![\w"-])"?SslPolicy"?\s*:\s*"ELBSecurityPolicy-(?:2016-08|TLS-1-0-\d{4}-\d{2}|TLS-1-1-\d{4}-\d{2})"/g;
58
+ // Azure ARM Microsoft.KeyVault key resource `properties.kty`.
59
+ const RE_CFN_ARM_KV_RSA = /(?<![\w"-])"?kty"?\s*:\s*"?RSA"?(?!\w)/g;
60
+ const RE_CFN_ARM_KV_EC = /(?<![\w"-])"?kty"?\s*:\s*"?EC"?(?!\w)/g;
61
+
62
+ const RULE_CFN_KMS_RSA: RuleMeta = {
63
+ id: "cfn-kms-rsa",
64
+ title: "CloudFormation KMS RSA key",
65
+ description: 'AWS::KMS::Key KeySpec = "RSA_*"',
66
+ category: "kem",
67
+ severity: "high",
68
+ confidence: "high",
69
+ algorithm: "RSA",
70
+ hndl: true,
71
+ cwe: CWE_BROKEN_CRYPTO,
72
+ message:
73
+ "CloudFormation provisions a classical RSA KMS key (harvest-now-decrypt-later exposed for encryption CMKs).",
74
+ remediation: "Plan migration to PQC as cloud KMS adds ML-KEM / ML-DSA key specs.",
75
+ };
76
+ const RULE_CFN_KMS_EC: RuleMeta = {
77
+ id: "cfn-kms-ec",
78
+ title: "CloudFormation KMS EC key",
79
+ description: 'AWS::KMS::Key KeySpec = "ECC_*"',
80
+ category: "key-exchange",
81
+ severity: "high",
82
+ confidence: "high",
83
+ algorithm: "ECDH",
84
+ hndl: true,
85
+ cwe: CWE_BROKEN_CRYPTO,
86
+ message:
87
+ "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).",
88
+ remediation:
89
+ "For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
90
+ };
91
+ const RULE_CFN_ACM_RSA: RuleMeta = {
92
+ id: "cfn-acm-rsa",
93
+ title: "CloudFormation ACM RSA certificate",
94
+ description: 'AWS::CertificateManager::Certificate KeyAlgorithm = "RSA_*"',
95
+ category: "certificate",
96
+ severity: "high",
97
+ confidence: "high",
98
+ algorithm: "RSA",
99
+ hndl: true,
100
+ cwe: CWE_BROKEN_CRYPTO,
101
+ message:
102
+ "CloudFormation provisions an ACM certificate with a classical RSA key, which is not quantum-safe.",
103
+ remediation: "Plan migration to PQC (ML-KEM-768 for encryption, ML-DSA-65 for signatures).",
104
+ };
105
+ const RULE_CFN_ACM_EC: RuleMeta = {
106
+ id: "cfn-acm-ec",
107
+ title: "CloudFormation ACM EC certificate",
108
+ description: 'AWS::CertificateManager::Certificate KeyAlgorithm = "EC_*"',
109
+ category: "certificate",
110
+ severity: "high",
111
+ confidence: "high",
112
+ algorithm: "ECDSA",
113
+ hndl: false,
114
+ cwe: CWE_BROKEN_CRYPTO,
115
+ message:
116
+ "CloudFormation provisions an ACM certificate with a classical EC key, forgeable by a quantum attacker.",
117
+ remediation: "ML-DSA-65 (FIPS 204) or SLH-DSA (FIPS 205).",
118
+ };
119
+ const RULE_CFN_CLOUDFRONT_TLS: RuleMeta = {
120
+ id: "cfn-cloudfront-legacy-tls",
121
+ title: "CloudFormation CloudFront legacy TLS",
122
+ description: 'CloudFront Distribution MinimumProtocolVersion = "TLSv1" / "TLSv1.1"',
123
+ category: "tls",
124
+ severity: "medium",
125
+ confidence: "high",
126
+ hndl: false,
127
+ cwe: CWE_WEAK_STRENGTH,
128
+ message: "CloudFront distribution permits TLS 1.0/1.1, which are deprecated and insecure.",
129
+ remediation:
130
+ "Set MinimumProtocolVersion to TLSv1.2_2021 (or later) and prefer PQC-hybrid key exchange.",
131
+ };
132
+ const RULE_CFN_ELB_TLS: RuleMeta = {
133
+ id: "cfn-elb-legacy-tls",
134
+ title: "CloudFormation ELB/ALB legacy TLS policy",
135
+ description: "Elastic Load Balancer SslPolicy naming a pre-2017 legacy policy",
136
+ category: "tls",
137
+ severity: "medium",
138
+ confidence: "high",
139
+ hndl: false,
140
+ cwe: CWE_WEAK_STRENGTH,
141
+ message: "Load balancer listener uses a legacy SSL negotiation policy permitting TLS 1.0/1.1.",
142
+ remediation: "Use ELBSecurityPolicy-TLS13-1-2-2021-06 (or the latest FS+TLS1.2/1.3 policy).",
143
+ };
144
+ const RULE_CFN_ARM_KV_RSA: RuleMeta = {
145
+ id: "cfn-arm-keyvault-rsa",
146
+ title: "ARM template Key Vault RSA key",
147
+ description: 'Microsoft.KeyVault key resource kty = "RSA"',
148
+ category: "kem",
149
+ severity: "high",
150
+ confidence: "high",
151
+ algorithm: "RSA",
152
+ hndl: true,
153
+ cwe: CWE_BROKEN_CRYPTO,
154
+ message:
155
+ "ARM template provisions a classical RSA Azure Key Vault key, which is not quantum-safe.",
156
+ remediation: "Plan migration to PQC (ML-KEM-768 / ML-DSA-65).",
157
+ };
158
+ const RULE_CFN_ARM_KV_EC: RuleMeta = {
159
+ id: "cfn-arm-keyvault-ec",
160
+ title: "ARM template Key Vault EC key",
161
+ description: 'Microsoft.KeyVault key resource kty = "EC"',
162
+ category: "key-exchange",
163
+ severity: "high",
164
+ confidence: "high",
165
+ algorithm: "ECDH",
166
+ hndl: true,
167
+ cwe: CWE_BROKEN_CRYPTO,
168
+ message:
169
+ "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).",
170
+ remediation:
171
+ "For key agreement: hybrid X25519MLKEM768 (ML-KEM-768). For signatures: ML-DSA-65 (FIPS 204).",
172
+ };
173
+
174
+ /**
175
+ * Detects classical asymmetric crypto and legacy TLS config declared in
176
+ * AWS CloudFormation / Azure ARM (incl. Bicep-compiled JSON) templates.
177
+ */
178
+ export const cloudformationDetector: Detector = {
179
+ id: "cloudformation-crypto",
180
+ description:
181
+ "Classical asymmetric crypto and legacy TLS config declared in CloudFormation / ARM templates (IaC)",
182
+ scope: "config",
183
+ language: "any",
184
+ rules: [
185
+ RULE_CFN_KMS_RSA,
186
+ RULE_CFN_KMS_EC,
187
+ RULE_CFN_ACM_RSA,
188
+ RULE_CFN_ACM_EC,
189
+ RULE_CFN_CLOUDFRONT_TLS,
190
+ RULE_CFN_ELB_TLS,
191
+ RULE_CFN_ARM_KV_RSA,
192
+ RULE_CFN_ARM_KV_EC,
193
+ ],
194
+ appliesTo: (f) => hasExtension(f, CFN_EXTENSIONS),
195
+ detect({ file, content }): Finding[] {
196
+ if (!CFN_MARKERS.some((marker) => content.includes(marker))) return [];
197
+
198
+ const findings: Finding[] = [];
199
+ const add = (re: RegExp, rule: RuleMeta) =>
200
+ eachMatch(re, content, (m) =>
201
+ findings.push(
202
+ findingFromRule(rule, { file, content, index: m.index, matchLength: m[0].length }),
203
+ ),
204
+ );
205
+ add(RE_CFN_KMS_RSA, RULE_CFN_KMS_RSA);
206
+ add(RE_CFN_KMS_EC, RULE_CFN_KMS_EC);
207
+ add(RE_CFN_ACM_RSA, RULE_CFN_ACM_RSA);
208
+ add(RE_CFN_ACM_EC, RULE_CFN_ACM_EC);
209
+ add(RE_CFN_CLOUDFRONT_TLS, RULE_CFN_CLOUDFRONT_TLS);
210
+ add(RE_CFN_ELB_TLS, RULE_CFN_ELB_TLS);
211
+ add(RE_CFN_ARM_KV_RSA, RULE_CFN_ARM_KV_RSA);
212
+ add(RE_CFN_ARM_KV_EC, RULE_CFN_ARM_KV_EC);
213
+ return findings;
214
+ },
215
+ };
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Config detector: classical crypto in database usage — public-key encryption of
3
+ * stored data (pgcrypto) and weak client TLS posture. Data-at-rest is the sharpest
4
+ * harvest-now-decrypt-later target: a column encrypted to an RSA key today is a
5
+ * time capsule an adversary can hold until key recovery is cheap.
6
+ *
7
+ * Covered:
8
+ * - pgcrypto `pgp_pub_encrypt` / `pgp_pub_decrypt` in `.sql` (RSA/ElGamal public-key
9
+ * encryption of column data) → `hndl:true`.
10
+ * - libpq `sslmode = disable | allow | prefer | require` in any config/connection
11
+ * file — a mode that does NOT verify the server certificate, so the classical
12
+ * TLS session it does (or doesn't) negotiate is both MITM-able and harvestable.
13
+ */
14
+ import type { Detector, Finding, RuleMeta } from "../types.js";
15
+ import { DOC_EXTENSIONS, eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
16
+ import { CWE_BROKEN_CRYPTO, CWE_CERT_VALIDATION } from "../cwe.js";
17
+
18
+ const RE_PGCRYPTO = /\bpgp_pub_(?:encrypt|decrypt)\b/g;
19
+ const RE_WEAK_SSLMODE = /\bsslmode\s*=\s*["']?(?:disable|allow|prefer|require)\b/gi;
20
+
21
+ const RULE_PGCRYPTO: RuleMeta = {
22
+ id: "db-pgcrypto-pubkey",
23
+ title: "pgcrypto public-key encryption",
24
+ description: "Postgres pgcrypto pgp_pub_encrypt / pgp_pub_decrypt (RSA/ElGamal) on stored data",
25
+ category: "kem",
26
+ severity: "high",
27
+ confidence: "high",
28
+ algorithm: "RSA",
29
+ hndl: true,
30
+ cwe: CWE_BROKEN_CRYPTO,
31
+ message:
32
+ "Column data is encrypted with pgcrypto public-key crypto (classical RSA/ElGamal); stored ciphertext is harvest-now-decrypt-later exposed.",
33
+ remediation:
34
+ "Plan migration to a post-quantum KEM (ML-KEM-768) envelope for at-rest data; re-encrypt long-lived rows.",
35
+ };
36
+ const RULE_WEAK_SSLMODE: RuleMeta = {
37
+ id: "db-weak-sslmode",
38
+ title: "Database sslmode without verification",
39
+ description: "libpq sslmode is disable/allow/prefer/require (no certificate verification)",
40
+ category: "tls",
41
+ severity: "medium",
42
+ confidence: "high",
43
+ hndl: false,
44
+ cwe: CWE_CERT_VALIDATION,
45
+ message:
46
+ "Database sslmode does not verify the server certificate; the classical TLS session is MITM-able and its key exchange is harvestable.",
47
+ remediation:
48
+ "Use sslmode=verify-full and TLS 1.3; track PQC-hybrid KEX (X25519MLKEM768) for database transport.",
49
+ };
50
+
51
+ /** Detects classical database at-rest / transport crypto. */
52
+ export const databaseDetector: Detector = {
53
+ id: "database-crypto",
54
+ description: "Classical crypto in database usage (pgcrypto public-key, weak client sslmode)",
55
+ scope: "config",
56
+ language: "any",
57
+ rules: [RULE_PGCRYPTO, RULE_WEAK_SSLMODE],
58
+ // Skip prose/docs: a README showing `sslmode=require` is not a live connection string.
59
+ appliesTo: (f) => !hasExtension(f, DOC_EXTENSIONS),
60
+ detect({ file, content }): Finding[] {
61
+ const findings: Finding[] = [];
62
+ if (file.toLowerCase().endsWith(".sql") && content.includes("pgp_pub_")) {
63
+ eachMatch(RE_PGCRYPTO, content, (m) =>
64
+ findings.push(
65
+ findingFromRule(RULE_PGCRYPTO, {
66
+ file,
67
+ content,
68
+ index: m.index,
69
+ matchLength: m[0].length,
70
+ }),
71
+ ),
72
+ );
73
+ }
74
+ if (content.includes("sslmode")) {
75
+ eachMatch(RE_WEAK_SSLMODE, content, (m) =>
76
+ findings.push(
77
+ findingFromRule(RULE_WEAK_SSLMODE, {
78
+ file,
79
+ content,
80
+ index: m.index,
81
+ matchLength: m[0].length,
82
+ }),
83
+ ),
84
+ );
85
+ }
86
+ return findings;
87
+ },
88
+ };
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Config detector: classical DNSSEC signing algorithms in zone files and
3
+ * signer/resolver config (BIND, Knot DNS, PowerDNS, `ldns-signzone` /
4
+ * `dnssec-signzone` invocations recorded in ops config).
5
+ *
6
+ * DNSSEC is "communication between things" infrastructure: resolvers verify
7
+ * DNSKEY/RRSIG chains to authenticate zone data. Unlike a KEM or key-exchange
8
+ * finding, a DNSSEC signing key is not harvest-now-decrypt-later exposed —
9
+ * there is no confidentiality to harvest — but every classical signature it
10
+ * produces becomes FORGEABLE the moment a cryptographically-relevant quantum
11
+ * computer (CRQC) exists. A forged DNSKEY/RRSIG chain lets an attacker spoof
12
+ * DNSSEC-validated records (cache poisoning that a validating resolver would
13
+ * otherwise reject). So these findings are `category: "signature"`,
14
+ * `hndl: false`.
15
+ *
16
+ * RFC 8624 / IANA "DNSSEC Algorithm Numbers" families covered, mapped to
17
+ * {@link AlgorithmFamily}:
18
+ * - RSASHA1 (5), RSASHA1-NSEC3-SHA1 (7), RSASHA256 (8), RSASHA512 (10) → RSA
19
+ * - ECDSAP256SHA256 (13), ECDSAP384SHA384 (14) → ECDSA
20
+ * - ED25519 (15), ED448 (16) → EdDSA
21
+ * - DSA (3), DSA-NSEC3-SHA1 (6) → DSA
22
+ *
23
+ * Two independent match shapes per family, both gated to `.zone` / `.db` /
24
+ * `.conf` files AND to a file-level DNSSEC marker (see `hasDnssecMarker`
25
+ * below) so the algorithm tokens can't fire on unrelated config:
26
+ *
27
+ * 1. NAMED form — the algorithm's mnemonic name, as written in signer/policy
28
+ * config (Knot `algorithm RSASHA256;`, a `dnssec-policy` block, BIND
29
+ * `algorithm: ecdsap256sha256;`) or on an `ldns-signzone -a ECDSAP256SHA256`
30
+ * / `dnssec-signzone -a ECDSAP256SHA256` command line. These mnemonics
31
+ * (`RSASHA256`, `ECDSAP384SHA384`, `ED25519`, …) are distinctive enough to
32
+ * match bare, EXCEPT plain `DSA`, which is too generic a token on its own
33
+ * (used well outside DNSSEC); that one is only matched immediately after
34
+ * an `algorithm` keyword.
35
+ * 2. STRUCTURAL form — the DNSKEY presentation-format RDATA, e.g.
36
+ * `example.com. IN DNSKEY 257 3 8 AwEAAd...`, where the fields after the
37
+ * `DNSKEY` keyword are `flags protocol algorithm public-key` (RFC 4034
38
+ * §2). Anchoring on the literal `DNSKEY` keyword AND the literal
39
+ * protocol value `3` (always 3 for DNSSEC) before a restricted algorithm
40
+ * number keeps this precise despite being numeric. Bare algorithm
41
+ * numbers with no such anchor are deliberately NOT matched anywhere —
42
+ * `algorithm 8;` alone is far too ambiguous to key off of.
43
+ *
44
+ * Fast reject: `detect()` bails unless the file contains `DNSKEY`, `RRSIG`,
45
+ * a case-insensitive `dnssec` substring (present in `dnssec-policy`,
46
+ * `dnssec-signing: on`, etc. in any real signer config), or an
47
+ * `ldns-signzone` / `dnssec-signzone` invocation. This stops the DSA/EdDSA
48
+ * named-form tokens — which are individually generic outside DNSSEC — from
49
+ * firing on, say, an unrelated SSH or TLS `.conf` file that happens to
50
+ * mention `ED25519` or `DSA` for its own reasons.
51
+ */
52
+ import type { Detector, Finding, RuleMeta } from "../types.js";
53
+ import { eachMatch, findingFromRule, hasExtension } from "../detect-utils.js";
54
+ import { CWE_BROKEN_CRYPTO } from "../cwe.js";
55
+
56
+ const DNSSEC_EXTENSIONS: readonly string[] = [".zone", ".db", ".conf"];
57
+
58
+ // IANA DNSSEC algorithm numbers, grouped by family.
59
+ const NUM_RSA = "5|7|8|10"; // RSASHA1, RSASHA1-NSEC3-SHA1, RSASHA256, RSASHA512
60
+ const NUM_ECDSA = "13|14"; // ECDSAP256SHA256, ECDSAP384SHA384
61
+ const NUM_EDDSA = "15|16"; // ED25519, ED448
62
+ const NUM_DSA = "3|6"; // DSA, DSA-NSEC3-SHA1
63
+
64
+ // --- NAMED form: mnemonic algorithm names in signer/policy config or CLI args. ---
65
+ const RE_NAMED_RSA = /\bRSASHA(?:256|512|1(?:-NSEC3-SHA1)?)\b/g;
66
+ const RE_NAMED_ECDSA = /\bECDSAP(?:256SHA256|384SHA384)\b/g;
67
+ const RE_NAMED_EDDSA = /\bED(?:25519|448)\b/g;
68
+ // Bare "DSA" is too generic to key off alone; require it right after an
69
+ // `algorithm` keyword (Knot/BIND config / dnssec-policy style), optionally
70
+ // quoted or separated by `:`/`=`.
71
+ const RE_NAMED_DSA = /\balgorithm\s*[:=]?\s*"?DSA(?:-NSEC3-SHA1)?"?\b/gi;
72
+
73
+ // --- STRUCTURAL form: `DNSKEY <flags> 3 <algorithm>` presentation RDATA (RFC 4034 §2). ---
74
+ const RE_DNSKEY_RSA = new RegExp(`\\bDNSKEY\\s+\\d+\\s+3\\s+(?:${NUM_RSA})\\b`, "g");
75
+ const RE_DNSKEY_ECDSA = new RegExp(`\\bDNSKEY\\s+\\d+\\s+3\\s+(?:${NUM_ECDSA})\\b`, "g");
76
+ const RE_DNSKEY_EDDSA = new RegExp(`\\bDNSKEY\\s+\\d+\\s+3\\s+(?:${NUM_EDDSA})\\b`, "g");
77
+ const RE_DNSKEY_DSA = new RegExp(`\\bDNSKEY\\s+\\d+\\s+3\\s+(?:${NUM_DSA})\\b`, "g");
78
+
79
+ const RULE_DNSSEC_RSA: RuleMeta = {
80
+ id: "dnssec-rsa-sig",
81
+ title: "DNSSEC RSA signing algorithm",
82
+ description: "DNSSEC zone signed with a classical RSA algorithm (RSASHA1/256/512)",
83
+ category: "signature",
84
+ severity: "medium",
85
+ confidence: "high",
86
+ algorithm: "RSA",
87
+ hndl: false,
88
+ cwe: CWE_BROKEN_CRYPTO,
89
+ message:
90
+ "DNSSEC zone is signed with a classical RSA algorithm (RSASHA1/RSASHA1-NSEC3-SHA1/RSASHA256/RSASHA512); DNSKEY/RRSIG signatures become forgeable once a CRQC exists.",
91
+ remediation:
92
+ "Track IETF dnsop post-quantum DNSSEC signing work (ML-DSA); plan re-signing with a PQC algorithm once assigned an IANA DNSSEC algorithm number.",
93
+ };
94
+ const RULE_DNSSEC_ECDSA: RuleMeta = {
95
+ id: "dnssec-ecdsa-sig",
96
+ title: "DNSSEC ECDSA signing algorithm",
97
+ description: "DNSSEC zone signed with a classical ECDSA algorithm (ECDSAP256SHA256/384SHA384)",
98
+ category: "signature",
99
+ severity: "medium",
100
+ confidence: "high",
101
+ algorithm: "ECDSA",
102
+ hndl: false,
103
+ cwe: CWE_BROKEN_CRYPTO,
104
+ message:
105
+ "DNSSEC zone is signed with a classical ECDSA algorithm (ECDSAP256SHA256/ECDSAP384SHA384); DNSKEY/RRSIG signatures become forgeable once a CRQC exists.",
106
+ remediation:
107
+ "Track IETF dnsop post-quantum DNSSEC signing work (ML-DSA); plan re-signing with a PQC algorithm once assigned an IANA DNSSEC algorithm number.",
108
+ };
109
+ const RULE_DNSSEC_EDDSA: RuleMeta = {
110
+ id: "dnssec-eddsa-sig",
111
+ title: "DNSSEC EdDSA signing algorithm",
112
+ description: "DNSSEC zone signed with a classical EdDSA algorithm (ED25519/ED448)",
113
+ category: "signature",
114
+ severity: "medium",
115
+ confidence: "high",
116
+ algorithm: "EdDSA",
117
+ hndl: false,
118
+ cwe: CWE_BROKEN_CRYPTO,
119
+ message:
120
+ "DNSSEC zone is signed with a classical EdDSA algorithm (ED25519/ED448); modern but still classical — DNSKEY/RRSIG signatures become forgeable once a CRQC exists.",
121
+ remediation:
122
+ "Track IETF dnsop post-quantum DNSSEC signing work (ML-DSA); plan re-signing with a PQC algorithm once assigned an IANA DNSSEC algorithm number.",
123
+ };
124
+ const RULE_DNSSEC_DSA: RuleMeta = {
125
+ id: "dnssec-dsa-sig",
126
+ title: "DNSSEC DSA signing algorithm (deprecated)",
127
+ description:
128
+ "DNSSEC zone signed with the deprecated classical DSA algorithm (DSA/DSA-NSEC3-SHA1)",
129
+ category: "signature",
130
+ severity: "medium",
131
+ confidence: "high",
132
+ algorithm: "DSA",
133
+ hndl: false,
134
+ cwe: CWE_BROKEN_CRYPTO,
135
+ message:
136
+ "DNSSEC zone is signed with DSA/DSA-NSEC3-SHA1 — deprecated by RFC 8624 (MUST NOT sign) and, independent of that, forgeable once a CRQC exists.",
137
+ remediation:
138
+ "Re-sign with a non-deprecated algorithm today (RFC 8624); track IETF dnsop post-quantum DNSSEC signing work (ML-DSA) for the eventual PQC migration.",
139
+ };
140
+
141
+ /** True when `content` carries some DNSSEC-specific marker (not just a bare algorithm token). */
142
+ function hasDnssecMarker(content: string): boolean {
143
+ return (
144
+ content.includes("DNSKEY") ||
145
+ content.includes("RRSIG") ||
146
+ /dnssec/i.test(content) ||
147
+ /ldns-signzone|dnssec-signzone/.test(content)
148
+ );
149
+ }
150
+
151
+ interface DnssecRule {
152
+ meta: RuleMeta;
153
+ res: readonly RegExp[];
154
+ }
155
+
156
+ const DNSSEC_RULES: readonly DnssecRule[] = [
157
+ { meta: RULE_DNSSEC_RSA, res: [RE_NAMED_RSA, RE_DNSKEY_RSA] },
158
+ { meta: RULE_DNSSEC_ECDSA, res: [RE_NAMED_ECDSA, RE_DNSKEY_ECDSA] },
159
+ { meta: RULE_DNSSEC_EDDSA, res: [RE_NAMED_EDDSA, RE_DNSKEY_EDDSA] },
160
+ { meta: RULE_DNSSEC_DSA, res: [RE_NAMED_DSA, RE_DNSKEY_DSA] },
161
+ ];
162
+
163
+ /** Detects classical DNSSEC signing algorithms in zone files and signer config. */
164
+ export const dnssecDetector: Detector = {
165
+ id: "dnssec-crypto",
166
+ description: "Classical DNSSEC signing algorithms in zone files / signer config",
167
+ scope: "config",
168
+ language: "any",
169
+ rules: DNSSEC_RULES.map((r) => r.meta),
170
+ appliesTo: (f) => hasExtension(f, DNSSEC_EXTENSIONS),
171
+ detect({ file, content }): Finding[] {
172
+ if (!hasDnssecMarker(content)) return [];
173
+
174
+ const findings: Finding[] = [];
175
+ for (const { meta, res } of DNSSEC_RULES) {
176
+ for (const re of res) {
177
+ eachMatch(re, content, (m) =>
178
+ findings.push(
179
+ findingFromRule(meta, { file, content, index: m.index, matchLength: m[0].length }),
180
+ ),
181
+ );
182
+ }
183
+ }
184
+ return findings;
185
+ },
186
+ };