0xray 2.1.2 → 2.1.3

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 (250) hide show
  1. package/.opencode/codex.codex +1 -1
  2. package/.opencode/commands/dependency-audit.md +3 -3
  3. package/.opencode/enforcer-config.json +2 -2
  4. package/AGENTS.md +2 -1
  5. package/README.md +12 -11
  6. package/dist/AGENTS.md +2 -1
  7. package/dist/CHANGELOG.md +26 -0
  8. package/dist/README.md +12 -11
  9. package/dist/agents/code-reviewer.js +1 -1
  10. package/dist/analytics/routing-refiner.js +1 -1
  11. package/dist/cli/index.js +11 -1
  12. package/dist/cli/server.js +3 -3
  13. package/dist/core/activity-logger.d.ts +2 -2
  14. package/dist/core/activity-logger.js +4 -4
  15. package/dist/core/boot-orchestrator.d.ts +1 -1
  16. package/dist/core/boot-orchestrator.js +13 -28
  17. package/dist/core/bridge.mjs +3 -3
  18. package/dist/core/codex-formatter.js +2 -2
  19. package/dist/core/codex-injector.d.ts +0 -1
  20. package/dist/core/codex-injector.js +2 -3
  21. package/dist/core/config-loader.d.ts +1 -1
  22. package/dist/core/config-loader.js +1 -1
  23. package/dist/core/config-paths.d.ts +0 -2
  24. package/dist/core/config-paths.js +7 -8
  25. package/dist/core/context-loader.d.ts +1 -1
  26. package/dist/core/context-loader.js +1 -1
  27. package/dist/core/errors.d.ts +3 -0
  28. package/dist/core/errors.js +10 -0
  29. package/dist/core/features-config.js +1 -1
  30. package/dist/core/framework-logger.d.ts +3 -3
  31. package/dist/core/framework-logger.js +17 -9
  32. package/dist/core/index.d.ts +2 -2
  33. package/dist/core/index.js +4 -2
  34. package/dist/core/logging-config.d.ts +2 -1
  35. package/dist/core/logging-config.js +7 -7
  36. package/dist/enforcement/loaders/codex-loader.js +1 -1
  37. package/dist/execution/opencode-cli-invoker.js +5 -5
  38. package/dist/governance/governance-service.js +1 -1
  39. package/dist/index.d.ts +3 -3
  40. package/dist/index.js +3 -3
  41. package/dist/inference/inference-cycle.d.ts +1 -1
  42. package/dist/inference/inference-cycle.js +10 -10
  43. package/dist/integrations/base/Integration.js +1 -1
  44. package/dist/integrations/base/registry.js +19 -19
  45. package/dist/integrations/grok/grok-cli.js +17 -17
  46. package/dist/integrations/grok/hooks/pre-tool-use.js +1 -1
  47. package/dist/integrations/hermes-agent/bridge.mjs +1 -1
  48. package/dist/integrations/openclaw/api-server.d.ts +0 -1
  49. package/dist/integrations/openclaw/api-server.js +7 -10
  50. package/dist/integrations/openclaw/client.d.ts +0 -1
  51. package/dist/integrations/openclaw/client.js +22 -24
  52. package/dist/integrations/openclaw/hooks/xray-hooks.d.ts +0 -1
  53. package/dist/integrations/openclaw/hooks/xray-hooks.js +17 -18
  54. package/dist/integrations/plugins/plugin-registry.js +5 -5
  55. package/dist/mcps/architect-tools.server.d.ts +2 -4
  56. package/dist/mcps/architect-tools.server.js +112 -195
  57. package/dist/mcps/auto-format.server.d.ts +2 -4
  58. package/dist/mcps/auto-format.server.js +49 -95
  59. package/dist/mcps/boot-orchestrator.server.d.ts +2 -4
  60. package/dist/mcps/boot-orchestrator.server.js +73 -105
  61. package/dist/mcps/config/server-config-registry.js +3 -3
  62. package/dist/mcps/enforcer-tools.server.d.ts +2 -4
  63. package/dist/mcps/enforcer-tools.server.js +202 -285
  64. package/dist/mcps/estimation.server.d.ts +2 -4
  65. package/dist/mcps/estimation.server.js +63 -107
  66. package/dist/mcps/framework-compliance-audit.server.d.ts +2 -4
  67. package/dist/mcps/framework-compliance-audit.server.js +53 -82
  68. package/dist/mcps/framework-help.server.d.ts +2 -4
  69. package/dist/mcps/framework-help.server.js +63 -101
  70. package/dist/mcps/governance.server.js +2 -2
  71. package/dist/mcps/knowledge-skills/api-design.server.d.ts +2 -4
  72. package/dist/mcps/knowledge-skills/api-design.server.js +35 -67
  73. package/dist/mcps/knowledge-skills/architecture-patterns.server.d.ts +2 -10
  74. package/dist/mcps/knowledge-skills/architecture-patterns.server.js +35 -74
  75. package/dist/mcps/knowledge-skills/bug-triage-specialist.server.d.ts +2 -4
  76. package/dist/mcps/knowledge-skills/bug-triage-specialist.server.js +143 -162
  77. package/dist/mcps/knowledge-skills/code-analyzer.server.d.ts +3 -4
  78. package/dist/mcps/knowledge-skills/code-analyzer.server.js +20 -45
  79. package/dist/mcps/knowledge-skills/code-review.server.d.ts +2 -4
  80. package/dist/mcps/knowledge-skills/code-review.server.js +109 -143
  81. package/dist/mcps/knowledge-skills/content-creator.server.d.ts +2 -4
  82. package/dist/mcps/knowledge-skills/content-creator.server.js +205 -226
  83. package/dist/mcps/knowledge-skills/database-design.server.d.ts +2 -4
  84. package/dist/mcps/knowledge-skills/database-design.server.js +117 -151
  85. package/dist/mcps/knowledge-skills/devops-deployment.server.d.ts +2 -4
  86. package/dist/mcps/knowledge-skills/devops-deployment.server.js +71 -160
  87. package/dist/mcps/knowledge-skills/git-workflow.server.d.ts +2 -4
  88. package/dist/mcps/knowledge-skills/git-workflow.server.js +36 -68
  89. package/dist/mcps/knowledge-skills/growth-strategist.server.d.ts +2 -4
  90. package/dist/mcps/knowledge-skills/growth-strategist.server.js +303 -324
  91. package/dist/mcps/knowledge-skills/log-monitor.server.d.ts +2 -4
  92. package/dist/mcps/knowledge-skills/log-monitor.server.js +141 -160
  93. package/dist/mcps/knowledge-skills/mobile-development.server.d.ts +2 -4
  94. package/dist/mcps/knowledge-skills/mobile-development.server.js +92 -209
  95. package/dist/mcps/knowledge-skills/multimodal-looker.server.d.ts +2 -4
  96. package/dist/mcps/knowledge-skills/multimodal-looker.server.js +123 -159
  97. package/dist/mcps/knowledge-skills/performance-optimization.server.d.ts +2 -5
  98. package/dist/mcps/knowledge-skills/performance-optimization.server.js +155 -296
  99. package/dist/mcps/knowledge-skills/project-analysis.server.d.ts +2 -4
  100. package/dist/mcps/knowledge-skills/project-analysis.server.js +75 -226
  101. package/dist/mcps/knowledge-skills/refactoring-strategies.server.d.ts +2 -4
  102. package/dist/mcps/knowledge-skills/refactoring-strategies.server.js +63 -156
  103. package/dist/mcps/knowledge-skills/security-audit.server.d.ts +2 -4
  104. package/dist/mcps/knowledge-skills/security-audit.server.js +102 -136
  105. package/dist/mcps/knowledge-skills/seo-consultant.server.d.ts +2 -4
  106. package/dist/mcps/knowledge-skills/seo-consultant.server.js +80 -203
  107. package/dist/mcps/knowledge-skills/session-management.server.d.ts +2 -4
  108. package/dist/mcps/knowledge-skills/session-management.server.js +50 -203
  109. package/dist/mcps/knowledge-skills/skill-invocation.server.d.ts +2 -4
  110. package/dist/mcps/knowledge-skills/skill-invocation.server.js +168 -347
  111. package/dist/mcps/knowledge-skills/strategist.server.d.ts +2 -11
  112. package/dist/mcps/knowledge-skills/strategist.server.js +72 -122
  113. package/dist/mcps/knowledge-skills/tech-writer.server.d.ts +2 -4
  114. package/dist/mcps/knowledge-skills/tech-writer.server.js +87 -300
  115. package/dist/mcps/knowledge-skills/testing-best-practices.server.d.ts +2 -4
  116. package/dist/mcps/knowledge-skills/testing-best-practices.server.js +147 -182
  117. package/dist/mcps/knowledge-skills/testing-strategy.server.d.ts +2 -4
  118. package/dist/mcps/knowledge-skills/testing-strategy.server.js +78 -153
  119. package/dist/mcps/knowledge-skills/ui-ux-design.server.d.ts +2 -5
  120. package/dist/mcps/knowledge-skills/ui-ux-design.server.js +90 -399
  121. package/dist/mcps/lint.server.d.ts +2 -4
  122. package/dist/mcps/lint.server.js +51 -92
  123. package/dist/mcps/mcp-client.js +2 -2
  124. package/dist/mcps/model-health-check.server.d.ts +2 -4
  125. package/dist/mcps/model-health-check.server.js +32 -60
  126. package/dist/mcps/performance-analysis.server.d.ts +2 -4
  127. package/dist/mcps/performance-analysis.server.js +57 -88
  128. package/dist/mcps/processor-pipeline.server.d.ts +2 -4
  129. package/dist/mcps/processor-pipeline.server.js +69 -100
  130. package/dist/mcps/registry.json +1 -1
  131. package/dist/mcps/researcher.server.d.ts +3 -5
  132. package/dist/mcps/researcher.server.js +81 -154
  133. package/dist/mcps/security-scan.server.d.ts +2 -4
  134. package/dist/mcps/security-scan.server.js +54 -96
  135. package/dist/mcps/shared/knowledge-skill-base.d.ts +14 -0
  136. package/dist/mcps/shared/knowledge-skill-base.js +45 -0
  137. package/dist/{security → mcps/shared}/security-scanner.js +1 -1
  138. package/dist/mcps/state-manager.server.d.ts +2 -4
  139. package/dist/mcps/state-manager.server.js +115 -160
  140. package/dist/orchestrator/orchestrator.d.ts +1 -1
  141. package/dist/orchestrator/orchestrator.js +1 -1
  142. package/dist/orchestrator/universal-registry-bridge.js +1 -1
  143. package/dist/plugin/xray-codex-injection.d.ts +1 -1
  144. package/dist/plugin/xray-codex-injection.js +1 -1
  145. package/dist/postprocessor/PostProcessor.d.ts +4 -44
  146. package/dist/postprocessor/PostProcessor.js +39 -553
  147. package/dist/postprocessor/analysis/CodeChangeAnalyzer.d.ts +11 -0
  148. package/dist/postprocessor/analysis/CodeChangeAnalyzer.js +50 -0
  149. package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.d.ts +11 -0
  150. package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.js +356 -0
  151. package/dist/postprocessor/config/ProcessorConfigLoader.d.ts +44 -0
  152. package/dist/postprocessor/config/ProcessorConfigLoader.js +21 -0
  153. package/dist/postprocessor/reporting/PostProcessorReporter.d.ts +19 -0
  154. package/dist/postprocessor/reporting/PostProcessorReporter.js +96 -0
  155. package/dist/postprocessor/triggers/GitHookTrigger.js +11 -11
  156. package/dist/processors/implementations/refactoring-logging-processor-wrapper.d.ts +32 -0
  157. package/dist/processors/implementations/refactoring-logging-processor-wrapper.js +95 -1
  158. package/dist/processors/processor-manager.js +346 -314
  159. package/dist/reporting/report-formatter.js +1 -1
  160. package/dist/security/security-hardener.d.ts +69 -2
  161. package/dist/security/security-hardener.js +129 -1
  162. package/dist/skills/registry.json +1 -1
  163. package/dist/state/index.d.ts +3 -5
  164. package/dist/state/index.js +1 -7
  165. package/dist/state/state-manager.d.ts +1 -1
  166. package/dist/state/state-manager.js +2 -3
  167. package/package.json +13 -10
  168. package/scripts/node/universal-version-manager.js +11 -11
  169. package/src/mcps/architect-tools.server.ts +112 -215
  170. package/src/mcps/auto-format.server.ts +50 -110
  171. package/src/mcps/boot-orchestrator.server.ts +75 -121
  172. package/src/mcps/config/__tests__/server-config-registry.test.ts +21 -12
  173. package/src/mcps/config/server-config-registry.ts +3 -3
  174. package/src/mcps/enforcer-tools.server.ts +212 -310
  175. package/src/mcps/estimation.server.ts +62 -122
  176. package/src/mcps/framework-compliance-audit.server.ts +52 -97
  177. package/src/mcps/framework-help.server.ts +64 -114
  178. package/src/mcps/governance.server.ts +2 -2
  179. package/src/mcps/knowledge-skills/api-design.server.ts +32 -77
  180. package/src/mcps/knowledge-skills/architecture-patterns.server.ts +31 -87
  181. package/src/mcps/knowledge-skills/bug-triage-specialist.server.ts +165 -193
  182. package/src/mcps/knowledge-skills/code-analyzer.server.ts +20 -55
  183. package/src/mcps/knowledge-skills/code-review.server.ts +114 -161
  184. package/src/mcps/knowledge-skills/content-creator.server.ts +218 -255
  185. package/src/mcps/knowledge-skills/database-design.server.ts +118 -165
  186. package/src/mcps/knowledge-skills/devops-deployment.server.ts +67 -172
  187. package/src/mcps/knowledge-skills/git-workflow.server.ts +32 -77
  188. package/src/mcps/knowledge-skills/growth-strategist.server.ts +324 -361
  189. package/src/mcps/knowledge-skills/log-monitor.server.ts +160 -187
  190. package/src/mcps/knowledge-skills/mobile-development.server.ts +89 -223
  191. package/src/mcps/knowledge-skills/multimodal-looker.server.ts +128 -175
  192. package/src/mcps/knowledge-skills/performance-optimization.server.ts +156 -329
  193. package/src/mcps/knowledge-skills/project-analysis.server.ts +72 -248
  194. package/src/mcps/knowledge-skills/refactoring-strategies.server.ts +59 -171
  195. package/src/mcps/knowledge-skills/security-audit.server.ts +104 -151
  196. package/src/mcps/knowledge-skills/seo-consultant.server.ts +80 -220
  197. package/src/mcps/knowledge-skills/session-management.server.ts +51 -232
  198. package/src/mcps/knowledge-skills/skill-invocation.server.ts +165 -372
  199. package/src/mcps/knowledge-skills/strategist.server.ts +72 -143
  200. package/src/mcps/knowledge-skills/tech-writer.server.ts +85 -350
  201. package/src/mcps/knowledge-skills/testing-best-practices.server.ts +146 -195
  202. package/src/mcps/knowledge-skills/testing-strategy.server.ts +75 -161
  203. package/src/mcps/knowledge-skills/ui-ux-design.server.ts +93 -487
  204. package/src/mcps/lint.server.ts +53 -107
  205. package/src/mcps/mcp-client.ts +2 -2
  206. package/src/mcps/model-health-check.server.ts +34 -71
  207. package/src/mcps/performance-analysis.server.ts +60 -104
  208. package/src/mcps/processor-pipeline.server.ts +72 -110
  209. package/src/mcps/registry.json +1 -1
  210. package/src/mcps/researcher.server.ts +88 -177
  211. package/src/mcps/security-scan.server.ts +55 -104
  212. package/src/mcps/shared/knowledge-skill-base.ts +62 -0
  213. package/src/mcps/shared/prompt-security-validator.ts +199 -0
  214. package/src/mcps/shared/security-scanner.ts +599 -0
  215. package/src/mcps/state-manager.server.ts +117 -175
  216. package/src/opencode/codex.codex +1 -1
  217. package/src/opencode/commands/dependency-audit.md +3 -3
  218. package/src/opencode/enforcer-config.json +2 -2
  219. package/src/skills/registry.json +1 -1
  220. package/xray/codex.json +1 -1
  221. package/xray/config.json +1 -1
  222. package/xray/features.json +1 -1
  223. package/xray/integrations.json +3 -3
  224. package/dist/integrations/hermes-agent/__pycache__/__init__.cpython-313.pyc +0 -0
  225. package/dist/integrations/hermes-agent/__pycache__/conftest.cpython-313-pytest-9.0.2.pyc +0 -0
  226. package/dist/integrations/hermes-agent/__pycache__/schemas.cpython-313.pyc +0 -0
  227. package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313-pytest-9.0.2.pyc +0 -0
  228. package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313.pyc +0 -0
  229. package/dist/integrations/hermes-agent/__pycache__/tools.cpython-313.pyc +0 -0
  230. package/dist/integrations/hermes-agent/conftest.py +0 -14
  231. package/dist/integrations/hermes-agent/test_plugin.py +0 -1103
  232. package/dist/processors/implementations/refactoring-logging-processor.d.ts +0 -31
  233. package/dist/processors/implementations/refactoring-logging-processor.js +0 -96
  234. package/dist/processors/implementations/session-capture-processor.d.ts +0 -14
  235. package/dist/processors/implementations/session-capture-processor.js +0 -37
  236. package/dist/scripts/activate-kernel-pipeline.d.ts +0 -7
  237. package/dist/scripts/activate-kernel-pipeline.js +0 -101
  238. package/dist/security/index.d.ts +0 -13
  239. package/dist/security/index.js +0 -13
  240. package/dist/security/security-agent-coordinator.d.ts +0 -72
  241. package/dist/security/security-agent-coordinator.js +0 -204
  242. package/dist/security/security-auditor.d.ts +0 -56
  243. package/dist/security/security-auditor.js +0 -584
  244. package/dist/security/security-hardening-system.d.ts +0 -239
  245. package/dist/security/security-hardening-system.js +0 -727
  246. package/dist/security/security-orchestration-layer.d.ts +0 -119
  247. package/dist/security/security-orchestration-layer.js +0 -496
  248. /package/dist/{security → mcps/shared}/prompt-security-validator.d.ts +0 -0
  249. /package/dist/{security → mcps/shared}/prompt-security-validator.js +0 -0
  250. /package/dist/{security → mcps/shared}/security-scanner.d.ts +0 -0
