@nahisaho/musubix-security 1.8.0 → 1.8.1

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 (186) hide show
  1. package/README.md +27 -0
  2. package/dist/analyzers/ai/index.d.ts +6 -0
  3. package/dist/analyzers/ai/index.d.ts.map +1 -0
  4. package/dist/analyzers/ai/index.js +6 -0
  5. package/dist/analyzers/ai/index.js.map +1 -0
  6. package/dist/analyzers/ai/prompt-injection-detector.d.ts +152 -0
  7. package/dist/analyzers/ai/prompt-injection-detector.d.ts.map +1 -0
  8. package/dist/analyzers/ai/prompt-injection-detector.js +468 -0
  9. package/dist/analyzers/ai/prompt-injection-detector.js.map +1 -0
  10. package/dist/analyzers/api/api-security-analyzer.d.ts +263 -0
  11. package/dist/analyzers/api/api-security-analyzer.d.ts.map +1 -0
  12. package/dist/analyzers/api/api-security-analyzer.js +581 -0
  13. package/dist/analyzers/api/api-security-analyzer.js.map +1 -0
  14. package/dist/analyzers/compliance/compliance-checker.d.ts +201 -0
  15. package/dist/analyzers/compliance/compliance-checker.d.ts.map +1 -0
  16. package/dist/analyzers/compliance/compliance-checker.js +772 -0
  17. package/dist/analyzers/compliance/compliance-checker.js.map +1 -0
  18. package/dist/analyzers/container/image-scanner.d.ts +163 -0
  19. package/dist/analyzers/container/image-scanner.d.ts.map +1 -0
  20. package/dist/analyzers/container/image-scanner.js +459 -0
  21. package/dist/analyzers/container/image-scanner.js.map +1 -0
  22. package/dist/analyzers/container/index.d.ts +6 -0
  23. package/dist/analyzers/container/index.d.ts.map +1 -0
  24. package/dist/analyzers/container/index.js +6 -0
  25. package/dist/analyzers/container/index.js.map +1 -0
  26. package/dist/analyzers/dashboard/security-dashboard.d.ts +286 -0
  27. package/dist/analyzers/dashboard/security-dashboard.d.ts.map +1 -0
  28. package/dist/analyzers/dashboard/security-dashboard.js +796 -0
  29. package/dist/analyzers/dashboard/security-dashboard.js.map +1 -0
  30. package/dist/analyzers/iac/iac-checker.d.ts +124 -0
  31. package/dist/analyzers/iac/iac-checker.d.ts.map +1 -0
  32. package/dist/analyzers/iac/iac-checker.js +755 -0
  33. package/dist/analyzers/iac/iac-checker.js.map +1 -0
  34. package/dist/analyzers/iac/index.d.ts +6 -0
  35. package/dist/analyzers/iac/index.d.ts.map +1 -0
  36. package/dist/analyzers/iac/index.js +6 -0
  37. package/dist/analyzers/iac/index.js.map +1 -0
  38. package/dist/analyzers/index.d.ts +9 -0
  39. package/dist/analyzers/index.d.ts.map +1 -0
  40. package/dist/analyzers/index.js +13 -0
  41. package/dist/analyzers/index.js.map +1 -0
  42. package/dist/analyzers/monitor/realtime-monitor.d.ts +216 -0
  43. package/dist/analyzers/monitor/realtime-monitor.d.ts.map +1 -0
  44. package/dist/analyzers/monitor/realtime-monitor.js +601 -0
  45. package/dist/analyzers/monitor/realtime-monitor.js.map +1 -0
  46. package/dist/analyzers/sast/index.d.ts +7 -0
  47. package/dist/analyzers/sast/index.d.ts.map +1 -0
  48. package/dist/analyzers/sast/index.js +7 -0
  49. package/dist/analyzers/sast/index.js.map +1 -0
  50. package/dist/analyzers/sast/interprocedural-analyzer.d.ts +276 -0
  51. package/dist/analyzers/sast/interprocedural-analyzer.d.ts.map +1 -0
  52. package/dist/analyzers/sast/interprocedural-analyzer.js +635 -0
  53. package/dist/analyzers/sast/interprocedural-analyzer.js.map +1 -0
  54. package/dist/analyzers/sast/zero-day-detector.d.ts +183 -0
  55. package/dist/analyzers/sast/zero-day-detector.d.ts.map +1 -0
  56. package/dist/analyzers/sast/zero-day-detector.js +593 -0
  57. package/dist/analyzers/sast/zero-day-detector.js.map +1 -0
  58. package/dist/analyzers/sca/dependency-scanner.d.ts +275 -0
  59. package/dist/analyzers/sca/dependency-scanner.d.ts.map +1 -0
  60. package/dist/analyzers/sca/dependency-scanner.js +642 -0
  61. package/dist/analyzers/sca/dependency-scanner.js.map +1 -0
  62. package/dist/core/index.d.ts +8 -0
  63. package/dist/core/index.d.ts.map +1 -0
  64. package/dist/core/index.js +10 -0
  65. package/dist/core/index.js.map +1 -0
  66. package/dist/core/pipeline-manager.d.ts +105 -0
  67. package/dist/core/pipeline-manager.d.ts.map +1 -0
  68. package/dist/core/pipeline-manager.js +449 -0
  69. package/dist/core/pipeline-manager.js.map +1 -0
  70. package/dist/core/result-aggregator.d.ts +96 -0
  71. package/dist/core/result-aggregator.d.ts.map +1 -0
  72. package/dist/core/result-aggregator.js +462 -0
  73. package/dist/core/result-aggregator.js.map +1 -0
  74. package/dist/index.d.ts +15 -0
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +68 -0
  77. package/dist/index.js.map +1 -1
  78. package/dist/integrations/ci-integration.d.ts +227 -0
  79. package/dist/integrations/ci-integration.d.ts.map +1 -0
  80. package/dist/integrations/ci-integration.js +472 -0
  81. package/dist/integrations/ci-integration.js.map +1 -0
  82. package/dist/integrations/git-hooks.d.ts +155 -0
  83. package/dist/integrations/git-hooks.d.ts.map +1 -0
  84. package/dist/integrations/git-hooks.js +425 -0
  85. package/dist/integrations/git-hooks.js.map +1 -0
  86. package/dist/integrations/index.d.ts +9 -0
  87. package/dist/integrations/index.d.ts.map +1 -0
  88. package/dist/integrations/index.js +9 -0
  89. package/dist/integrations/index.js.map +1 -0
  90. package/dist/integrations/report-aggregator.d.ts +250 -0
  91. package/dist/integrations/report-aggregator.d.ts.map +1 -0
  92. package/dist/integrations/report-aggregator.js +488 -0
  93. package/dist/integrations/report-aggregator.js.map +1 -0
  94. package/dist/integrations/vscode-integration.d.ts +245 -0
  95. package/dist/integrations/vscode-integration.d.ts.map +1 -0
  96. package/dist/integrations/vscode-integration.js +449 -0
  97. package/dist/integrations/vscode-integration.js.map +1 -0
  98. package/dist/intelligence/attack-pattern-matcher.d.ts +217 -0
  99. package/dist/intelligence/attack-pattern-matcher.d.ts.map +1 -0
  100. package/dist/intelligence/attack-pattern-matcher.js +887 -0
  101. package/dist/intelligence/attack-pattern-matcher.js.map +1 -0
  102. package/dist/intelligence/index.d.ts +12 -0
  103. package/dist/intelligence/index.d.ts.map +1 -0
  104. package/dist/intelligence/index.js +18 -0
  105. package/dist/intelligence/index.js.map +1 -0
  106. package/dist/intelligence/neuro-symbolic-core.d.ts +88 -0
  107. package/dist/intelligence/neuro-symbolic-core.d.ts.map +1 -0
  108. package/dist/intelligence/neuro-symbolic-core.js +403 -0
  109. package/dist/intelligence/neuro-symbolic-core.js.map +1 -0
  110. package/dist/intelligence/predictive-analyzer.d.ts +317 -0
  111. package/dist/intelligence/predictive-analyzer.d.ts.map +1 -0
  112. package/dist/intelligence/predictive-analyzer.js +714 -0
  113. package/dist/intelligence/predictive-analyzer.js.map +1 -0
  114. package/dist/intelligence/risk-scorer.d.ts +333 -0
  115. package/dist/intelligence/risk-scorer.d.ts.map +1 -0
  116. package/dist/intelligence/risk-scorer.js +824 -0
  117. package/dist/intelligence/risk-scorer.js.map +1 -0
  118. package/dist/intelligence/security-analytics.d.ts +349 -0
  119. package/dist/intelligence/security-analytics.d.ts.map +1 -0
  120. package/dist/intelligence/security-analytics.js +813 -0
  121. package/dist/intelligence/security-analytics.js.map +1 -0
  122. package/dist/intelligence/threat-intelligence.d.ts +288 -0
  123. package/dist/intelligence/threat-intelligence.d.ts.map +1 -0
  124. package/dist/intelligence/threat-intelligence.js +639 -0
  125. package/dist/intelligence/threat-intelligence.js.map +1 -0
  126. package/dist/policy/index.d.ts +6 -0
  127. package/dist/policy/index.d.ts.map +1 -0
  128. package/dist/policy/index.js +6 -0
  129. package/dist/policy/index.js.map +1 -0
  130. package/dist/policy/policy-engine.d.ts +254 -0
  131. package/dist/policy/policy-engine.d.ts.map +1 -0
  132. package/dist/policy/policy-engine.js +651 -0
  133. package/dist/policy/policy-engine.js.map +1 -0
  134. package/dist/remediation/auto-fixer.d.ts +179 -0
  135. package/dist/remediation/auto-fixer.d.ts.map +1 -0
  136. package/dist/remediation/auto-fixer.js +540 -0
  137. package/dist/remediation/auto-fixer.js.map +1 -0
  138. package/dist/remediation/fix-validator.d.ts +195 -0
  139. package/dist/remediation/fix-validator.d.ts.map +1 -0
  140. package/dist/remediation/fix-validator.js +462 -0
  141. package/dist/remediation/fix-validator.js.map +1 -0
  142. package/dist/remediation/index.d.ts +10 -0
  143. package/dist/remediation/index.d.ts.map +1 -0
  144. package/dist/remediation/index.js +15 -0
  145. package/dist/remediation/index.js.map +1 -0
  146. package/dist/remediation/patch-generator.d.ts +203 -0
  147. package/dist/remediation/patch-generator.d.ts.map +1 -0
  148. package/dist/remediation/patch-generator.js +533 -0
  149. package/dist/remediation/patch-generator.js.map +1 -0
  150. package/dist/remediation/remediation-planner.d.ts +262 -0
  151. package/dist/remediation/remediation-planner.d.ts.map +1 -0
  152. package/dist/remediation/remediation-planner.js +531 -0
  153. package/dist/remediation/remediation-planner.js.map +1 -0
  154. package/dist/remediation/secure-code-transformer.d.ts +222 -0
  155. package/dist/remediation/secure-code-transformer.d.ts.map +1 -0
  156. package/dist/remediation/secure-code-transformer.js +625 -0
  157. package/dist/remediation/secure-code-transformer.js.map +1 -0
  158. package/dist/types/fix.d.ts +3 -1
  159. package/dist/types/fix.d.ts.map +1 -1
  160. package/dist/types/index.d.ts +6 -0
  161. package/dist/types/index.d.ts.map +1 -1
  162. package/dist/types/index.js +1 -0
  163. package/dist/types/index.js.map +1 -1
  164. package/dist/types/interprocedural.d.ts +203 -0
  165. package/dist/types/interprocedural.d.ts.map +1 -0
  166. package/dist/types/interprocedural.js +7 -0
  167. package/dist/types/interprocedural.js.map +1 -0
  168. package/dist/types/neuro-symbolic.d.ts +179 -0
  169. package/dist/types/neuro-symbolic.d.ts.map +1 -0
  170. package/dist/types/neuro-symbolic.js +7 -0
  171. package/dist/types/neuro-symbolic.js.map +1 -0
  172. package/dist/types/pipeline.d.ts +173 -0
  173. package/dist/types/pipeline.d.ts.map +1 -0
  174. package/dist/types/pipeline.js +7 -0
  175. package/dist/types/pipeline.js.map +1 -0
  176. package/dist/types/result.d.ts +134 -0
  177. package/dist/types/result.d.ts.map +1 -0
  178. package/dist/types/result.js +25 -0
  179. package/dist/types/result.js.map +1 -0
  180. package/dist/types/vulnerability.d.ts +2 -2
  181. package/dist/types/vulnerability.d.ts.map +1 -1
  182. package/dist/types/zero-day.d.ts +146 -0
  183. package/dist/types/zero-day.d.ts.map +1 -0
  184. package/dist/types/zero-day.js +7 -0
  185. package/dist/types/zero-day.js.map +1 -0
  186. package/package.json +2 -2
