0xray 2.1.1 ā 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.
- package/.opencode/codex.codex +1 -1
- package/.opencode/commands/dependency-audit.md +3 -3
- package/.opencode/enforcer-config.json +2 -2
- package/AGENTS.md +3 -2
- package/README.md +12 -11
- package/dist/AGENTS.md +3 -2
- package/dist/CHANGELOG.md +26 -0
- package/dist/README.md +12 -11
- package/dist/agents/code-reviewer.js +1 -1
- package/dist/analytics/routing-refiner.js +1 -1
- package/dist/cli/index.js +11 -1
- package/dist/cli/server.js +3 -3
- package/dist/core/activity-logger.d.ts +2 -2
- package/dist/core/activity-logger.js +4 -4
- package/dist/core/boot-orchestrator.d.ts +1 -1
- package/dist/core/boot-orchestrator.js +13 -28
- package/dist/core/bridge.mjs +3 -3
- package/dist/core/codex-formatter.js +2 -2
- package/dist/core/codex-injector.d.ts +0 -1
- package/dist/core/codex-injector.js +2 -3
- package/dist/core/config-loader.d.ts +1 -1
- package/dist/core/config-loader.js +1 -1
- package/dist/core/config-paths.d.ts +0 -2
- package/dist/core/config-paths.js +7 -8
- package/dist/core/context-loader.d.ts +1 -1
- package/dist/core/context-loader.js +1 -1
- package/dist/core/errors.d.ts +3 -0
- package/dist/core/errors.js +10 -0
- package/dist/core/features-config.js +1 -1
- package/dist/core/framework-logger.d.ts +3 -3
- package/dist/core/framework-logger.js +17 -9
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +4 -2
- package/dist/core/logging-config.d.ts +2 -1
- package/dist/core/logging-config.js +7 -7
- package/dist/enforcement/loaders/codex-loader.js +1 -1
- package/dist/execution/opencode-cli-invoker.js +5 -5
- package/dist/governance/governance-service.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/inference/inference-cycle.d.ts +1 -1
- package/dist/inference/inference-cycle.js +10 -10
- package/dist/integrations/base/Integration.js +1 -1
- package/dist/integrations/base/registry.js +19 -19
- package/dist/integrations/grok/grok-cli.js +17 -17
- package/dist/integrations/grok/hooks/pre-tool-use.js +1 -1
- package/dist/integrations/hermes-agent/bridge.mjs +1 -1
- package/dist/integrations/openclaw/api-server.d.ts +0 -1
- package/dist/integrations/openclaw/api-server.js +7 -10
- package/dist/integrations/openclaw/client.d.ts +0 -1
- package/dist/integrations/openclaw/client.js +22 -24
- package/dist/integrations/openclaw/hooks/xray-hooks.d.ts +0 -1
- package/dist/integrations/openclaw/hooks/xray-hooks.js +17 -18
- package/dist/integrations/plugins/plugin-registry.js +5 -5
- package/dist/mcps/architect-tools.server.d.ts +2 -4
- package/dist/mcps/architect-tools.server.js +112 -195
- package/dist/mcps/auto-format.server.d.ts +2 -4
- package/dist/mcps/auto-format.server.js +49 -95
- package/dist/mcps/boot-orchestrator.server.d.ts +2 -4
- package/dist/mcps/boot-orchestrator.server.js +73 -105
- package/dist/mcps/config/server-config-registry.js +3 -3
- package/dist/mcps/enforcer-tools.server.d.ts +2 -4
- package/dist/mcps/enforcer-tools.server.js +202 -285
- package/dist/mcps/estimation.server.d.ts +2 -4
- package/dist/mcps/estimation.server.js +63 -107
- package/dist/mcps/framework-compliance-audit.server.d.ts +2 -4
- package/dist/mcps/framework-compliance-audit.server.js +53 -82
- package/dist/mcps/framework-help.server.d.ts +2 -4
- package/dist/mcps/framework-help.server.js +63 -101
- package/dist/mcps/governance.server.js +2 -2
- package/dist/mcps/knowledge-skills/api-design.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/api-design.server.js +35 -67
- package/dist/mcps/knowledge-skills/architecture-patterns.server.d.ts +2 -10
- package/dist/mcps/knowledge-skills/architecture-patterns.server.js +35 -74
- package/dist/mcps/knowledge-skills/bug-triage-specialist.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/bug-triage-specialist.server.js +143 -162
- package/dist/mcps/knowledge-skills/code-analyzer.server.d.ts +3 -4
- package/dist/mcps/knowledge-skills/code-analyzer.server.js +20 -45
- package/dist/mcps/knowledge-skills/code-review.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/code-review.server.js +109 -143
- package/dist/mcps/knowledge-skills/content-creator.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/content-creator.server.js +205 -226
- package/dist/mcps/knowledge-skills/database-design.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/database-design.server.js +117 -151
- package/dist/mcps/knowledge-skills/devops-deployment.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/devops-deployment.server.js +71 -160
- package/dist/mcps/knowledge-skills/git-workflow.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/git-workflow.server.js +36 -68
- package/dist/mcps/knowledge-skills/growth-strategist.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/growth-strategist.server.js +303 -324
- package/dist/mcps/knowledge-skills/log-monitor.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/log-monitor.server.js +141 -160
- package/dist/mcps/knowledge-skills/mobile-development.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/mobile-development.server.js +92 -209
- package/dist/mcps/knowledge-skills/multimodal-looker.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/multimodal-looker.server.js +123 -159
- package/dist/mcps/knowledge-skills/performance-optimization.server.d.ts +2 -5
- package/dist/mcps/knowledge-skills/performance-optimization.server.js +155 -296
- package/dist/mcps/knowledge-skills/project-analysis.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/project-analysis.server.js +75 -226
- package/dist/mcps/knowledge-skills/refactoring-strategies.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/refactoring-strategies.server.js +63 -156
- package/dist/mcps/knowledge-skills/security-audit.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/security-audit.server.js +102 -136
- package/dist/mcps/knowledge-skills/seo-consultant.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/seo-consultant.server.js +80 -203
- package/dist/mcps/knowledge-skills/session-management.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/session-management.server.js +50 -203
- package/dist/mcps/knowledge-skills/skill-invocation.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/skill-invocation.server.js +168 -347
- package/dist/mcps/knowledge-skills/strategist.server.d.ts +2 -11
- package/dist/mcps/knowledge-skills/strategist.server.js +72 -122
- package/dist/mcps/knowledge-skills/tech-writer.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/tech-writer.server.js +87 -300
- package/dist/mcps/knowledge-skills/testing-best-practices.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/testing-best-practices.server.js +147 -182
- package/dist/mcps/knowledge-skills/testing-strategy.server.d.ts +2 -4
- package/dist/mcps/knowledge-skills/testing-strategy.server.js +78 -153
- package/dist/mcps/knowledge-skills/ui-ux-design.server.d.ts +2 -5
- package/dist/mcps/knowledge-skills/ui-ux-design.server.js +90 -399
- package/dist/mcps/lint.server.d.ts +2 -4
- package/dist/mcps/lint.server.js +51 -92
- package/dist/mcps/mcp-client.js +2 -2
- package/dist/mcps/model-health-check.server.d.ts +2 -4
- package/dist/mcps/model-health-check.server.js +32 -60
- package/dist/mcps/performance-analysis.server.d.ts +2 -4
- package/dist/mcps/performance-analysis.server.js +57 -88
- package/dist/mcps/processor-pipeline.server.d.ts +2 -4
- package/dist/mcps/processor-pipeline.server.js +69 -100
- package/dist/mcps/registry.json +1 -1
- package/dist/mcps/researcher.server.d.ts +3 -5
- package/dist/mcps/researcher.server.js +81 -154
- package/dist/mcps/security-scan.server.d.ts +2 -4
- package/dist/mcps/security-scan.server.js +54 -96
- package/dist/mcps/shared/knowledge-skill-base.d.ts +14 -0
- package/dist/mcps/shared/knowledge-skill-base.js +45 -0
- package/dist/{security ā mcps/shared}/security-scanner.js +1 -1
- package/dist/mcps/state-manager.server.d.ts +2 -4
- package/dist/mcps/state-manager.server.js +115 -160
- package/dist/orchestrator/orchestrator.d.ts +1 -1
- package/dist/orchestrator/orchestrator.js +1 -1
- package/dist/orchestrator/universal-registry-bridge.js +1 -1
- package/dist/plugin/xray-codex-injection.d.ts +1 -1
- package/dist/plugin/xray-codex-injection.js +1 -1
- package/dist/postprocessor/PostProcessor.d.ts +4 -44
- package/dist/postprocessor/PostProcessor.js +39 -553
- package/dist/postprocessor/analysis/CodeChangeAnalyzer.d.ts +11 -0
- package/dist/postprocessor/analysis/CodeChangeAnalyzer.js +50 -0
- package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.d.ts +11 -0
- package/dist/postprocessor/compliance/ArchitecturalComplianceChecker.js +356 -0
- package/dist/postprocessor/config/ProcessorConfigLoader.d.ts +44 -0
- package/dist/postprocessor/config/ProcessorConfigLoader.js +21 -0
- package/dist/postprocessor/reporting/PostProcessorReporter.d.ts +19 -0
- package/dist/postprocessor/reporting/PostProcessorReporter.js +96 -0
- package/dist/postprocessor/triggers/GitHookTrigger.js +11 -11
- package/dist/processors/implementations/refactoring-logging-processor-wrapper.d.ts +32 -0
- package/dist/processors/implementations/refactoring-logging-processor-wrapper.js +95 -1
- package/dist/processors/processor-manager.js +346 -314
- package/dist/reporting/report-formatter.js +1 -1
- package/dist/security/security-hardener.d.ts +69 -2
- package/dist/security/security-hardener.js +129 -1
- package/dist/skills/registry.json +1 -1
- package/dist/state/index.d.ts +3 -5
- package/dist/state/index.js +1 -7
- package/dist/state/state-manager.d.ts +1 -1
- package/dist/state/state-manager.js +2 -3
- package/package.json +14 -10
- package/scripts/node/setup.cjs +32 -0
- package/scripts/node/universal-version-manager.js +11 -11
- package/src/mcps/architect-tools.server.ts +112 -215
- package/src/mcps/auto-format.server.ts +50 -110
- package/src/mcps/boot-orchestrator.server.ts +75 -121
- package/src/mcps/config/__tests__/server-config-registry.test.ts +21 -12
- package/src/mcps/config/server-config-registry.ts +3 -3
- package/src/mcps/enforcer-tools.server.ts +212 -310
- package/src/mcps/estimation.server.ts +62 -122
- package/src/mcps/framework-compliance-audit.server.ts +52 -97
- package/src/mcps/framework-help.server.ts +64 -114
- package/src/mcps/governance.server.ts +2 -2
- package/src/mcps/knowledge-skills/api-design.server.ts +32 -77
- package/src/mcps/knowledge-skills/architecture-patterns.server.ts +31 -87
- package/src/mcps/knowledge-skills/bug-triage-specialist.server.ts +165 -193
- package/src/mcps/knowledge-skills/code-analyzer.server.ts +20 -55
- package/src/mcps/knowledge-skills/code-review.server.ts +114 -161
- package/src/mcps/knowledge-skills/content-creator.server.ts +218 -255
- package/src/mcps/knowledge-skills/database-design.server.ts +118 -165
- package/src/mcps/knowledge-skills/devops-deployment.server.ts +67 -172
- package/src/mcps/knowledge-skills/git-workflow.server.ts +32 -77
- package/src/mcps/knowledge-skills/growth-strategist.server.ts +324 -361
- package/src/mcps/knowledge-skills/log-monitor.server.ts +160 -187
- package/src/mcps/knowledge-skills/mobile-development.server.ts +89 -223
- package/src/mcps/knowledge-skills/multimodal-looker.server.ts +128 -175
- package/src/mcps/knowledge-skills/performance-optimization.server.ts +156 -329
- package/src/mcps/knowledge-skills/project-analysis.server.ts +72 -248
- package/src/mcps/knowledge-skills/refactoring-strategies.server.ts +59 -171
- package/src/mcps/knowledge-skills/security-audit.server.ts +104 -151
- package/src/mcps/knowledge-skills/seo-consultant.server.ts +80 -220
- package/src/mcps/knowledge-skills/session-management.server.ts +51 -232
- package/src/mcps/knowledge-skills/skill-invocation.server.ts +165 -372
- package/src/mcps/knowledge-skills/strategist.server.ts +72 -143
- package/src/mcps/knowledge-skills/tech-writer.server.ts +85 -350
- package/src/mcps/knowledge-skills/testing-best-practices.server.ts +146 -195
- package/src/mcps/knowledge-skills/testing-strategy.server.ts +75 -161
- package/src/mcps/knowledge-skills/ui-ux-design.server.ts +93 -487
- package/src/mcps/lint.server.ts +53 -107
- package/src/mcps/mcp-client.ts +2 -2
- package/src/mcps/model-health-check.server.ts +34 -71
- package/src/mcps/performance-analysis.server.ts +60 -104
- package/src/mcps/processor-pipeline.server.ts +72 -110
- package/src/mcps/registry.json +1 -1
- package/src/mcps/researcher.server.ts +88 -177
- package/src/mcps/security-scan.server.ts +55 -104
- package/src/mcps/shared/knowledge-skill-base.ts +62 -0
- package/src/mcps/shared/prompt-security-validator.ts +199 -0
- package/src/mcps/shared/security-scanner.ts +599 -0
- package/src/mcps/state-manager.server.ts +117 -175
- package/src/opencode/codex.codex +1 -1
- package/src/opencode/commands/dependency-audit.md +3 -3
- package/src/opencode/enforcer-config.json +2 -2
- package/src/skills/registry.json +1 -1
- package/xray/agents_template.md +109 -0
- package/xray/codex.json +598 -0
- package/xray/config.json +26 -0
- package/xray/features.json +132 -0
- package/xray/integrations.json +23 -0
- package/xray/routing-mappings.json +752 -0
- package/xray/workflow_state.json +28 -0
- package/dist/integrations/hermes-agent/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/conftest.cpython-313-pytest-9.0.2.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/schemas.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313-pytest-9.0.2.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/test_plugin.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/__pycache__/tools.cpython-313.pyc +0 -0
- package/dist/integrations/hermes-agent/conftest.py +0 -14
- package/dist/integrations/hermes-agent/test_plugin.py +0 -1103
- package/dist/processors/implementations/refactoring-logging-processor.d.ts +0 -31
- package/dist/processors/implementations/refactoring-logging-processor.js +0 -96
- package/dist/processors/implementations/session-capture-processor.d.ts +0 -14
- package/dist/processors/implementations/session-capture-processor.js +0 -37
- package/dist/scripts/activate-kernel-pipeline.d.ts +0 -7
- package/dist/scripts/activate-kernel-pipeline.js +0 -101
- package/dist/security/index.d.ts +0 -13
- package/dist/security/index.js +0 -13
- package/dist/security/security-agent-coordinator.d.ts +0 -72
- package/dist/security/security-agent-coordinator.js +0 -204
- package/dist/security/security-auditor.d.ts +0 -56
- package/dist/security/security-auditor.js +0 -584
- package/dist/security/security-hardening-system.d.ts +0 -239
- package/dist/security/security-hardening-system.js +0 -727
- package/dist/security/security-orchestration-layer.d.ts +0 -119
- package/dist/security/security-orchestration-layer.js +0 -496
- /package/dist/{security ā mcps/shared}/prompt-security-validator.d.ts +0 -0
- /package/dist/{security ā mcps/shared}/prompt-security-validator.js +0 -0
- /package/dist/{security ā mcps/shared}/security-scanner.d.ts +0 -0
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0xRay Framework - Security Scanner
|
|
3
|
+
*
|
|
4
|
+
* Automated security vulnerability scanning and compliance validation
|
|
5
|
+
* Integrates with security tools and provides comprehensive security reports
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { exec } from "child_process";
|
|
9
|
+
import { promises as fs } from "fs";
|
|
10
|
+
import { frameworkLogger } from "../../core/framework-logger.js";
|
|
11
|
+
import { promisify } from "util";
|
|
12
|
+
import {
|
|
13
|
+
promptSecurityValidator,
|
|
14
|
+
PromptSecurityValidator,
|
|
15
|
+
} from "./prompt-security-validator.js";
|
|
16
|
+
|
|
17
|
+
const execAsync = promisify(exec);
|
|
18
|
+
|
|
19
|
+
export interface SecurityScanConfig {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
tools: {
|
|
22
|
+
npmAudit: boolean;
|
|
23
|
+
trivy: boolean;
|
|
24
|
+
eslintSecurity: boolean;
|
|
25
|
+
dependencyCheck: boolean;
|
|
26
|
+
};
|
|
27
|
+
severityThreshold: "low" | "moderate" | "high" | "critical";
|
|
28
|
+
reportPath: string;
|
|
29
|
+
failOnVulnerabilities: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SecurityVulnerability {
|
|
33
|
+
id: string;
|
|
34
|
+
title: string;
|
|
35
|
+
description: string;
|
|
36
|
+
severity: "low" | "moderate" | "high" | "critical";
|
|
37
|
+
package?: string;
|
|
38
|
+
version?: string;
|
|
39
|
+
cve?: string;
|
|
40
|
+
url?: string;
|
|
41
|
+
recommendation: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SecurityReport {
|
|
45
|
+
timestamp: string;
|
|
46
|
+
duration: number;
|
|
47
|
+
tools: {
|
|
48
|
+
npmAudit: SecurityVulnerability[];
|
|
49
|
+
trivy: SecurityVulnerability[];
|
|
50
|
+
eslintSecurity: SecurityVulnerability[];
|
|
51
|
+
dependencyCheck: SecurityVulnerability[];
|
|
52
|
+
};
|
|
53
|
+
summary: {
|
|
54
|
+
totalVulnerabilities: number;
|
|
55
|
+
bySeverity: Record<string, number>;
|
|
56
|
+
byTool: Record<string, number>;
|
|
57
|
+
};
|
|
58
|
+
recommendations: string[];
|
|
59
|
+
compliant: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class SecurityScanner {
|
|
63
|
+
private config: SecurityScanConfig;
|
|
64
|
+
|
|
65
|
+
constructor(config: Partial<SecurityScanConfig> = {}) {
|
|
66
|
+
this.config = {
|
|
67
|
+
enabled: true,
|
|
68
|
+
tools: {
|
|
69
|
+
npmAudit: true,
|
|
70
|
+
trivy: false, // Requires separate installation
|
|
71
|
+
eslintSecurity: true,
|
|
72
|
+
dependencyCheck: false, // Requires separate installation
|
|
73
|
+
...config.tools,
|
|
74
|
+
},
|
|
75
|
+
severityThreshold: "moderate",
|
|
76
|
+
reportPath: "./security-report.json",
|
|
77
|
+
failOnVulnerabilities: true,
|
|
78
|
+
...config,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Run comprehensive security scan
|
|
84
|
+
*/
|
|
85
|
+
async runSecurityScan(): Promise<SecurityReport> {
|
|
86
|
+
const jobId = `security-scan-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
87
|
+
const startTime = Date.now();
|
|
88
|
+
|
|
89
|
+
if (!this.config.enabled) {
|
|
90
|
+
return this.createEmptyReport();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
frameworkLogger.log("security-scanner", "scan-start", "info", {
|
|
94
|
+
jobId,
|
|
95
|
+
tools: this.config.tools,
|
|
96
|
+
severityThreshold: this.config.severityThreshold,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const results = await Promise.allSettled([
|
|
100
|
+
this.config.tools.npmAudit ? this.runNpmAudit() : Promise.resolve([]),
|
|
101
|
+
this.config.tools.trivy ? this.runTrivyScan() : Promise.resolve([]),
|
|
102
|
+
this.config.tools.eslintSecurity
|
|
103
|
+
? this.runEslintSecurity()
|
|
104
|
+
: Promise.resolve([]),
|
|
105
|
+
this.config.tools.dependencyCheck
|
|
106
|
+
? this.runDependencyCheck()
|
|
107
|
+
: Promise.resolve([]),
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
const tools = {
|
|
111
|
+
npmAudit: results[0].status === "fulfilled" ? results[0].value : [],
|
|
112
|
+
trivy: results[1].status === "fulfilled" ? results[1].value : [],
|
|
113
|
+
eslintSecurity: results[2].status === "fulfilled" ? results[2].value : [],
|
|
114
|
+
dependencyCheck:
|
|
115
|
+
results[3].status === "fulfilled" ? results[3].value : [],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const duration = Date.now() - startTime;
|
|
119
|
+
const report = this.generateReport(tools, duration);
|
|
120
|
+
|
|
121
|
+
// Save report
|
|
122
|
+
await this.saveReport(report, jobId);
|
|
123
|
+
|
|
124
|
+
// Log results
|
|
125
|
+
await this.logResults(report);
|
|
126
|
+
|
|
127
|
+
return report;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Run npm audit
|
|
132
|
+
*/
|
|
133
|
+
private async runNpmAudit(): Promise<SecurityVulnerability[]> {
|
|
134
|
+
try {
|
|
135
|
+
const { stdout } = await execAsync("npm audit --json");
|
|
136
|
+
const auditResult = JSON.parse(stdout);
|
|
137
|
+
|
|
138
|
+
const vulnerabilities: SecurityVulnerability[] = [];
|
|
139
|
+
|
|
140
|
+
if (auditResult.vulnerabilities) {
|
|
141
|
+
for (const [packageName, vuln] of Object.entries(
|
|
142
|
+
auditResult.vulnerabilities,
|
|
143
|
+
) as any) {
|
|
144
|
+
vulnerabilities.push({
|
|
145
|
+
id: vuln.name || packageName,
|
|
146
|
+
title: vuln.title || "Security vulnerability",
|
|
147
|
+
description: vuln.overview || "No description available",
|
|
148
|
+
severity: this.mapNpmSeverity(vuln.severity),
|
|
149
|
+
package: packageName,
|
|
150
|
+
version: vuln.version,
|
|
151
|
+
cve: vuln.cwe,
|
|
152
|
+
url: vuln.url,
|
|
153
|
+
recommendation: vuln.recommendation || "Update to a secure version",
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return vulnerabilities;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
const errorMessage =
|
|
161
|
+
error instanceof Error ? error.message : String(error);
|
|
162
|
+
frameworkLogger.log("security-scanner", "npm-audit-failed", "warning", { message: "ā ļø npm audit failed", error: errorMessage });
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Run Trivy security scan
|
|
169
|
+
*/
|
|
170
|
+
private async runTrivyScan(): Promise<SecurityVulnerability[]> {
|
|
171
|
+
try {
|
|
172
|
+
const { stdout } = await execAsync("trivy fs --format json .");
|
|
173
|
+
const trivyResult = JSON.parse(stdout);
|
|
174
|
+
|
|
175
|
+
const vulnerabilities: SecurityVulnerability[] = [];
|
|
176
|
+
|
|
177
|
+
if (trivyResult.Results) {
|
|
178
|
+
for (const result of trivyResult.Results) {
|
|
179
|
+
if (result.Vulnerabilities) {
|
|
180
|
+
for (const vuln of result.Vulnerabilities) {
|
|
181
|
+
vulnerabilities.push({
|
|
182
|
+
id: vuln.VulnerabilityID,
|
|
183
|
+
title: vuln.Title,
|
|
184
|
+
description: vuln.Description,
|
|
185
|
+
severity: this.mapTrivySeverity(vuln.Severity),
|
|
186
|
+
package: vuln.PkgName,
|
|
187
|
+
version: vuln.InstalledVersion,
|
|
188
|
+
cve: vuln.VulnerabilityID,
|
|
189
|
+
url: vuln.PrimaryURL,
|
|
190
|
+
recommendation: vuln.FixedVersion
|
|
191
|
+
? `Update to ${vuln.FixedVersion}`
|
|
192
|
+
: "Review and mitigate",
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return vulnerabilities;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
const errorMessage =
|
|
202
|
+
error instanceof Error ? error.message : String(error);
|
|
203
|
+
frameworkLogger.log("security-scanner", "trivy-scan-failed", "warning", { message: "ā ļø Trivy scan failed", error: errorMessage });
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Run ESLint security rules
|
|
210
|
+
*/
|
|
211
|
+
private async runEslintSecurity(): Promise<SecurityVulnerability[]> {
|
|
212
|
+
try {
|
|
213
|
+
const { stdout } = await execAsync("npx eslint --format json src/");
|
|
214
|
+
const eslintResults = JSON.parse(stdout);
|
|
215
|
+
|
|
216
|
+
const vulnerabilities: SecurityVulnerability[] = [];
|
|
217
|
+
|
|
218
|
+
for (const result of eslintResults) {
|
|
219
|
+
for (const message of result.messages) {
|
|
220
|
+
if (
|
|
221
|
+
message.ruleId &&
|
|
222
|
+
(message.ruleId.includes("security") ||
|
|
223
|
+
message.ruleId.includes("xss") ||
|
|
224
|
+
message.ruleId.includes("injection"))
|
|
225
|
+
) {
|
|
226
|
+
vulnerabilities.push({
|
|
227
|
+
id: message.ruleId,
|
|
228
|
+
title: message.message,
|
|
229
|
+
description: `Security issue in ${result.filePath}:${message.line}:${message.column}`,
|
|
230
|
+
severity: "moderate",
|
|
231
|
+
recommendation:
|
|
232
|
+
"Fix the security vulnerability according to ESLint recommendations",
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return vulnerabilities;
|
|
239
|
+
} catch (error) {
|
|
240
|
+
const errorMessage =
|
|
241
|
+
error instanceof Error ? error.message : String(error);
|
|
242
|
+
frameworkLogger.log("security-scanner", "eslint-scan-failed", "warning", { message: "ā ļø ESLint security scan failed", error: errorMessage });
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Run OWASP Dependency Check
|
|
249
|
+
*/
|
|
250
|
+
private async runDependencyCheck(): Promise<SecurityVulnerability[]> {
|
|
251
|
+
try {
|
|
252
|
+
const { stdout } = await execAsync(
|
|
253
|
+
"dependency-check --format JSON --out . --scan .",
|
|
254
|
+
);
|
|
255
|
+
const dcResult = JSON.parse(stdout);
|
|
256
|
+
|
|
257
|
+
const vulnerabilities: SecurityVulnerability[] = [];
|
|
258
|
+
|
|
259
|
+
if (dcResult.dependencies) {
|
|
260
|
+
for (const dep of dcResult.dependencies) {
|
|
261
|
+
if (dep.vulnerabilities) {
|
|
262
|
+
for (const vuln of dep.vulnerabilities) {
|
|
263
|
+
vulnerabilities.push({
|
|
264
|
+
id: vuln.name,
|
|
265
|
+
title: vuln.description,
|
|
266
|
+
description: vuln.description,
|
|
267
|
+
severity: this.mapDependencyCheckSeverity(vuln.severity),
|
|
268
|
+
package: dep.fileName,
|
|
269
|
+
cve: vuln.name,
|
|
270
|
+
url: vuln.references?.[0]?.url,
|
|
271
|
+
recommendation: "Update dependency or apply security patches",
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return vulnerabilities;
|
|
279
|
+
} catch (error) {
|
|
280
|
+
const errorMessage =
|
|
281
|
+
error instanceof Error ? error.message : String(error);
|
|
282
|
+
frameworkLogger.log("security-scanner", "dependency-check-failed", "warning", { message: "ā ļø Dependency check failed", error: errorMessage });
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Generate comprehensive security report
|
|
289
|
+
*/
|
|
290
|
+
private generateReport(
|
|
291
|
+
tools: SecurityReport["tools"],
|
|
292
|
+
duration: number,
|
|
293
|
+
): SecurityReport {
|
|
294
|
+
const allVulnerabilities = [
|
|
295
|
+
...tools.npmAudit,
|
|
296
|
+
...tools.trivy,
|
|
297
|
+
...tools.eslintSecurity,
|
|
298
|
+
...tools.dependencyCheck,
|
|
299
|
+
];
|
|
300
|
+
|
|
301
|
+
const bySeverity = allVulnerabilities.reduce(
|
|
302
|
+
(acc, vuln) => {
|
|
303
|
+
acc[vuln.severity] = (acc[vuln.severity] || 0) + 1;
|
|
304
|
+
return acc;
|
|
305
|
+
},
|
|
306
|
+
{} as Record<string, number>,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const byTool = {
|
|
310
|
+
npmAudit: tools.npmAudit.length,
|
|
311
|
+
trivy: tools.trivy.length,
|
|
312
|
+
eslintSecurity: tools.eslintSecurity.length,
|
|
313
|
+
dependencyCheck: tools.dependencyCheck.length,
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const highSeverityCount =
|
|
317
|
+
(bySeverity.high || 0) + (bySeverity.critical || 0);
|
|
318
|
+
const shouldFail =
|
|
319
|
+
this.config.failOnVulnerabilities &&
|
|
320
|
+
highSeverityCount > 0 &&
|
|
321
|
+
this.config.severityThreshold !== "low";
|
|
322
|
+
|
|
323
|
+
const recommendations = this.generateRecommendations(allVulnerabilities);
|
|
324
|
+
|
|
325
|
+
return {
|
|
326
|
+
timestamp: new Date().toISOString(),
|
|
327
|
+
duration,
|
|
328
|
+
tools,
|
|
329
|
+
summary: {
|
|
330
|
+
totalVulnerabilities: allVulnerabilities.length,
|
|
331
|
+
bySeverity,
|
|
332
|
+
byTool,
|
|
333
|
+
},
|
|
334
|
+
recommendations,
|
|
335
|
+
compliant: !shouldFail,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Generate security recommendations
|
|
341
|
+
*/
|
|
342
|
+
private generateRecommendations(
|
|
343
|
+
vulnerabilities: SecurityVulnerability[],
|
|
344
|
+
): string[] {
|
|
345
|
+
const recommendations: string[] = [];
|
|
346
|
+
|
|
347
|
+
if (vulnerabilities.some((v) => v.severity === "critical")) {
|
|
348
|
+
recommendations.push(
|
|
349
|
+
"šØ Critical security vulnerabilities found - immediate action required",
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (vulnerabilities.some((v) => v.severity === "high")) {
|
|
354
|
+
recommendations.push(
|
|
355
|
+
"ā ļø High-severity vulnerabilities detected - prioritize fixes",
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (vulnerabilities.filter((v) => v.package).length > 0) {
|
|
360
|
+
recommendations.push(
|
|
361
|
+
"š¦ Update vulnerable dependencies to latest secure versions",
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (vulnerabilities.filter((v) => v.id.includes("eslint")).length > 0) {
|
|
366
|
+
recommendations.push("š§ Fix code security issues identified by ESLint");
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
recommendations.push(
|
|
370
|
+
"š Run regular security scans and keep dependencies updated",
|
|
371
|
+
);
|
|
372
|
+
recommendations.push(
|
|
373
|
+
"š Review security policies and implement security headers",
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
return recommendations;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Save report to file
|
|
381
|
+
*/
|
|
382
|
+
private async saveReport(
|
|
383
|
+
report: SecurityReport,
|
|
384
|
+
jobId: string,
|
|
385
|
+
): Promise<void> {
|
|
386
|
+
try {
|
|
387
|
+
await fs.writeFile(
|
|
388
|
+
this.config.reportPath,
|
|
389
|
+
JSON.stringify(report, null, 2),
|
|
390
|
+
);
|
|
391
|
+
frameworkLogger.log("security-scanner", "report-saved", "success", {
|
|
392
|
+
jobId,
|
|
393
|
+
reportPath: this.config.reportPath,
|
|
394
|
+
});
|
|
395
|
+
} catch (error) {
|
|
396
|
+
const errorMessage =
|
|
397
|
+
error instanceof Error ? error.message : String(error);
|
|
398
|
+
frameworkLogger.log("security-scanner", "save-report-failed", "warning", { message: "ā ļø Failed to save security report", error: errorMessage });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Log security scan results
|
|
404
|
+
*/
|
|
405
|
+
private async logResults(report: SecurityReport): Promise<void> {
|
|
406
|
+
await frameworkLogger.log(
|
|
407
|
+
"security-scanner",
|
|
408
|
+
"-n-security-scan-complete-report-duration-ms-",
|
|
409
|
+
"info",
|
|
410
|
+
{ message: `\nš Security Scan Complete (${report.duration}ms)` },
|
|
411
|
+
);
|
|
412
|
+
await frameworkLogger.log(
|
|
413
|
+
"security-scanner",
|
|
414
|
+
"-total-vulnerabilities-report-summary-totalvulnera",
|
|
415
|
+
"info",
|
|
416
|
+
{
|
|
417
|
+
message: `š Total vulnerabilities: ${report.summary.totalVulnerabilities}`,
|
|
418
|
+
},
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
await frameworkLogger.log("security-scanner", "-n-by-severity-", "info", {
|
|
422
|
+
message: "\nš By Severity:",
|
|
423
|
+
});
|
|
424
|
+
for (const [severity, count] of Object.entries(report.summary.bySeverity)) {
|
|
425
|
+
await frameworkLogger.log(
|
|
426
|
+
"security-scanner",
|
|
427
|
+
"-severity-count-",
|
|
428
|
+
"info",
|
|
429
|
+
{ message: ` ${severity}: ${count}` },
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
await frameworkLogger.log("security-scanner", "-n-by-tool-", "info", {
|
|
434
|
+
message: "\nš ļø By Tool:",
|
|
435
|
+
});
|
|
436
|
+
for (const [tool, count] of Object.entries(report.summary.byTool)) {
|
|
437
|
+
await frameworkLogger.log("security-scanner", "-tool-count-", "info", {
|
|
438
|
+
message: ` ${tool}: ${count}`,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (report.recommendations.length > 0) {
|
|
443
|
+
await frameworkLogger.log(
|
|
444
|
+
"security-scanner",
|
|
445
|
+
"-n-recommendations-",
|
|
446
|
+
"info",
|
|
447
|
+
{ message: "\nš” Recommendations:" },
|
|
448
|
+
);
|
|
449
|
+
for (const rec of report.recommendations) {
|
|
450
|
+
await frameworkLogger.log("security-scanner", "-rec-", "info", {
|
|
451
|
+
message: ` ⢠${rec}`,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (report.compliant) {
|
|
457
|
+
// Security scan result - kept as console.log for user visibility
|
|
458
|
+
} else {
|
|
459
|
+
// Security scan failure - kept as console.log for user visibility
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Map npm audit severity levels
|
|
465
|
+
*/
|
|
466
|
+
private mapNpmSeverity(severity: string): SecurityVulnerability["severity"] {
|
|
467
|
+
switch (severity) {
|
|
468
|
+
case "critical":
|
|
469
|
+
return "critical";
|
|
470
|
+
case "high":
|
|
471
|
+
return "high";
|
|
472
|
+
case "moderate":
|
|
473
|
+
return "moderate";
|
|
474
|
+
case "low":
|
|
475
|
+
return "low";
|
|
476
|
+
default:
|
|
477
|
+
return "moderate";
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Map Trivy severity levels
|
|
483
|
+
*/
|
|
484
|
+
private mapTrivySeverity(
|
|
485
|
+
severity: string,
|
|
486
|
+
): SecurityVulnerability["severity"] {
|
|
487
|
+
switch (severity.toUpperCase()) {
|
|
488
|
+
case "CRITICAL":
|
|
489
|
+
return "critical";
|
|
490
|
+
case "HIGH":
|
|
491
|
+
return "high";
|
|
492
|
+
case "MEDIUM":
|
|
493
|
+
return "moderate";
|
|
494
|
+
case "LOW":
|
|
495
|
+
return "low";
|
|
496
|
+
default:
|
|
497
|
+
return "moderate";
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Map Dependency Check severity levels
|
|
503
|
+
*/
|
|
504
|
+
private mapDependencyCheckSeverity(
|
|
505
|
+
severity: string,
|
|
506
|
+
): SecurityVulnerability["severity"] {
|
|
507
|
+
switch (severity.toUpperCase()) {
|
|
508
|
+
case "CRITICAL":
|
|
509
|
+
return "critical";
|
|
510
|
+
case "HIGH":
|
|
511
|
+
return "high";
|
|
512
|
+
case "MEDIUM":
|
|
513
|
+
return "moderate";
|
|
514
|
+
case "LOW":
|
|
515
|
+
return "low";
|
|
516
|
+
default:
|
|
517
|
+
return "moderate";
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Validate AI prompt security
|
|
523
|
+
*/
|
|
524
|
+
async validatePrompt(prompt: string): Promise<{
|
|
525
|
+
isSafe: boolean;
|
|
526
|
+
violations: string[];
|
|
527
|
+
riskLevel: string;
|
|
528
|
+
}> {
|
|
529
|
+
const result = promptSecurityValidator.validatePrompt(prompt);
|
|
530
|
+
|
|
531
|
+
if (!result.isSafe) {
|
|
532
|
+
frameworkLogger.log("security-scanner", "prompt-violation", "warning", {
|
|
533
|
+
message: `šØ Prompt security violation detected (risk: ${result.riskLevel})`,
|
|
534
|
+
violations: result.violations,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return {
|
|
539
|
+
isSafe: result.isSafe,
|
|
540
|
+
violations: result.violations,
|
|
541
|
+
riskLevel: result.riskLevel,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Validate AI response security
|
|
547
|
+
*/
|
|
548
|
+
async validateResponse(response: string): Promise<{
|
|
549
|
+
isSafe: boolean;
|
|
550
|
+
violations: string[];
|
|
551
|
+
riskLevel: string;
|
|
552
|
+
}> {
|
|
553
|
+
const result = promptSecurityValidator.validateResponse(response);
|
|
554
|
+
|
|
555
|
+
if (!result.isSafe) {
|
|
556
|
+
frameworkLogger.log("security-scanner", "response-violation", "warning", {
|
|
557
|
+
message: `šØ Response security violation detected (risk: ${result.riskLevel})`,
|
|
558
|
+
violations: result.violations,
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
return {
|
|
563
|
+
isSafe: result.isSafe,
|
|
564
|
+
violations: result.violations,
|
|
565
|
+
riskLevel: result.riskLevel,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Create empty report when scanning is disabled
|
|
571
|
+
*/
|
|
572
|
+
private createEmptyReport(): SecurityReport {
|
|
573
|
+
return {
|
|
574
|
+
timestamp: new Date().toISOString(),
|
|
575
|
+
duration: 0,
|
|
576
|
+
tools: {
|
|
577
|
+
npmAudit: [],
|
|
578
|
+
trivy: [],
|
|
579
|
+
eslintSecurity: [],
|
|
580
|
+
dependencyCheck: [],
|
|
581
|
+
},
|
|
582
|
+
summary: {
|
|
583
|
+
totalVulnerabilities: 0,
|
|
584
|
+
bySeverity: {},
|
|
585
|
+
byTool: {
|
|
586
|
+
npmAudit: 0,
|
|
587
|
+
trivy: 0,
|
|
588
|
+
eslintSecurity: 0,
|
|
589
|
+
dependencyCheck: 0,
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
recommendations: ["Security scanning is disabled"],
|
|
593
|
+
compliant: true,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Export singleton instance
|
|
599
|
+
export const securityScanner = new SecurityScanner();
|