0xray 4.0.20 ā 4.0.22
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/.grok-plugin/plugin.json +1 -1
- package/.opencode/skills/hermes-agent/SKILL.md +1 -1
- package/.opencode/skills/orchestrator/SKILL.md +23 -1
- package/.xray/features.json +1 -1
- package/AGENTS-consumer.md +15 -15
- package/AGENTS.md +12 -12
- package/README.md +40 -40
- package/SKILLS.md +4 -4
- package/dist/AGENTS.md +12 -12
- package/dist/CHANGELOG.md +91 -8
- package/dist/README.md +40 -40
- package/dist/SKILLS.md +4 -4
- package/dist/cli/commands/validate.d.ts +1 -1
- package/dist/cli/commands/validate.js +7 -1
- package/dist/governance/governance-core.d.ts +2 -1
- package/dist/governance/governance-core.js +20 -11
- package/dist/governance/governance-service.js +9 -7
- package/dist/inference/inference-cycle.js +22 -5
- package/dist/integrations/cursor/README.md +7 -6
- package/dist/integrations/cursor/hooks/after-file-edit.sh +3 -0
- package/dist/integrations/cursor/hooks/before-read-file.sh +3 -0
- package/dist/integrations/cursor/hooks/before-shell-execution.sh +3 -0
- package/dist/integrations/cursor/hooks/cursor-hook-utils.js +112 -12
- package/dist/integrations/cursor/hooks/cursor-usage-receipt.js +3 -0
- package/dist/integrations/cursor/hooks/hooks.json +13 -3
- package/dist/integrations/cursor/hooks/pre-compact.js +9 -0
- package/dist/integrations/cursor/hooks/pre-compact.sh +3 -0
- package/dist/integrations/cursor/hooks/pre-tool-use.js +17 -12
- package/dist/integrations/cursor/hooks/pre-tool-use.sh +3 -0
- package/dist/integrations/cursor/hooks/xray-cloud-hook.sh +63 -0
- package/dist/integrations/grok/hooks/grok-hook-utils.js +3 -2
- package/dist/integrations/hooks/station-hook-runtime.cjs +310 -98
- package/dist/integrations/hooks/station-hook-runtime.mjs +10 -0
- package/dist/integrations/hooks/station-memory-ingest.mjs +4 -3
- package/dist/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
- package/dist/memory-routing/provider-loader.d.ts +3 -1
- package/dist/memory-routing/provider-loader.js +3 -1
- package/dist/nucleus/suit-temperament.d.ts +0 -5
- package/dist/nucleus/suit-temperament.js +13 -1
- package/dist/nucleus/thin-dispatch.js +11 -2
- package/dist/processors/implementations/agents-md-validation-processor.js +1 -1
- package/dist/skills/hermes-agent/SKILL.md +1 -1
- package/dist/skills/orchestrator/SKILL.md +23 -1
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/scripts/foundry/CHANGELOG.md +2 -0
- package/scripts/foundry/README.md +4 -4
- package/scripts/foundry/assert-packed-dist-cli.mjs +4 -0
- package/scripts/foundry/cli.mjs +1 -1
- package/scripts/foundry/inspect.mjs +160 -5
- package/scripts/foundry/plant/skills/inspect/SKILL.md +2 -0
- package/scripts/foundry/plant/skills/mill/SKILL.md +1 -1
- package/scripts/foundry/validate-release-docs.mjs +48 -0
- package/scripts/foundry/version-manager.mjs +127 -7
- package/scripts/mjs/test-consumer-readiness.mjs +10 -3
- package/scripts/node/install-bridges.cjs +256 -10
- package/src/integrations/openclaw/plugin/xray-pre-tool/package.json +1 -1
- package/src/skills/hermes-agent/SKILL.md +1 -1
- package/src/skills/orchestrator/SKILL.md +23 -1
- package/vendor/@0xray/repertoire/data/stack-overlay.json +154 -1
- package/vendor/@0xray/repertoire/dist/RepertoireService.js +7 -6
- package/vendor/@0xray/repertoire/dist/ingestion/xray-session-ingester.js +10 -11
- package/vendor/@0xray/repertoire/dist/paths.js +66 -4
- package/vendor/@0xray/repertoire/dist/registry/CuratedSignalsManager.js +54 -14
- package/xray/agents_template.md +10 -5
- package/xray/features.json +1 -1
- package/dist/mcps/shared/prompt-security-validator.d.ts +0 -44
- package/dist/mcps/shared/prompt-security-validator.js +0 -148
- package/dist/mcps/shared/security-scanner.d.ts +0 -119
- package/dist/mcps/shared/security-scanner.js +0 -429
- package/dist/scripts/activate-kernel-pipeline.d.ts +0 -7
- package/dist/scripts/activate-kernel-pipeline.js +0 -101
- package/src/mcps/shared/prompt-security-validator.ts +0 -199
- package/src/mcps/shared/security-scanner.ts +0 -599
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 0xRay Framework - AI Prompt Security Validator
|
|
3
|
-
*
|
|
4
|
-
* Specialized security validation for AI agent prompts and responses
|
|
5
|
-
* Prevents prompt injection, system prompt override, and malicious inputs
|
|
6
|
-
*/
|
|
7
|
-
export class PromptSecurityValidator {
|
|
8
|
-
config;
|
|
9
|
-
constructor(config = {}) {
|
|
10
|
-
this.config = {
|
|
11
|
-
enabled: true,
|
|
12
|
-
maxPromptLength: 10000,
|
|
13
|
-
allowedPatterns: [],
|
|
14
|
-
blockedPatterns: [
|
|
15
|
-
/system\s+prompt\s*[:=]/gi,
|
|
16
|
-
/ignore\s+previous\s+instructions/gi,
|
|
17
|
-
/you\s+are\s+now\s+/gi,
|
|
18
|
-
/forget\s+your\s+previous\s+/gi,
|
|
19
|
-
/override\s+(your\s+)?instructions/gi,
|
|
20
|
-
/jailbreak/gi,
|
|
21
|
-
/dan.*mode/gi,
|
|
22
|
-
],
|
|
23
|
-
sanitizeLevel: "strict",
|
|
24
|
-
...config,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Validate AI prompt for security issues
|
|
29
|
-
*/
|
|
30
|
-
validatePrompt(prompt) {
|
|
31
|
-
if (!this.config.enabled) {
|
|
32
|
-
return { isSafe: true, violations: [], riskLevel: "low" };
|
|
33
|
-
}
|
|
34
|
-
const violations = [];
|
|
35
|
-
let riskLevel = "low";
|
|
36
|
-
// Length check
|
|
37
|
-
if (prompt.length > this.config.maxPromptLength) {
|
|
38
|
-
violations.push(`Prompt too long: ${prompt.length} > ${this.config.maxPromptLength}`);
|
|
39
|
-
riskLevel = "medium";
|
|
40
|
-
}
|
|
41
|
-
// Blocked pattern check
|
|
42
|
-
for (const pattern of this.config.blockedPatterns) {
|
|
43
|
-
if (pattern.test(prompt)) {
|
|
44
|
-
violations.push(`Blocked pattern detected: ${pattern.source}`);
|
|
45
|
-
riskLevel = "high";
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// Advanced pattern analysis
|
|
49
|
-
if (this.containsSystemPromptOverride(prompt)) {
|
|
50
|
-
violations.push("Potential system prompt override attempt");
|
|
51
|
-
riskLevel = "critical";
|
|
52
|
-
}
|
|
53
|
-
if (this.containsInjectionAttempts(prompt)) {
|
|
54
|
-
violations.push("Potential prompt injection detected");
|
|
55
|
-
riskLevel = "high";
|
|
56
|
-
}
|
|
57
|
-
const isSafe = violations.length === 0;
|
|
58
|
-
const sanitizedPrompt = isSafe ? undefined : this.sanitizePrompt(prompt);
|
|
59
|
-
return {
|
|
60
|
-
isSafe,
|
|
61
|
-
violations,
|
|
62
|
-
sanitizedPrompt,
|
|
63
|
-
riskLevel,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Check for system prompt override attempts
|
|
68
|
-
*/
|
|
69
|
-
containsSystemPromptOverride(prompt) {
|
|
70
|
-
const overrideIndicators = [
|
|
71
|
-
"you are now",
|
|
72
|
-
"act as if",
|
|
73
|
-
"pretend to be",
|
|
74
|
-
"role-play as",
|
|
75
|
-
"from now on you are",
|
|
76
|
-
"ignore your system",
|
|
77
|
-
"override your",
|
|
78
|
-
"new personality",
|
|
79
|
-
"different role",
|
|
80
|
-
];
|
|
81
|
-
const lowerPrompt = prompt.toLowerCase();
|
|
82
|
-
return overrideIndicators.some((indicator) => lowerPrompt.includes(indicator));
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Check for prompt injection attempts
|
|
86
|
-
*/
|
|
87
|
-
containsInjectionAttempts(prompt) {
|
|
88
|
-
const injectionIndicators = [
|
|
89
|
-
"ignore previous",
|
|
90
|
-
"forget instructions",
|
|
91
|
-
"start over",
|
|
92
|
-
"new conversation",
|
|
93
|
-
"reset context",
|
|
94
|
-
"clear memory",
|
|
95
|
-
"delete history",
|
|
96
|
-
];
|
|
97
|
-
const lowerPrompt = prompt.toLowerCase();
|
|
98
|
-
return injectionIndicators.some((indicator) => lowerPrompt.includes(indicator));
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Sanitize prompt by removing dangerous patterns
|
|
102
|
-
*/
|
|
103
|
-
sanitizePrompt(prompt) {
|
|
104
|
-
let sanitized = prompt;
|
|
105
|
-
// Remove blocked patterns
|
|
106
|
-
for (const pattern of this.config.blockedPatterns) {
|
|
107
|
-
sanitized = sanitized.replace(pattern, "[REDACTED]");
|
|
108
|
-
}
|
|
109
|
-
// Additional sanitization based on level
|
|
110
|
-
if (this.config.sanitizeLevel === "strict" ||
|
|
111
|
-
this.config.sanitizeLevel === "paranoid") {
|
|
112
|
-
// Remove potential code execution
|
|
113
|
-
sanitized = sanitized.replace(/```[\s\S]*?```/g, "[CODE_BLOCK_REMOVED]");
|
|
114
|
-
// Remove potential file system access
|
|
115
|
-
sanitized = sanitized.replace(/(?:\/|\\)\.\.(?:\/|\\)/g, "/");
|
|
116
|
-
// Remove potential command injection
|
|
117
|
-
sanitized = sanitized.replace(/[;&|`$()]/g, "");
|
|
118
|
-
}
|
|
119
|
-
if (this.config.sanitizeLevel === "paranoid") {
|
|
120
|
-
// Extreme sanitization - only allow alphanumeric, spaces, and basic punctuation
|
|
121
|
-
sanitized = sanitized.replace(/[^a-zA-Z0-9\s.,!?-]/g, "");
|
|
122
|
-
}
|
|
123
|
-
return sanitized;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Validate agent response for safety
|
|
127
|
-
*/
|
|
128
|
-
validateResponse(response) {
|
|
129
|
-
// Similar validation but focused on response safety
|
|
130
|
-
const violations = [];
|
|
131
|
-
// Check for potentially harmful content
|
|
132
|
-
if (response.includes("system prompt") ||
|
|
133
|
-
response.includes("internal instructions")) {
|
|
134
|
-
violations.push("Response contains sensitive system information");
|
|
135
|
-
}
|
|
136
|
-
// Check for code execution attempts
|
|
137
|
-
if (/eval\s*\(|Function\s*\(/.test(response)) {
|
|
138
|
-
violations.push("Response contains potential code execution");
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
isSafe: violations.length === 0,
|
|
142
|
-
violations,
|
|
143
|
-
riskLevel: violations.length > 0 ? "medium" : "low",
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
// Export singleton instance
|
|
148
|
-
export const promptSecurityValidator = new PromptSecurityValidator();
|
|
@@ -1,119 +0,0 @@
|
|
|
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
|
-
export interface SecurityScanConfig {
|
|
8
|
-
enabled: boolean;
|
|
9
|
-
tools: {
|
|
10
|
-
npmAudit: boolean;
|
|
11
|
-
trivy: boolean;
|
|
12
|
-
eslintSecurity: boolean;
|
|
13
|
-
dependencyCheck: boolean;
|
|
14
|
-
};
|
|
15
|
-
severityThreshold: "low" | "moderate" | "high" | "critical";
|
|
16
|
-
reportPath: string;
|
|
17
|
-
failOnVulnerabilities: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface SecurityVulnerability {
|
|
20
|
-
id: string;
|
|
21
|
-
title: string;
|
|
22
|
-
description: string;
|
|
23
|
-
severity: "low" | "moderate" | "high" | "critical";
|
|
24
|
-
package?: string;
|
|
25
|
-
version?: string;
|
|
26
|
-
cve?: string;
|
|
27
|
-
url?: string;
|
|
28
|
-
recommendation: string;
|
|
29
|
-
}
|
|
30
|
-
export interface SecurityReport {
|
|
31
|
-
timestamp: string;
|
|
32
|
-
duration: number;
|
|
33
|
-
tools: {
|
|
34
|
-
npmAudit: SecurityVulnerability[];
|
|
35
|
-
trivy: SecurityVulnerability[];
|
|
36
|
-
eslintSecurity: SecurityVulnerability[];
|
|
37
|
-
dependencyCheck: SecurityVulnerability[];
|
|
38
|
-
};
|
|
39
|
-
summary: {
|
|
40
|
-
totalVulnerabilities: number;
|
|
41
|
-
bySeverity: Record<string, number>;
|
|
42
|
-
byTool: Record<string, number>;
|
|
43
|
-
};
|
|
44
|
-
recommendations: string[];
|
|
45
|
-
compliant: boolean;
|
|
46
|
-
}
|
|
47
|
-
export declare class SecurityScanner {
|
|
48
|
-
private config;
|
|
49
|
-
constructor(config?: Partial<SecurityScanConfig>);
|
|
50
|
-
/**
|
|
51
|
-
* Run comprehensive security scan
|
|
52
|
-
*/
|
|
53
|
-
runSecurityScan(): Promise<SecurityReport>;
|
|
54
|
-
/**
|
|
55
|
-
* Run npm audit
|
|
56
|
-
*/
|
|
57
|
-
private runNpmAudit;
|
|
58
|
-
/**
|
|
59
|
-
* Run Trivy security scan
|
|
60
|
-
*/
|
|
61
|
-
private runTrivyScan;
|
|
62
|
-
/**
|
|
63
|
-
* Run ESLint security rules
|
|
64
|
-
*/
|
|
65
|
-
private runEslintSecurity;
|
|
66
|
-
/**
|
|
67
|
-
* Run OWASP Dependency Check
|
|
68
|
-
*/
|
|
69
|
-
private runDependencyCheck;
|
|
70
|
-
/**
|
|
71
|
-
* Generate comprehensive security report
|
|
72
|
-
*/
|
|
73
|
-
private generateReport;
|
|
74
|
-
/**
|
|
75
|
-
* Generate security recommendations
|
|
76
|
-
*/
|
|
77
|
-
private generateRecommendations;
|
|
78
|
-
/**
|
|
79
|
-
* Save report to file
|
|
80
|
-
*/
|
|
81
|
-
private saveReport;
|
|
82
|
-
/**
|
|
83
|
-
* Log security scan results
|
|
84
|
-
*/
|
|
85
|
-
private logResults;
|
|
86
|
-
/**
|
|
87
|
-
* Map npm audit severity levels
|
|
88
|
-
*/
|
|
89
|
-
private mapNpmSeverity;
|
|
90
|
-
/**
|
|
91
|
-
* Map Trivy severity levels
|
|
92
|
-
*/
|
|
93
|
-
private mapTrivySeverity;
|
|
94
|
-
/**
|
|
95
|
-
* Map Dependency Check severity levels
|
|
96
|
-
*/
|
|
97
|
-
private mapDependencyCheckSeverity;
|
|
98
|
-
/**
|
|
99
|
-
* Validate AI prompt security
|
|
100
|
-
*/
|
|
101
|
-
validatePrompt(prompt: string): Promise<{
|
|
102
|
-
isSafe: boolean;
|
|
103
|
-
violations: string[];
|
|
104
|
-
riskLevel: string;
|
|
105
|
-
}>;
|
|
106
|
-
/**
|
|
107
|
-
* Validate AI response security
|
|
108
|
-
*/
|
|
109
|
-
validateResponse(response: string): Promise<{
|
|
110
|
-
isSafe: boolean;
|
|
111
|
-
violations: string[];
|
|
112
|
-
riskLevel: string;
|
|
113
|
-
}>;
|
|
114
|
-
/**
|
|
115
|
-
* Create empty report when scanning is disabled
|
|
116
|
-
*/
|
|
117
|
-
private createEmptyReport;
|
|
118
|
-
}
|
|
119
|
-
export declare const securityScanner: SecurityScanner;
|
|
@@ -1,429 +0,0 @@
|
|
|
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
|
-
import { exec } from "child_process";
|
|
8
|
-
import { promises as fs } from "fs";
|
|
9
|
-
import { frameworkLogger } from "../../core/framework-logger.js";
|
|
10
|
-
import { promisify } from "util";
|
|
11
|
-
import { promptSecurityValidator, } from "./prompt-security-validator.js";
|
|
12
|
-
const execAsync = promisify(exec);
|
|
13
|
-
export class SecurityScanner {
|
|
14
|
-
config;
|
|
15
|
-
constructor(config = {}) {
|
|
16
|
-
this.config = {
|
|
17
|
-
enabled: true,
|
|
18
|
-
tools: {
|
|
19
|
-
npmAudit: true,
|
|
20
|
-
trivy: false, // Requires separate installation
|
|
21
|
-
eslintSecurity: true,
|
|
22
|
-
dependencyCheck: false, // Requires separate installation
|
|
23
|
-
...config.tools,
|
|
24
|
-
},
|
|
25
|
-
severityThreshold: "moderate",
|
|
26
|
-
reportPath: "./security-report.json",
|
|
27
|
-
failOnVulnerabilities: true,
|
|
28
|
-
...config,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Run comprehensive security scan
|
|
33
|
-
*/
|
|
34
|
-
async runSecurityScan() {
|
|
35
|
-
const jobId = `security-scan-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
36
|
-
const startTime = Date.now();
|
|
37
|
-
if (!this.config.enabled) {
|
|
38
|
-
return this.createEmptyReport();
|
|
39
|
-
}
|
|
40
|
-
frameworkLogger.log("security-scanner", "scan-start", "info", {
|
|
41
|
-
jobId,
|
|
42
|
-
tools: this.config.tools,
|
|
43
|
-
severityThreshold: this.config.severityThreshold,
|
|
44
|
-
});
|
|
45
|
-
const results = await Promise.allSettled([
|
|
46
|
-
this.config.tools.npmAudit ? this.runNpmAudit() : Promise.resolve([]),
|
|
47
|
-
this.config.tools.trivy ? this.runTrivyScan() : Promise.resolve([]),
|
|
48
|
-
this.config.tools.eslintSecurity
|
|
49
|
-
? this.runEslintSecurity()
|
|
50
|
-
: Promise.resolve([]),
|
|
51
|
-
this.config.tools.dependencyCheck
|
|
52
|
-
? this.runDependencyCheck()
|
|
53
|
-
: Promise.resolve([]),
|
|
54
|
-
]);
|
|
55
|
-
const tools = {
|
|
56
|
-
npmAudit: results[0].status === "fulfilled" ? results[0].value : [],
|
|
57
|
-
trivy: results[1].status === "fulfilled" ? results[1].value : [],
|
|
58
|
-
eslintSecurity: results[2].status === "fulfilled" ? results[2].value : [],
|
|
59
|
-
dependencyCheck: results[3].status === "fulfilled" ? results[3].value : [],
|
|
60
|
-
};
|
|
61
|
-
const duration = Date.now() - startTime;
|
|
62
|
-
const report = this.generateReport(tools, duration);
|
|
63
|
-
// Save report
|
|
64
|
-
await this.saveReport(report, jobId);
|
|
65
|
-
// Log results
|
|
66
|
-
await this.logResults(report);
|
|
67
|
-
return report;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Run npm audit
|
|
71
|
-
*/
|
|
72
|
-
async runNpmAudit() {
|
|
73
|
-
try {
|
|
74
|
-
const { stdout } = await execAsync("npm audit --json");
|
|
75
|
-
const auditResult = JSON.parse(stdout);
|
|
76
|
-
const vulnerabilities = [];
|
|
77
|
-
if (auditResult.vulnerabilities) {
|
|
78
|
-
for (const [packageName, vuln] of Object.entries(auditResult.vulnerabilities)) {
|
|
79
|
-
vulnerabilities.push({
|
|
80
|
-
id: vuln.name || packageName,
|
|
81
|
-
title: vuln.title || "Security vulnerability",
|
|
82
|
-
description: vuln.overview || "No description available",
|
|
83
|
-
severity: this.mapNpmSeverity(vuln.severity),
|
|
84
|
-
package: packageName,
|
|
85
|
-
version: vuln.version,
|
|
86
|
-
cve: vuln.cwe,
|
|
87
|
-
url: vuln.url,
|
|
88
|
-
recommendation: vuln.recommendation || "Update to a secure version",
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return vulnerabilities;
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
96
|
-
frameworkLogger.log("security-scanner", "npm-audit-failed", "warning", { message: "ā ļø npm audit failed", error: errorMessage });
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Run Trivy security scan
|
|
102
|
-
*/
|
|
103
|
-
async runTrivyScan() {
|
|
104
|
-
try {
|
|
105
|
-
const { stdout } = await execAsync("trivy fs --format json .");
|
|
106
|
-
const trivyResult = JSON.parse(stdout);
|
|
107
|
-
const vulnerabilities = [];
|
|
108
|
-
if (trivyResult.Results) {
|
|
109
|
-
for (const result of trivyResult.Results) {
|
|
110
|
-
if (result.Vulnerabilities) {
|
|
111
|
-
for (const vuln of result.Vulnerabilities) {
|
|
112
|
-
vulnerabilities.push({
|
|
113
|
-
id: vuln.VulnerabilityID,
|
|
114
|
-
title: vuln.Title,
|
|
115
|
-
description: vuln.Description,
|
|
116
|
-
severity: this.mapTrivySeverity(vuln.Severity),
|
|
117
|
-
package: vuln.PkgName,
|
|
118
|
-
version: vuln.InstalledVersion,
|
|
119
|
-
cve: vuln.VulnerabilityID,
|
|
120
|
-
url: vuln.PrimaryURL,
|
|
121
|
-
recommendation: vuln.FixedVersion
|
|
122
|
-
? `Update to ${vuln.FixedVersion}`
|
|
123
|
-
: "Review and mitigate",
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return vulnerabilities;
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
133
|
-
frameworkLogger.log("security-scanner", "trivy-scan-failed", "warning", { message: "ā ļø Trivy scan failed", error: errorMessage });
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Run ESLint security rules
|
|
139
|
-
*/
|
|
140
|
-
async runEslintSecurity() {
|
|
141
|
-
try {
|
|
142
|
-
const { stdout } = await execAsync("npx eslint --format json src/");
|
|
143
|
-
const eslintResults = JSON.parse(stdout);
|
|
144
|
-
const vulnerabilities = [];
|
|
145
|
-
for (const result of eslintResults) {
|
|
146
|
-
for (const message of result.messages) {
|
|
147
|
-
if (message.ruleId &&
|
|
148
|
-
(message.ruleId.includes("security") ||
|
|
149
|
-
message.ruleId.includes("xss") ||
|
|
150
|
-
message.ruleId.includes("injection"))) {
|
|
151
|
-
vulnerabilities.push({
|
|
152
|
-
id: message.ruleId,
|
|
153
|
-
title: message.message,
|
|
154
|
-
description: `Security issue in ${result.filePath}:${message.line}:${message.column}`,
|
|
155
|
-
severity: "moderate",
|
|
156
|
-
recommendation: "Fix the security vulnerability according to ESLint recommendations",
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return vulnerabilities;
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
165
|
-
frameworkLogger.log("security-scanner", "eslint-scan-failed", "warning", { message: "ā ļø ESLint security scan failed", error: errorMessage });
|
|
166
|
-
return [];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Run OWASP Dependency Check
|
|
171
|
-
*/
|
|
172
|
-
async runDependencyCheck() {
|
|
173
|
-
try {
|
|
174
|
-
const { stdout } = await execAsync("dependency-check --format JSON --out . --scan .");
|
|
175
|
-
const dcResult = JSON.parse(stdout);
|
|
176
|
-
const vulnerabilities = [];
|
|
177
|
-
if (dcResult.dependencies) {
|
|
178
|
-
for (const dep of dcResult.dependencies) {
|
|
179
|
-
if (dep.vulnerabilities) {
|
|
180
|
-
for (const vuln of dep.vulnerabilities) {
|
|
181
|
-
vulnerabilities.push({
|
|
182
|
-
id: vuln.name,
|
|
183
|
-
title: vuln.description,
|
|
184
|
-
description: vuln.description,
|
|
185
|
-
severity: this.mapDependencyCheckSeverity(vuln.severity),
|
|
186
|
-
package: dep.fileName,
|
|
187
|
-
cve: vuln.name,
|
|
188
|
-
url: vuln.references?.[0]?.url,
|
|
189
|
-
recommendation: "Update dependency or apply security patches",
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return vulnerabilities;
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
199
|
-
frameworkLogger.log("security-scanner", "dependency-check-failed", "warning", { message: "ā ļø Dependency check failed", error: errorMessage });
|
|
200
|
-
return [];
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Generate comprehensive security report
|
|
205
|
-
*/
|
|
206
|
-
generateReport(tools, duration) {
|
|
207
|
-
const allVulnerabilities = [
|
|
208
|
-
...tools.npmAudit,
|
|
209
|
-
...tools.trivy,
|
|
210
|
-
...tools.eslintSecurity,
|
|
211
|
-
...tools.dependencyCheck,
|
|
212
|
-
];
|
|
213
|
-
const bySeverity = allVulnerabilities.reduce((acc, vuln) => {
|
|
214
|
-
acc[vuln.severity] = (acc[vuln.severity] || 0) + 1;
|
|
215
|
-
return acc;
|
|
216
|
-
}, {});
|
|
217
|
-
const byTool = {
|
|
218
|
-
npmAudit: tools.npmAudit.length,
|
|
219
|
-
trivy: tools.trivy.length,
|
|
220
|
-
eslintSecurity: tools.eslintSecurity.length,
|
|
221
|
-
dependencyCheck: tools.dependencyCheck.length,
|
|
222
|
-
};
|
|
223
|
-
const highSeverityCount = (bySeverity.high || 0) + (bySeverity.critical || 0);
|
|
224
|
-
const shouldFail = this.config.failOnVulnerabilities &&
|
|
225
|
-
highSeverityCount > 0 &&
|
|
226
|
-
this.config.severityThreshold !== "low";
|
|
227
|
-
const recommendations = this.generateRecommendations(allVulnerabilities);
|
|
228
|
-
return {
|
|
229
|
-
timestamp: new Date().toISOString(),
|
|
230
|
-
duration,
|
|
231
|
-
tools,
|
|
232
|
-
summary: {
|
|
233
|
-
totalVulnerabilities: allVulnerabilities.length,
|
|
234
|
-
bySeverity,
|
|
235
|
-
byTool,
|
|
236
|
-
},
|
|
237
|
-
recommendations,
|
|
238
|
-
compliant: !shouldFail,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Generate security recommendations
|
|
243
|
-
*/
|
|
244
|
-
generateRecommendations(vulnerabilities) {
|
|
245
|
-
const recommendations = [];
|
|
246
|
-
if (vulnerabilities.some((v) => v.severity === "critical")) {
|
|
247
|
-
recommendations.push("šØ Critical security vulnerabilities found - immediate action required");
|
|
248
|
-
}
|
|
249
|
-
if (vulnerabilities.some((v) => v.severity === "high")) {
|
|
250
|
-
recommendations.push("ā ļø High-severity vulnerabilities detected - prioritize fixes");
|
|
251
|
-
}
|
|
252
|
-
if (vulnerabilities.filter((v) => v.package).length > 0) {
|
|
253
|
-
recommendations.push("š¦ Update vulnerable dependencies to latest secure versions");
|
|
254
|
-
}
|
|
255
|
-
if (vulnerabilities.filter((v) => v.id.includes("eslint")).length > 0) {
|
|
256
|
-
recommendations.push("š§ Fix code security issues identified by ESLint");
|
|
257
|
-
}
|
|
258
|
-
recommendations.push("š Run regular security scans and keep dependencies updated");
|
|
259
|
-
recommendations.push("š Review security policies and implement security headers");
|
|
260
|
-
return recommendations;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Save report to file
|
|
264
|
-
*/
|
|
265
|
-
async saveReport(report, jobId) {
|
|
266
|
-
try {
|
|
267
|
-
await fs.writeFile(this.config.reportPath, JSON.stringify(report, null, 2));
|
|
268
|
-
frameworkLogger.log("security-scanner", "report-saved", "success", {
|
|
269
|
-
jobId,
|
|
270
|
-
reportPath: this.config.reportPath,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
275
|
-
frameworkLogger.log("security-scanner", "save-report-failed", "warning", { message: "ā ļø Failed to save security report", error: errorMessage });
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Log security scan results
|
|
280
|
-
*/
|
|
281
|
-
async logResults(report) {
|
|
282
|
-
await frameworkLogger.log("security-scanner", "-n-security-scan-complete-report-duration-ms-", "info", { message: `\nš Security Scan Complete (${report.duration}ms)` });
|
|
283
|
-
await frameworkLogger.log("security-scanner", "-total-vulnerabilities-report-summary-totalvulnera", "info", {
|
|
284
|
-
message: `š Total vulnerabilities: ${report.summary.totalVulnerabilities}`,
|
|
285
|
-
});
|
|
286
|
-
await frameworkLogger.log("security-scanner", "-n-by-severity-", "info", {
|
|
287
|
-
message: "\nš By Severity:",
|
|
288
|
-
});
|
|
289
|
-
for (const [severity, count] of Object.entries(report.summary.bySeverity)) {
|
|
290
|
-
await frameworkLogger.log("security-scanner", "-severity-count-", "info", { message: ` ${severity}: ${count}` });
|
|
291
|
-
}
|
|
292
|
-
await frameworkLogger.log("security-scanner", "-n-by-tool-", "info", {
|
|
293
|
-
message: "\nš ļø By Tool:",
|
|
294
|
-
});
|
|
295
|
-
for (const [tool, count] of Object.entries(report.summary.byTool)) {
|
|
296
|
-
await frameworkLogger.log("security-scanner", "-tool-count-", "info", {
|
|
297
|
-
message: ` ${tool}: ${count}`,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
if (report.recommendations.length > 0) {
|
|
301
|
-
await frameworkLogger.log("security-scanner", "-n-recommendations-", "info", { message: "\nš” Recommendations:" });
|
|
302
|
-
for (const rec of report.recommendations) {
|
|
303
|
-
await frameworkLogger.log("security-scanner", "-rec-", "info", {
|
|
304
|
-
message: ` ⢠${rec}`,
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (report.compliant) {
|
|
309
|
-
// Security scan result - kept as console.log for user visibility
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
// Security scan failure - kept as console.log for user visibility
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Map npm audit severity levels
|
|
317
|
-
*/
|
|
318
|
-
mapNpmSeverity(severity) {
|
|
319
|
-
switch (severity) {
|
|
320
|
-
case "critical":
|
|
321
|
-
return "critical";
|
|
322
|
-
case "high":
|
|
323
|
-
return "high";
|
|
324
|
-
case "moderate":
|
|
325
|
-
return "moderate";
|
|
326
|
-
case "low":
|
|
327
|
-
return "low";
|
|
328
|
-
default:
|
|
329
|
-
return "moderate";
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Map Trivy severity levels
|
|
334
|
-
*/
|
|
335
|
-
mapTrivySeverity(severity) {
|
|
336
|
-
switch (severity.toUpperCase()) {
|
|
337
|
-
case "CRITICAL":
|
|
338
|
-
return "critical";
|
|
339
|
-
case "HIGH":
|
|
340
|
-
return "high";
|
|
341
|
-
case "MEDIUM":
|
|
342
|
-
return "moderate";
|
|
343
|
-
case "LOW":
|
|
344
|
-
return "low";
|
|
345
|
-
default:
|
|
346
|
-
return "moderate";
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Map Dependency Check severity levels
|
|
351
|
-
*/
|
|
352
|
-
mapDependencyCheckSeverity(severity) {
|
|
353
|
-
switch (severity.toUpperCase()) {
|
|
354
|
-
case "CRITICAL":
|
|
355
|
-
return "critical";
|
|
356
|
-
case "HIGH":
|
|
357
|
-
return "high";
|
|
358
|
-
case "MEDIUM":
|
|
359
|
-
return "moderate";
|
|
360
|
-
case "LOW":
|
|
361
|
-
return "low";
|
|
362
|
-
default:
|
|
363
|
-
return "moderate";
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Validate AI prompt security
|
|
368
|
-
*/
|
|
369
|
-
async validatePrompt(prompt) {
|
|
370
|
-
const result = promptSecurityValidator.validatePrompt(prompt);
|
|
371
|
-
if (!result.isSafe) {
|
|
372
|
-
frameworkLogger.log("security-scanner", "prompt-violation", "warning", {
|
|
373
|
-
message: `šØ Prompt security violation detected (risk: ${result.riskLevel})`,
|
|
374
|
-
violations: result.violations,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
return {
|
|
378
|
-
isSafe: result.isSafe,
|
|
379
|
-
violations: result.violations,
|
|
380
|
-
riskLevel: result.riskLevel,
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Validate AI response security
|
|
385
|
-
*/
|
|
386
|
-
async validateResponse(response) {
|
|
387
|
-
const result = promptSecurityValidator.validateResponse(response);
|
|
388
|
-
if (!result.isSafe) {
|
|
389
|
-
frameworkLogger.log("security-scanner", "response-violation", "warning", {
|
|
390
|
-
message: `šØ Response security violation detected (risk: ${result.riskLevel})`,
|
|
391
|
-
violations: result.violations,
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
isSafe: result.isSafe,
|
|
396
|
-
violations: result.violations,
|
|
397
|
-
riskLevel: result.riskLevel,
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Create empty report when scanning is disabled
|
|
402
|
-
*/
|
|
403
|
-
createEmptyReport() {
|
|
404
|
-
return {
|
|
405
|
-
timestamp: new Date().toISOString(),
|
|
406
|
-
duration: 0,
|
|
407
|
-
tools: {
|
|
408
|
-
npmAudit: [],
|
|
409
|
-
trivy: [],
|
|
410
|
-
eslintSecurity: [],
|
|
411
|
-
dependencyCheck: [],
|
|
412
|
-
},
|
|
413
|
-
summary: {
|
|
414
|
-
totalVulnerabilities: 0,
|
|
415
|
-
bySeverity: {},
|
|
416
|
-
byTool: {
|
|
417
|
-
npmAudit: 0,
|
|
418
|
-
trivy: 0,
|
|
419
|
-
eslintSecurity: 0,
|
|
420
|
-
dependencyCheck: 0,
|
|
421
|
-
},
|
|
422
|
-
},
|
|
423
|
-
recommendations: ["Security scanning is disabled"],
|
|
424
|
-
compliant: true,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
// Export singleton instance
|
|
429
|
-
export const securityScanner = new SecurityScanner();
|