@@ -0,0 +1,772 @@
1
+ /**
2
+ * @fileoverview Compliance Checker - Security compliance verification
3
+ * @module @nahisaho/musubix-security/analyzers/compliance/compliance-checker
4
+ * @trace DES-SEC3-COMPLIANCE-001, REQ-SEC3-COMPLIANCE-001
5
+ */
6
+ /**
7
+ * OWASP ASVS Requirements Database
8
+ */
9
+ const ASVS_REQUIREMENTS = [
10
+ // V1: Architecture
11
+ {
12
+ id: 'V1.1.1',
13
+ standard: 'owasp-asvs-l1',
14
+ category: 'Architecture',
15
+ title: 'Secure Development Lifecycle',
16
+ description: 'Verify that a secure software development lifecycle is in use',
17
+ level: 1,
18
+ controls: ['SDLC', 'security-requirements'],
19
+ },
20
+ {
21
+ id: 'V1.1.2',
22
+ standard: 'owasp-asvs-l1',
23
+ category: 'Architecture',
24
+ title: 'Threat Modeling',
25
+ description: 'Verify that threat modeling is performed for changes',
26
+ level: 2,
27
+ controls: ['threat-model', 'design-review'],
28
+ },
29
+ // V2: Authentication
30
+ {
31
+ id: 'V2.1.1',
32
+ standard: 'owasp-asvs-l1',
33
+ category: 'Authentication',
34
+ title: 'Password Length',
35
+ description: 'Verify that user passwords are at least 12 characters',
36
+ level: 1,
37
+ controls: ['password-policy', 'input-validation'],
38
+ },
39
+ {
40
+ id: 'V2.1.2',
41
+ standard: 'owasp-asvs-l1',
42
+ category: 'Authentication',
43
+ title: 'Password Complexity',
44
+ description: 'Verify that passwords can contain spaces and all printable characters',
45
+ level: 1,
46
+ controls: ['password-policy'],
47
+ },
48
+ {
49
+ id: 'V2.2.1',
50
+ standard: 'owasp-asvs-l1',
51
+ category: 'Authentication',
52
+ title: 'Anti-Automation',
53
+ description: 'Verify that anti-automation controls are in place',
54
+ level: 1,
55
+ controls: ['rate-limiting', 'captcha'],
56
+ },
57
+ {
58
+ id: 'V2.5.1',
59
+ standard: 'owasp-asvs-l1',
60
+ category: 'Authentication',
61
+ title: 'Credential Recovery',
62
+ description: 'Verify that credential recovery does not reveal current password',
63
+ level: 1,
64
+ controls: ['password-reset', 'secure-recovery'],
65
+ },
66
+ // V3: Session Management
67
+ {
68
+ id: 'V3.1.1',
69
+ standard: 'owasp-asvs-l1',
70
+ category: 'Session Management',
71
+ title: 'Secure Session Tokens',
72
+ description: 'Verify that the app generates a new session token on authentication',
73
+ level: 1,
74
+ controls: ['session-management', 'token-generation'],
75
+ },
76
+ {
77
+ id: 'V3.2.1',
78
+ standard: 'owasp-asvs-l1',
79
+ category: 'Session Management',
80
+ title: 'Session Binding',
81
+ description: 'Verify that session tokens are bound to the user',
82
+ level: 1,
83
+ controls: ['session-binding', 'cookie-security'],
84
+ },
85
+ {
86
+ id: 'V3.3.1',
87
+ standard: 'owasp-asvs-l1',
88
+ category: 'Session Management',
89
+ title: 'Session Timeout',
90
+ description: 'Verify that session times out after inactivity',
91
+ level: 1,
92
+ controls: ['session-timeout', 'idle-timeout'],
93
+ },
94
+ // V4: Access Control
95
+ {
96
+ id: 'V4.1.1',
97
+ standard: 'owasp-asvs-l1',
98
+ category: 'Access Control',
99
+ title: 'Access Control Policy',
100
+ description: 'Verify that the app enforces access control rules on trusted service layer',
101
+ level: 1,
102
+ controls: ['access-control', 'authorization'],
103
+ },
104
+ {
105
+ id: 'V4.1.2',
106
+ standard: 'owasp-asvs-l1',
107
+ category: 'Access Control',
108
+ title: 'Sensitive Data Access',
109
+ description: 'Verify that sensitive data and APIs are protected',
110
+ level: 1,
111
+ controls: ['data-protection', 'api-security'],
112
+ },
113
+ {
114
+ id: 'V4.2.1',
115
+ standard: 'owasp-asvs-l1',
116
+ category: 'Access Control',
117
+ title: 'Secure Direct Object References',
118
+ description: 'Verify that users can only access authorized data',
119
+ level: 1,
120
+ controls: ['idor-prevention', 'authorization'],
121
+ },
122
+ // V5: Validation
123
+ {
124
+ id: 'V5.1.1',
125
+ standard: 'owasp-asvs-l1',
126
+ category: 'Input Validation',
127
+ title: 'Input Validation',
128
+ description: 'Verify that input validation is performed on all input',
129
+ level: 1,
130
+ controls: ['input-validation', 'sanitization'],
131
+ },
132
+ {
133
+ id: 'V5.2.1',
134
+ standard: 'owasp-asvs-l1',
135
+ category: 'Input Validation',
136
+ title: 'Sanitization',
137
+ description: 'Verify that output encoding is applied to prevent XSS',
138
+ level: 1,
139
+ controls: ['output-encoding', 'xss-prevention'],
140
+ },
141
+ {
142
+ id: 'V5.3.1',
143
+ standard: 'owasp-asvs-l1',
144
+ category: 'Input Validation',
145
+ title: 'SQL Injection Prevention',
146
+ description: 'Verify that parameterized queries are used',
147
+ level: 1,
148
+ controls: ['parameterized-queries', 'sql-injection'],
149
+ },
150
+ // V6: Cryptography
151
+ {
152
+ id: 'V6.1.1',
153
+ standard: 'owasp-asvs-l1',
154
+ category: 'Cryptography',
155
+ title: 'Data Classification',
156
+ description: 'Verify that regulated data is stored encrypted',
157
+ level: 1,
158
+ controls: ['encryption-at-rest', 'data-classification'],
159
+ },
160
+ {
161
+ id: 'V6.2.1',
162
+ standard: 'owasp-asvs-l1',
163
+ category: 'Cryptography',
164
+ title: 'Strong Algorithms',
165
+ description: 'Verify that only approved cryptographic algorithms are used',
166
+ level: 1,
167
+ controls: ['crypto-algorithms', 'key-management'],
168
+ },
169
+ // V7: Error Handling
170
+ {
171
+ id: 'V7.1.1',
172
+ standard: 'owasp-asvs-l1',
173
+ category: 'Error Handling',
174
+ title: 'Error Logging',
175
+ description: 'Verify that the app logs security events',
176
+ level: 1,
177
+ controls: ['logging', 'audit-trail'],
178
+ },
179
+ {
180
+ id: 'V7.2.1',
181
+ standard: 'owasp-asvs-l1',
182
+ category: 'Error Handling',
183
+ title: 'Generic Error Messages',
184
+ description: 'Verify that error messages do not leak sensitive information',
185
+ level: 1,
186
+ controls: ['error-handling', 'information-disclosure'],
187
+ },
188
+ // V8: Data Protection
189
+ {
190
+ id: 'V8.1.1',
191
+ standard: 'owasp-asvs-l1',
192
+ category: 'Data Protection',
193
+ title: 'Sensitive Data Protection',
194
+ description: 'Verify that sensitive data is protected in transit',
195
+ level: 1,
196
+ controls: ['tls', 'encryption-in-transit'],
197
+ },
198
+ {
199
+ id: 'V8.2.1',
200
+ standard: 'owasp-asvs-l1',
201
+ category: 'Data Protection',
202
+ title: 'Client-side Data Protection',
203
+ description: 'Verify that sensitive data is not cached on client',
204
+ level: 1,
205
+ controls: ['cache-control', 'client-storage'],
206
+ },
207
+ ];
208
+ /**
209
+ * PCI-DSS Requirements Database
210
+ */
211
+ const PCI_DSS_REQUIREMENTS = [
212
+ {
213
+ id: 'PCI-1.1',
214
+ standard: 'pci-dss',
215
+ category: 'Network Security',
216
+ title: 'Firewall Configuration',
217
+ description: 'Install and maintain firewall configurations',
218
+ level: 1,
219
+ controls: ['firewall', 'network-segmentation'],
220
+ },
221
+ {
222
+ id: 'PCI-2.1',
223
+ standard: 'pci-dss',
224
+ category: 'Secure Configuration',
225
+ title: 'Default Credentials',
226
+ description: 'Change vendor-supplied defaults',
227
+ level: 1,
228
+ controls: ['credential-management', 'configuration'],
229
+ },
230
+ {
231
+ id: 'PCI-3.1',
232
+ standard: 'pci-dss',
233
+ category: 'Data Protection',
234
+ title: 'Stored Data Protection',
235
+ description: 'Protect stored cardholder data',
236
+ level: 1,
237
+ controls: ['encryption', 'data-masking'],
238
+ },
239
+ {
240
+ id: 'PCI-4.1',
241
+ standard: 'pci-dss',
242
+ category: 'Encryption',
243
+ title: 'Transmission Encryption',
244
+ description: 'Encrypt transmission of cardholder data',
245
+ level: 1,
246
+ controls: ['tls', 'certificate-management'],
247
+ },
248
+ {
249
+ id: 'PCI-6.1',
250
+ standard: 'pci-dss',
251
+ category: 'Vulnerability Management',
252
+ title: 'Security Patching',
253
+ description: 'Deploy critical security patches within one month',
254
+ level: 1,
255
+ controls: ['patch-management', 'vulnerability-scanning'],
256
+ },
257
+ {
258
+ id: 'PCI-6.5',
259
+ standard: 'pci-dss',
260
+ category: 'Secure Development',
261
+ title: 'Secure Coding',
262
+ description: 'Develop applications based on secure coding guidelines',
263
+ level: 1,
264
+ controls: ['secure-sdlc', 'code-review'],
265
+ },
266
+ {
267
+ id: 'PCI-8.1',
268
+ standard: 'pci-dss',
269
+ category: 'Access Control',
270
+ title: 'User Identification',
271
+ description: 'Assign unique IDs to each person with access',
272
+ level: 1,
273
+ controls: ['identity-management', 'user-provisioning'],
274
+ },
275
+ {
276
+ id: 'PCI-10.1',
277
+ standard: 'pci-dss',
278
+ category: 'Logging',
279
+ title: 'Audit Logging',
280
+ description: 'Implement audit trails for system components',
281
+ level: 1,
282
+ controls: ['audit-logging', 'log-management'],
283
+ },
284
+ ];
285
+ const COMPLIANCE_PATTERNS = [
286
+ // Password validation
287
+ {
288
+ id: 'CP-001',
289
+ name: 'Weak Password Check',
290
+ pattern: /password\.length\s*[<>=]+\s*[0-8]\b/gi,
291
+ type: 'absent',
292
+ relatedControls: ['password-policy'],
293
+ severity: 'high',
294
+ },
295
+ // SQL Injection
296
+ {
297
+ id: 'CP-002',
298
+ name: 'SQL String Concatenation',
299
+ pattern: /(?:query|sql|execute)\s*\(\s*['"`].*\$\{|query\s*\+\s*(?:req|user|input)/gi,
300
+ type: 'absent',
301
+ relatedControls: ['parameterized-queries', 'sql-injection'],
302
+ severity: 'critical',
303
+ },
304
+ // Rate Limiting
305
+ {
306
+ id: 'CP-003',
307
+ name: 'Rate Limiting Present',
308
+ pattern: /rateLimit|rateLimiter|throttle|express-rate-limit/gi,
309
+ type: 'present',
310
+ relatedControls: ['rate-limiting'],
311
+ severity: 'medium',
312
+ },
313
+ // Session Management
314
+ {
315
+ id: 'CP-004',
316
+ name: 'Session Configuration',
317
+ pattern: /session\s*\(\s*\{[^}]*(?:secure|httpOnly|sameSite)/gi,
318
+ type: 'present',
319
+ relatedControls: ['session-management', 'cookie-security'],
320
+ severity: 'high',
321
+ },
322
+ // TLS/HTTPS
323
+ {
324
+ id: 'CP-005',
325
+ name: 'HTTP Redirect',
326
+ pattern: /app\.use\([^)]*redirect[^)]*https|forceHTTPS|requireHTTPS/gi,
327
+ type: 'present',
328
+ relatedControls: ['tls', 'encryption-in-transit'],
329
+ severity: 'high',
330
+ },
331
+ // Crypto
332
+ {
333
+ id: 'CP-006',
334
+ name: 'Weak Crypto Algorithm',
335
+ pattern: /createHash\s*\(\s*['"](?:md5|sha1)['"]\s*\)|DES|RC4|MD5/gi,
336
+ type: 'absent',
337
+ relatedControls: ['crypto-algorithms'],
338
+ severity: 'high',
339
+ },
340
+ // Input Validation
341
+ {
342
+ id: 'CP-007',
343
+ name: 'Input Validation',
344
+ pattern: /(?:validator|joi|yup|zod)\.(?:string|number|object)|validate\s*\(/gi,
345
+ type: 'present',
346
+ relatedControls: ['input-validation'],
347
+ severity: 'medium',
348
+ },
349
+ // Output Encoding
350
+ {
351
+ id: 'CP-008',
352
+ name: 'XSS Prevention',
353
+ pattern: /(?:escape|encode|sanitize)(?:Html|Xml|Url)|DOMPurify|xss/gi,
354
+ type: 'present',
355
+ relatedControls: ['output-encoding', 'xss-prevention'],
356
+ severity: 'high',
357
+ },
358
+ // Logging
359
+ {
360
+ id: 'CP-009',
361
+ name: 'Security Logging',
362
+ pattern: /(?:logger|log)\.(?:security|audit|info)\s*\(|winston|pino|bunyan/gi,
363
+ type: 'present',
364
+ relatedControls: ['logging', 'audit-trail'],
365
+ severity: 'medium',
366
+ },
367
+ // Error Handling
368
+ {
369
+ id: 'CP-010',
370
+ name: 'Error Information Disclosure',
371
+ pattern: /(?:res|response)\.(?:send|json)\s*\(\s*(?:err|error)(?:\.stack|\.message)?[^,)]*\)/gi,
372
+ type: 'absent',
373
+ relatedControls: ['error-handling', 'information-disclosure'],
374
+ severity: 'medium',
375
+ },
376
+ // Access Control
377
+ {
378
+ id: 'CP-011',
379
+ name: 'Authorization Check',
380
+ pattern: /(?:isAuthorized|checkPermission|requireRole|hasAccess|authorize)\s*\(/gi,
381
+ type: 'present',
382
+ relatedControls: ['access-control', 'authorization'],
383
+ severity: 'high',
384
+ },
385
+ // IDOR Prevention
386
+ {
387
+ id: 'CP-012',
388
+ name: 'User ID Verification',
389
+ pattern: /(?:user\.id|userId|currentUser)\s*===?\s*(?:req\.params|params|id)/gi,
390
+ type: 'present',
391
+ relatedControls: ['idor-prevention'],
392
+ severity: 'high',
393
+ },
394
+ ];
395
+ /**
396
+ * Compliance Checker
397
+ * @trace DES-SEC3-COMPLIANCE-001
398
+ */
399
+ export class ComplianceChecker {
400
+ options;
401
+ requirements;
402
+ constructor(options = {}) {
403
+ this.options = {
404
+ standards: options.standards ?? ['owasp-asvs-l1'],
405
+ level: options.level ?? 1,
406
+ includeEvidence: options.includeEvidence ?? true,
407
+ skipCategories: options.skipCategories ?? [],
408
+ };
409
+ // Initialize requirements database
410
+ this.requirements = new Map();
411
+ this.requirements.set('owasp-asvs-l1', ASVS_REQUIREMENTS.filter(r => r.level <= 1));
412
+ this.requirements.set('owasp-asvs-l2', ASVS_REQUIREMENTS.filter(r => r.level <= 2));
413
+ this.requirements.set('owasp-asvs-l3', ASVS_REQUIREMENTS);
414
+ this.requirements.set('pci-dss', PCI_DSS_REQUIREMENTS);
415
+ }
416
+ /**
417
+ * Check compliance against a standard
418
+ * @trace REQ-SEC3-COMPLIANCE-001
419
+ */
420
+ async check(code, filePath, standard) {
421
+ const targetStandard = standard ?? this.options.standards[0];
422
+ const requirements = this.getRequirementsInternal(targetStandard);
423
+ const results = [];
424
+ let passed = 0;
425
+ let failed = 0;
426
+ let partial = 0;
427
+ let notApplicable = 0;
428
+ for (const requirement of requirements) {
429
+ // Skip excluded categories
430
+ if (this.options.skipCategories.includes(requirement.category)) {
431
+ notApplicable++;
432
+ results.push({
433
+ requirement,
434
+ status: 'not-applicable',
435
+ findings: [],
436
+ evidence: ['Category excluded from scan'],
437
+ });
438
+ continue;
439
+ }
440
+ const result = this.checkRequirement(requirement, code, filePath);
441
+ results.push(result);
442
+ switch (result.status) {
443
+ case 'pass':
444
+ passed++;
445
+ break;
446
+ case 'fail':
447
+ failed++;
448
+ break;
449
+ case 'partial':
450
+ partial++;
451
+ break;
452
+ case 'not-applicable':
453
+ notApplicable++;
454
+ break;
455
+ }
456
+ }
457
+ const total = requirements.length;
458
+ const applicable = total - notApplicable;
459
+ const score = applicable > 0 ? Math.round((passed / applicable) * 100) : 100;
460
+ return {
461
+ standard: targetStandard,
462
+ timestamp: new Date(),
463
+ overallStatus: this.determineOverallStatus(passed, failed, partial, applicable),
464
+ score,
465
+ totalRequirements: total,
466
+ passedRequirements: passed,
467
+ failedRequirements: failed,
468
+ partialRequirements: partial,
469
+ notApplicable,
470
+ results,
471
+ summary: this.generateSummary(results),
472
+ };
473
+ }
474
+ /**
475
+ * Check multiple files for compliance
476
+ */
477
+ async checkFiles(files, standard) {
478
+ const combinedCode = files.map(f => `// FILE: ${f.path}\n${f.content}`).join('\n\n');
479
+ return this.check(combinedCode, 'combined', standard);
480
+ }
481
+ /**
482
+ * Alias for check() - Check compliance against a standard with empty code
483
+ * Used for obtaining compliance reports without actual code analysis
484
+ */
485
+ async checkCompliance(standard) {
486
+ const report = await this.check('', 'compliance-check', standard);
487
+ return {
488
+ standard: report.standard,
489
+ timestamp: report.timestamp,
490
+ findings: report.results.map(r => ({
491
+ requirement: r.requirement,
492
+ status: r.status,
493
+ evidence: r.evidence?.join('; '),
494
+ })),
495
+ summary: {
496
+ totalRequirements: report.totalRequirements,
497
+ passed: report.passedRequirements,
498
+ failed: report.failedRequirements,
499
+ notApplicable: report.notApplicable,
500
+ compliancePercentage: report.score,
501
+ byCategory: Object.entries(report.summary.byCategory).map(([category, data]) => ({
502
+ category,
503
+ passed: data.passed,
504
+ failed: data.failed,
505
+ })),
506
+ },
507
+ };
508
+ }
509
+ /**
510
+ * Check all configured standards
511
+ */
512
+ async checkAllStandards() {
513
+ const results = [];
514
+ for (const standard of this.options.standards) {
515
+ results.push(await this.checkCompliance(standard));
516
+ }
517
+ return results;
518
+ }
519
+ /**
520
+ * Get list of supported compliance standards
521
+ */
522
+ getSupportedStandards() {
523
+ return Array.from(this.requirements.keys());
524
+ }
525
+ /**
526
+ * Get requirements for a specific standard (public accessor)
527
+ */
528
+ getRequirements(standard) {
529
+ return this.getRequirementsInternal(standard);
530
+ }
531
+ /**
532
+ * Check a specific requirement
533
+ */
534
+ checkRequirement(requirement, code, filePath) {
535
+ const findings = [];
536
+ const evidence = [];
537
+ let passCount = 0;
538
+ let failCount = 0;
539
+ // Check code patterns related to this requirement
540
+ for (const pattern of COMPLIANCE_PATTERNS) {
541
+ const hasOverlap = pattern.relatedControls.some(c => requirement.controls.includes(c));
542
+ if (!hasOverlap)
543
+ continue;
544
+ const matches = code.match(pattern.pattern);
545
+ if (pattern.type === 'present') {
546
+ if (matches && matches.length > 0) {
547
+ passCount++;
548
+ if (this.options.includeEvidence) {
549
+ evidence.push(`Found ${pattern.name}: ${matches.slice(0, 3).join(', ')}`);
550
+ }
551
+ }
552
+ else {
553
+ failCount++;
554
+ findings.push({
555
+ id: `${requirement.id}-${pattern.id}`,
556
+ requirementId: requirement.id,
557
+ severity: pattern.severity,
558
+ location: { file: filePath },
559
+ description: `Missing ${pattern.name}`,
560
+ evidence: 'Pattern not found in code',
561
+ recommendation: `Implement ${pattern.name} to meet ${requirement.title}`,
562
+ });
563
+ }
564
+ }
565
+ else {
566
+ // type === 'absent'
567
+ if (matches && matches.length > 0) {
568
+ failCount++;
569
+ // Find line numbers
570
+ const lines = code.split('\n');
571
+ for (let i = 0; i < lines.length; i++) {
572
+ if (pattern.pattern.test(lines[i])) {
573
+ findings.push({
574
+ id: `${requirement.id}-${pattern.id}-L${i + 1}`,
575
+ requirementId: requirement.id,
576
+ severity: pattern.severity,
577
+ location: { file: filePath, line: i + 1 },
578
+ description: `Found problematic pattern: ${pattern.name}`,
579
+ evidence: lines[i].trim().substring(0, 100),
580
+ recommendation: `Remove or fix ${pattern.name} to meet ${requirement.title}`,
581
+ });
582
+ }
583
+ // Reset regex lastIndex
584
+ pattern.pattern.lastIndex = 0;
585
+ }
586
+ }
587
+ else {
588
+ passCount++;
589
+ if (this.options.includeEvidence) {
590
+ evidence.push(`No ${pattern.name} found (good)`);
591
+ }
592
+ }
593
+ }
594
+ // Reset regex lastIndex
595
+ pattern.pattern.lastIndex = 0;
596
+ }
597
+ // Determine status
598
+ let status;
599
+ if (failCount === 0 && passCount > 0) {
600
+ status = 'pass';
601
+ }
602
+ else if (passCount === 0 && failCount > 0) {
603
+ status = 'fail';
604
+ }
605
+ else if (passCount > 0 && failCount > 0) {
606
+ status = 'partial';
607
+ }
608
+ else {
609
+ status = 'not-applicable';
610
+ }
611
+ return {
612
+ requirement,
613
+ status,
614
+ findings,
615
+ evidence,
616
+ remediationSteps: findings.length > 0
617
+ ? findings.map(f => f.recommendation)
618
+ : undefined,
619
+ };
620
+ }
621
+ /**
622
+ * Get requirements for a standard (internal)
623
+ */
624
+ getRequirementsInternal(standard) {
625
+ const reqs = this.requirements.get(standard);
626
+ if (!reqs) {
627
+ // Return ASVS L1 as default
628
+ return this.requirements.get('owasp-asvs-l1') ?? [];
629
+ }
630
+ return reqs.filter(r => r.level <= this.options.level);
631
+ }
632
+ /**
633
+ * Determine overall compliance status
634
+ */
635
+ determineOverallStatus(passed, failed, partial, applicable) {
636
+ if (applicable === 0)
637
+ return 'compliant';
638
+ if (failed === 0 && partial === 0)
639
+ return 'compliant';
640
+ if (passed === 0)
641
+ return 'non-compliant';
642
+ return 'partial';
643
+ }
644
+ /**
645
+ * Generate compliance summary
646
+ */
647
+ generateSummary(results) {
648
+ const byCategory = {};
649
+ const criticalFindings = [];
650
+ const remediations = new Set();
651
+ for (const result of results) {
652
+ const category = result.requirement.category;
653
+ if (!byCategory[category]) {
654
+ byCategory[category] = {
655
+ total: 0,
656
+ passed: 0,
657
+ failed: 0,
658
+ partial: 0,
659
+ percentage: 0,
660
+ };
661
+ }
662
+ byCategory[category].total++;
663
+ switch (result.status) {
664
+ case 'pass':
665
+ byCategory[category].passed++;
666
+ break;
667
+ case 'fail':
668
+ byCategory[category].failed++;
669
+ break;
670
+ case 'partial':
671
+ byCategory[category].partial++;
672
+ break;
673
+ }
674
+ // Collect critical findings
675
+ for (const finding of result.findings) {
676
+ if (finding.severity === 'critical' || finding.severity === 'high') {
677
+ criticalFindings.push(finding);
678
+ }
679
+ remediations.add(finding.recommendation);
680
+ }
681
+ }
682
+ // Calculate percentages
683
+ for (const category of Object.keys(byCategory)) {
684
+ const cat = byCategory[category];
685
+ const applicable = cat.total - (results.filter(r => r.requirement.category === category && r.status === 'not-applicable').length);
686
+ cat.percentage = applicable > 0
687
+ ? Math.round((cat.passed / applicable) * 100)
688
+ : 100;
689
+ }
690
+ return {
691
+ byCategory,
692
+ criticalFindings: criticalFindings.slice(0, 10),
693
+ topRemediations: Array.from(remediations).slice(0, 5),
694
+ };
695
+ }
696
+ /**
697
+ * Convert compliance findings to vulnerabilities
698
+ */
699
+ toVulnerabilities(report) {
700
+ const vulnerabilities = [];
701
+ for (const result of report.results) {
702
+ for (const finding of result.findings) {
703
+ vulnerabilities.push({
704
+ id: finding.id,
705
+ type: 'configuration',
706
+ severity: finding.severity,
707
+ cwes: this.mapRequirementToCWE(result.requirement),
708
+ owasp: this.mapRequirementToOWASP(result.requirement),
709
+ location: {
710
+ file: finding.location?.file ?? 'unknown',
711
+ startLine: finding.location?.line ?? 1,
712
+ endLine: finding.location?.line ?? 1,
713
+ startColumn: 0,
714
+ endColumn: 0,
715
+ },
716
+ description: finding.description,
717
+ recommendation: finding.recommendation,
718
+ confidence: 0.85,
719
+ ruleId: result.requirement.id,
720
+ codeSnippet: finding.evidence,
721
+ detectedAt: new Date(),
722
+ });
723
+ }
724
+ }
725
+ return vulnerabilities;
726
+ }
727
+ /**
728
+ * Map requirement to CWE IDs
729
+ */
730
+ mapRequirementToCWE(requirement) {
731
+ const cweMappings = {
732
+ 'password-policy': ['CWE-521'],
733
+ 'sql-injection': ['CWE-89'],
734
+ 'xss-prevention': ['CWE-79'],
735
+ 'session-management': ['CWE-384'],
736
+ 'access-control': ['CWE-284'],
737
+ 'crypto-algorithms': ['CWE-327'],
738
+ 'logging': ['CWE-778'],
739
+ 'error-handling': ['CWE-209'],
740
+ 'tls': ['CWE-319'],
741
+ };
742
+ const cwes = [];
743
+ for (const control of requirement.controls) {
744
+ if (cweMappings[control]) {
745
+ cwes.push(...cweMappings[control]);
746
+ }
747
+ }
748
+ return [...new Set(cwes)];
749
+ }
750
+ /**
751
+ * Map requirement to OWASP categories
752
+ */
753
+ mapRequirementToOWASP(requirement) {
754
+ const owaspMappings = {
755
+ 'Authentication': ['A07:2021'],
756
+ 'Session Management': ['A07:2021'],
757
+ 'Access Control': ['A01:2021'],
758
+ 'Input Validation': ['A03:2021'],
759
+ 'Cryptography': ['A02:2021'],
760
+ 'Error Handling': ['A09:2021'],
761
+ 'Data Protection': ['A02:2021'],
762
+ };
763
+ return owaspMappings[requirement.category] ?? ['A00:Unknown'];
764
+ }
765
+ }
766
+ /**
767
+ * Create compliance checker instance
768
+ */
769
+ export function createComplianceChecker(options) {
770
+ return new ComplianceChecker(options);
771
+ }
772
+ //# sourceMappingURL=compliance-checker.js.map