@@ -1,584 +0,0 @@
1
- /**
2
- * Security Audit Tool
3
- *
4
- * Comprehensive security auditing for the framework and its components.
5
- * Identifies vulnerabilities, misconfigurations, and security weaknesses.
6
- *
7
- * @version 1.0.0
8
- * @since 2026-01-07
9
- */
10
- import { readFileSync, readdirSync, statSync } from "fs";
11
- import { join } from "path";
12
- import { frameworkLogger } from "../core/framework-logger.js";
13
- export class SecurityAuditor {
14
- dangerousPatterns = [
15
- // Code injection
16
- {
17
- pattern: /eval\s*\(/g,
18
- severity: "critical",
19
- category: "code-injection",
20
- cwe: "CWE-95",
21
- },
22
- {
23
- pattern: /Function\s*\(/g,
24
- severity: "critical",
25
- category: "code-injection",
26
- cwe: "CWE-95",
27
- },
28
- {
29
- pattern: /new\s+Function\s*\(/g,
30
- severity: "critical",
31
- category: "code-injection",
32
- cwe: "CWE-95",
33
- },
34
- // Command injection
35
- {
36
- pattern: /child_process\.exec\s*\(/g,
37
- severity: "high",
38
- category: "command-injection",
39
- cwe: "CWE-78",
40
- },
41
- {
42
- pattern: /child_process\.spawn\s*\(/g,
43
- severity: "high",
44
- category: "command-injection",
45
- cwe: "CWE-78",
46
- },
47
- {
48
- pattern: /execSync\s*\(/g,
49
- severity: "high",
50
- category: "command-injection",
51
- cwe: "CWE-78",
52
- },
53
- // SQL injection (if applicable)
54
- {
55
- pattern: /SELECT.*\+/g,
56
- severity: "high",
57
- category: "sql-injection",
58
- cwe: "CWE-89",
59
- },
60
- {
61
- pattern: /INSERT.*\+/g,
62
- severity: "high",
63
- category: "sql-injection",
64
- cwe: "CWE-89",
65
- },
66
- // Path traversal
67
- {
68
- pattern: /\.\.[\/\\]/g,
69
- severity: "high",
70
- category: "path-traversal",
71
- cwe: "CWE-22",
72
- },
73
- {
74
- pattern: /path\.join\s*\(\s*\.\./g,
75
- severity: "high",
76
- category: "path-traversal",
77
- cwe: "CWE-22",
78
- },
79
- // Hardcoded secrets
80
- {
81
- pattern: /password\s*[:=]\s*['"][^'"]*['"]/gi,
82
- severity: "high",
83
- category: "hardcoded-secrets",
84
- cwe: "CWE-798",
85
- },
86
- {
87
- pattern: /api[_-]?key\s*[:=]\s*['"][^'"]*['"]/gi,
88
- severity: "high",
89
- category: "hardcoded-secrets",
90
- cwe: "CWE-798",
91
- },
92
- {
93
- pattern: /secret\s*[:=]\s*['"][^'"]*['"]/gi,
94
- severity: "high",
95
- category: "hardcoded-secrets",
96
- cwe: "CWE-798",
97
- },
98
- // Insecure random
99
- {
100
- pattern: /Math\.random\s*\(\)/g,
101
- severity: "medium",
102
- category: "weak-cryptography",
103
- cwe: "CWE-338",
104
- },
105
- // Console logging sensitive data
106
- {
107
- pattern: /console\.log\s*\([^)]*password[^)]*\)/gi,
108
- severity: "medium",
109
- category: "information-disclosure",
110
- cwe: "CWE-532",
111
- },
112
- {
113
- pattern: /console\.log\s*\([^)]*secret[^)]*\)/gi,
114
- severity: "medium",
115
- category: "information-disclosure",
116
- cwe: "CWE-532",
117
- },
118
- // Missing input validation
119
- {
120
- pattern: /req\.body\./g,
121
- severity: "medium",
122
- category: "input-validation",
123
- cwe: "CWE-20",
124
- },
125
- {
126
- pattern: /req\.query\./g,
127
- severity: "medium",
128
- category: "input-validation",
129
- cwe: "CWE-20",
130
- },
131
- // Insecure deserialization
132
- {
133
- pattern: /JSON\.parse\s*\([^)]*req\./g,
134
- severity: "medium",
135
- category: "deserialization",
136
- cwe: "CWE-502",
137
- },
138
- // Race conditions
139
- {
140
- pattern: /setTimeout.*0/g,
141
- severity: "low",
142
- category: "race-conditions",
143
- cwe: "CWE-362",
144
- },
145
- // Information disclosure in errors
146
- {
147
- pattern: /throw\s+new\s+Error\s*\([^)]*stack[^)]*\)/gi,
148
- severity: "low",
149
- category: "information-disclosure",
150
- cwe: "CWE-209",
151
- },
152
- ];
153
- dangerousImports = [
154
- "child_process",
155
- "fs",
156
- "net",
157
- "http",
158
- "https",
159
- "crypto",
160
- "tls",
161
- "cluster",
162
- "worker_threads",
163
- "vm",
164
- ];
165
- /**
166
- * Run comprehensive security audit
167
- */
168
- async auditProject(projectPath = ".") {
169
- const jobId = `security-audit-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
170
- const issues = [];
171
- const files = this.getAllFiles(projectPath);
172
- frameworkLogger.log("security-auditor", "scan-start", "info", {
173
- jobId,
174
- filesCount: files.length,
175
- projectPath,
176
- });
177
- for (const file of files) {
178
- if (this.shouldAuditFile(file)) {
179
- const fileIssues = await this.auditFile(file);
180
- issues.push(...fileIssues);
181
- }
182
- }
183
- // Additional checks
184
- issues.push(...this.auditPackageJson(projectPath));
185
- issues.push(...this.auditConfiguration(projectPath));
186
- issues.push(...this.auditDependencies(projectPath));
187
- const summary = this.generateSummary(issues);
188
- const score = this.calculateSecurityScore(issues, files.length);
189
- return {
190
- totalFiles: files.length,
191
- issues,
192
- summary,
193
- score,
194
- };
195
- }
196
- getAllFiles(dirPath) {
197
- const files = [];
198
- const traverse = (currentPath) => {
199
- const items = readdirSync(currentPath);
200
- for (const item of items) {
201
- const fullPath = join(currentPath, item);
202
- const stat = statSync(fullPath);
203
- if (stat.isDirectory() && !this.shouldSkipDirectory(item)) {
204
- traverse(fullPath);
205
- }
206
- else if (stat.isFile()) {
207
- files.push(fullPath);
208
- }
209
- }
210
- };
211
- traverse(dirPath);
212
- return files;
213
- }
214
- shouldSkipDirectory(dirName) {
215
- const skipDirs = [
216
- "node_modules",
217
- ".git",
218
- "dist",
219
- "build",
220
- ".next",
221
- ".nuxt",
222
- "coverage",
223
- ];
224
- return skipDirs.includes(dirName);
225
- }
226
- shouldAuditFile(filePath) {
227
- const auditExtensions = [".ts", ".tsx", ".js", ".jsx", ".json", ".md"];
228
- const excludePatterns = [/__tests__/, /test\.ts$/, /spec\.ts$/];
229
- // Check if file should be excluded from security audit
230
- if (excludePatterns.some((pattern) => pattern.test(filePath))) {
231
- return false;
232
- }
233
- return auditExtensions.some((ext) => filePath.endsWith(ext));
234
- }
235
- async auditFile(filePath) {
236
- const issues = [];
237
- try {
238
- const content = readFileSync(filePath, "utf-8");
239
- const lines = content.split("\n");
240
- // Pattern-based security checks
241
- for (let i = 0; i < lines.length; i++) {
242
- const line = lines[i];
243
- const lineNumber = i + 1;
244
- for (const { pattern, severity, category, cwe } of this
245
- .dangerousPatterns) {
246
- const matches = line?.match(pattern);
247
- if (matches && line) {
248
- // Skip false positives in security validation and test code
249
- if (this.isFalsePositive(filePath, line, category)) {
250
- continue;
251
- }
252
- issues.push({
253
- severity,
254
- category,
255
- file: filePath,
256
- line: lineNumber,
257
- description: `Potentially dangerous pattern detected: ${pattern}`,
258
- recommendation: this.getRecommendationForCategory(category),
259
- cwe,
260
- });
261
- }
262
- }
263
- }
264
- // Import security checks
265
- if (filePath.endsWith(".ts") || filePath.endsWith(".js")) {
266
- issues.push(...this.auditImports(content, filePath));
267
- }
268
- // File permission checks
269
- issues.push(...this.auditFilePermissions(filePath));
270
- }
271
- catch (error) {
272
- issues.push({
273
- severity: "medium",
274
- category: "file-access",
275
- file: filePath,
276
- description: `Failed to audit file: ${error}`,
277
- recommendation: "Ensure file is readable and not corrupted",
278
- });
279
- }
280
- return issues;
281
- }
282
- isFalsePositive(filePath, line, category) {
283
- if (!line)
284
- return false;
285
- const safeLine = line;
286
- // Security validation code that legitimately uses dangerous patterns for detection
287
- if (filePath.includes("security-auditor.ts") &&
288
- category === "code-injection") {
289
- return true;
290
- }
291
- // Test code that uses eval in string literals for testing purposes
292
- if (filePath.includes("__tests__") &&
293
- category === "code-injection" &&
294
- safeLine.includes("eval(")) {
295
- return (safeLine.includes("'eval('") ||
296
- safeLine.includes('"eval(') ||
297
- safeLine.includes("`eval("));
298
- }
299
- // Security validation modules that check for dangerous patterns
300
- if (filePath.includes("codex-parser.ts") && category === "code-injection") {
301
- return (safeLine.includes("content.includes('eval(')") ||
302
- safeLine.includes("content.includes('Function(')"));
303
- }
304
- return false;
305
- }
306
- auditImports(content, filePath) {
307
- const issues = [];
308
- for (const dangerousImport of this.dangerousImports) {
309
- const importPatterns = [
310
- new RegExp(`import.*from.*['"]${dangerousImport}['"]`, "g"),
311
- new RegExp(`require\\s*\\(\\s*['"]${dangerousImport}['"]\\s*\\)`, "g"),
312
- new RegExp(`import.*${dangerousImport}`, "g"),
313
- ];
314
- for (const pattern of importPatterns) {
315
- if (pattern.test(content)) {
316
- issues.push({
317
- severity: "medium",
318
- category: "dangerous-imports",
319
- file: filePath,
320
- description: `Potentially dangerous import detected: ${dangerousImport}`,
321
- recommendation: "Review usage and ensure proper sandboxing/validation",
322
- cwe: "CWE-350",
323
- });
324
- break; // Only report once per import per file
325
- }
326
- }
327
- }
328
- return issues;
329
- }
330
- auditFilePermissions(filePath) {
331
- const issues = [];
332
- try {
333
- const stat = statSync(filePath);
334
- const mode = stat.mode;
335
- // Check for world-writable files
336
- if (mode & parseInt("2", 8)) {
337
- issues.push({
338
- severity: "high",
339
- category: "file-permissions",
340
- file: filePath,
341
- description: "File is world-writable",
342
- recommendation: "Restrict file permissions to prevent unauthorized modification",
343
- cwe: "CWE-732",
344
- });
345
- }
346
- // Check for executable scripts in sensitive directories
347
- if (mode & parseInt("111", 8) && filePath.includes("config")) {
348
- issues.push({
349
- severity: "medium",
350
- category: "file-permissions",
351
- file: filePath,
352
- description: "Executable file in configuration directory",
353
- recommendation: "Review if this file needs execute permissions",
354
- cwe: "CWE-732",
355
- });
356
- }
357
- }
358
- catch (error) {
359
- // File permission check failed
360
- }
361
- return issues;
362
- }
363
- auditPackageJson(projectPath) {
364
- const issues = [];
365
- try {
366
- const packagePath = join(projectPath, "package.json");
367
- const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
368
- // Check for vulnerable dependencies
369
- const allDeps = {
370
- ...packageJson.dependencies,
371
- ...packageJson.devDependencies,
372
- };
373
- for (const [dep, version] of Object.entries(allDeps)) {
374
- if (typeof version === "string" &&
375
- (version.includes("*") || version.includes("latest"))) {
376
- issues.push({
377
- severity: "medium",
378
- category: "dependency-management",
379
- file: packagePath,
380
- description: `Insecure version constraint for ${dep}: ${version}`,
381
- recommendation: "Use specific version ranges to avoid vulnerable versions",
382
- cwe: "CWE-1104",
383
- });
384
- }
385
- }
386
- // Check for missing security scripts
387
- const scripts = packageJson.scripts || {};
388
- if (!scripts["audit"] || !scripts["security-audit"]) {
389
- issues.push({
390
- severity: "low",
391
- category: "security-practices",
392
- file: packagePath,
393
- description: "Missing security audit scripts",
394
- recommendation: "Add npm audit and security audit scripts to package.json",
395
- });
396
- }
397
- }
398
- catch (error) {
399
- issues.push({
400
- severity: "medium",
401
- category: "configuration",
402
- file: join(projectPath, "package.json"),
403
- description: "Failed to audit package.json",
404
- recommendation: "Ensure package.json is valid and accessible",
405
- });
406
- }
407
- return issues;
408
- }
409
- auditConfiguration(projectPath) {
410
- const issues = [];
411
- const configFiles = ["opencode.json", "config.json", ".env"];
412
- for (const configFile of configFiles) {
413
- const configPath = join(projectPath, configFile);
414
- try {
415
- const content = readFileSync(configPath, "utf-8");
416
- // Check for hardcoded secrets
417
- const secretPatterns = [
418
- /password\s*[:=]\s*['"][^'"]*['"]/gi,
419
- /api[_-]?key\s*[:=]\s*['"][^'"]*['"]/gi,
420
- /secret\s*[:=]\s*['"][^'"]*['"]/gi,
421
- /token\s*[:=]\s*['"][^'"]*['"]/gi,
422
- ];
423
- for (const pattern of secretPatterns) {
424
- if (pattern.test(content)) {
425
- issues.push({
426
- severity: "high",
427
- category: "hardcoded-secrets",
428
- file: configPath,
429
- description: "Potential hardcoded secrets detected in configuration",
430
- recommendation: "Move secrets to environment variables or secure vault",
431
- cwe: "CWE-798",
432
- });
433
- break;
434
- }
435
- }
436
- }
437
- catch (error) {
438
- // Config file doesn't exist or can't be read
439
- }
440
- }
441
- return issues;
442
- }
443
- auditDependencies(projectPath) {
444
- const issues = [];
445
- try {
446
- const packageLockPath = join(projectPath, "package-lock.json");
447
- const yarnLockPath = join(projectPath, "yarn.lock");
448
- if (!statSync(packageLockPath).isFile() &&
449
- !statSync(yarnLockPath).isFile()) {
450
- issues.push({
451
- severity: "medium",
452
- category: "dependency-management",
453
- file: join(projectPath, "package.json"),
454
- description: "Missing lockfile (package-lock.json or yarn.lock)",
455
- recommendation: "Use lockfiles to ensure reproducible and secure dependency versions",
456
- cwe: "CWE-1104",
457
- });
458
- }
459
- }
460
- catch (error) {
461
- // Lockfile check failed
462
- }
463
- return issues;
464
- }
465
- getRecommendationForCategory(category) {
466
- const recommendations = {
467
- "code-injection": "Use static code analysis and avoid dynamic code execution",
468
- "command-injection": "Validate and sanitize all user inputs, use parameterized commands",
469
- "sql-injection": "Use parameterized queries or ORM with built-in protection",
470
- "path-traversal": "Validate paths, use allowlists, resolve to absolute paths",
471
- "hardcoded-secrets": "Use environment variables or secure credential management",
472
- "weak-cryptography": "Use cryptographically secure random number generators",
473
- "information-disclosure": "Avoid logging sensitive information, use proper log levels",
474
- "input-validation": "Implement comprehensive input validation and sanitization",
475
- deserialization: "Validate serialized data, use safe deserialization libraries",
476
- "race-conditions": "Use proper synchronization primitives",
477
- "dangerous-imports": "Review usage and implement proper access controls",
478
- "file-permissions": "Restrict file permissions to minimum required access",
479
- };
480
- return (recommendations[category] ||
481
- "Review and implement appropriate security measures");
482
- }
483
- generateSummary(issues) {
484
- const summary = {
485
- critical: 0,
486
- high: 0,
487
- medium: 0,
488
- low: 0,
489
- info: 0,
490
- };
491
- for (const issue of issues) {
492
- summary[issue.severity]++;
493
- }
494
- return summary;
495
- }
496
- calculateSecurityScore(issues, totalFiles) {
497
- let score = 100;
498
- // Weight issues by severity
499
- const weights = {
500
- critical: 20,
501
- high: 10,
502
- medium: 5,
503
- low: 2,
504
- info: 1,
505
- };
506
- for (const issue of issues) {
507
- score -= weights[issue.severity];
508
- }
509
- // Bonus for having many files (indicates thorough codebase)
510
- if (totalFiles > 50) {
511
- score += 5;
512
- }
513
- return Math.max(0, Math.min(100, score));
514
- }
515
- /**
516
- * Generate security audit report
517
- */
518
- generateReport(result) {
519
- let report = `# 🔒 0xRay Framework Security Audit Report
520
-
521
- **Audit Date:** ${new Date().toISOString()}
522
- **Framework Version:** v1.3.4
523
- **Files Scanned:** ${result.totalFiles}
524
- **Security Score:** ${result.score}/100
525
-
526
- ## 📊 Summary
527
-
528
- - **Critical Issues:** ${result.summary.critical}
529
- - **High Severity:** ${result.summary.high}
530
- - **Medium Severity:** ${result.summary.medium}
531
- - **Low Severity:** ${result.summary.low}
532
- - **Informational:** ${result.summary.info}
533
-
534
- ## 🚨 Issues Found
535
-
536
- `;
537
- if (result.issues.length === 0) {
538
- report += "✅ No security issues found!\n\n";
539
- }
540
- else {
541
- // Group issues by severity
542
- const groupedIssues = result.issues.reduce((groups, issue) => {
543
- if (!groups[issue.severity])
544
- groups[issue.severity] = [];
545
- groups[issue.severity].push(issue);
546
- return groups;
547
- }, {});
548
- for (const [severity, issues] of Object.entries(groupedIssues)) {
549
- report += `### ${severity.toUpperCase()} SEVERITY (${issues.length})\n\n`;
550
- for (const issue of issues) {
551
- report += `**${issue.category.toUpperCase()}** in \`${issue.file}\`${issue.line ? `:${issue.line}` : ""}\n`;
552
- report += `${issue.description}\n`;
553
- report += `💡 ${issue.recommendation}\n`;
554
- if (issue.cwe) {
555
- report += `🔗 CWE: ${issue.cwe}\n`;
556
- }
557
- report += "\n";
558
- }
559
- }
560
- }
561
- report += `## 🛡️ Security Recommendations
562
-
563
- 1. **Address all Critical and High severity issues immediately**
564
- 2. **Implement automated security scanning in CI/CD pipeline**
565
- 3. **Regular security audits and dependency updates**
566
- 4. **Use security headers and secure coding practices**
567
- 5. **Monitor for new vulnerabilities in dependencies**
568
-
569
- ## 📈 Score Interpretation
570
-
571
- - **90-100:** Excellent security posture
572
- - **80-89:** Good security with minor issues
573
- - **70-79:** Adequate security, address high-priority issues
574
- - **60-69:** Security concerns present, immediate action required
575
- - **<60:** Critical security issues, immediate remediation needed
576
-
577
- ---
578
- *Generated by 0xRay v1.2.0*
579
- `;
580
- return report;
581
- }
582
- }
583
- // Export singleton instance
584
- export const securityAuditor = new SecurityAuditor();