hackmyagent 0.11.13 → 0.11.15
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/README.md +26 -3
- package/dist/attack-engine/feedback-loop.d.ts +36 -0
- package/dist/attack-engine/feedback-loop.d.ts.map +1 -0
- package/dist/attack-engine/feedback-loop.js +261 -0
- package/dist/attack-engine/feedback-loop.js.map +1 -0
- package/dist/attack-engine/index.d.ts +13 -0
- package/dist/attack-engine/index.d.ts.map +1 -0
- package/dist/attack-engine/index.js +21 -0
- package/dist/attack-engine/index.js.map +1 -0
- package/dist/attack-engine/payload-generator.d.ts +21 -0
- package/dist/attack-engine/payload-generator.d.ts.map +1 -0
- package/dist/attack-engine/payload-generator.js +210 -0
- package/dist/attack-engine/payload-generator.js.map +1 -0
- package/dist/attack-engine/target-reader.d.ts +15 -0
- package/dist/attack-engine/target-reader.d.ts.map +1 -0
- package/dist/attack-engine/target-reader.js +152 -0
- package/dist/attack-engine/target-reader.js.map +1 -0
- package/dist/attack-engine/training-pipeline.d.ts +57 -0
- package/dist/attack-engine/training-pipeline.d.ts.map +1 -0
- package/dist/attack-engine/training-pipeline.js +146 -0
- package/dist/attack-engine/training-pipeline.js.map +1 -0
- package/dist/attack-engine/types.d.ts +133 -0
- package/dist/attack-engine/types.d.ts.map +1 -0
- package/dist/attack-engine/types.js +22 -0
- package/dist/attack-engine/types.js.map +1 -0
- package/dist/cli.js +248 -15
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/nanomind-core/analyzers/capability-analyzer.d.ts +40 -0
- package/dist/nanomind-core/analyzers/capability-analyzer.d.ts.map +1 -0
- package/dist/nanomind-core/analyzers/capability-analyzer.js +310 -0
- package/dist/nanomind-core/analyzers/capability-analyzer.js.map +1 -0
- package/dist/nanomind-core/analyzers/code-analyzer.d.ts +21 -0
- package/dist/nanomind-core/analyzers/code-analyzer.d.ts.map +1 -0
- package/dist/nanomind-core/analyzers/code-analyzer.js +350 -0
- package/dist/nanomind-core/analyzers/code-analyzer.js.map +1 -0
- package/dist/nanomind-core/analyzers/credential-analyzer.d.ts +20 -0
- package/dist/nanomind-core/analyzers/credential-analyzer.d.ts.map +1 -0
- package/dist/nanomind-core/analyzers/credential-analyzer.js +317 -0
- package/dist/nanomind-core/analyzers/credential-analyzer.js.map +1 -0
- package/dist/nanomind-core/analyzers/governance-analyzer.d.ts +22 -0
- package/dist/nanomind-core/analyzers/governance-analyzer.d.ts.map +1 -0
- package/dist/nanomind-core/analyzers/governance-analyzer.js +393 -0
- package/dist/nanomind-core/analyzers/governance-analyzer.js.map +1 -0
- package/dist/nanomind-core/analyzers/prompt-analyzer.d.ts +22 -0
- package/dist/nanomind-core/analyzers/prompt-analyzer.d.ts.map +1 -0
- package/dist/nanomind-core/analyzers/prompt-analyzer.js +486 -0
- package/dist/nanomind-core/analyzers/prompt-analyzer.js.map +1 -0
- package/dist/nanomind-core/analyzers/scope-analyzer.d.ts +20 -0
- package/dist/nanomind-core/analyzers/scope-analyzer.d.ts.map +1 -0
- package/dist/nanomind-core/analyzers/scope-analyzer.js +326 -0
- package/dist/nanomind-core/analyzers/scope-analyzer.js.map +1 -0
- package/dist/nanomind-core/compiler/semantic-compiler.d.ts +41 -0
- package/dist/nanomind-core/compiler/semantic-compiler.d.ts.map +1 -0
- package/dist/nanomind-core/compiler/semantic-compiler.js +490 -0
- package/dist/nanomind-core/compiler/semantic-compiler.js.map +1 -0
- package/dist/nanomind-core/index.d.ts +30 -0
- package/dist/nanomind-core/index.d.ts.map +1 -0
- package/dist/nanomind-core/index.js +45 -0
- package/dist/nanomind-core/index.js.map +1 -0
- package/dist/nanomind-core/ingestion/artifact-parser.d.ts +48 -0
- package/dist/nanomind-core/ingestion/artifact-parser.d.ts.map +1 -0
- package/dist/nanomind-core/ingestion/artifact-parser.js +203 -0
- package/dist/nanomind-core/ingestion/artifact-parser.js.map +1 -0
- package/dist/nanomind-core/ingestion/input-sanitizer.d.ts +49 -0
- package/dist/nanomind-core/ingestion/input-sanitizer.d.ts.map +1 -0
- package/dist/nanomind-core/ingestion/input-sanitizer.js +80 -0
- package/dist/nanomind-core/ingestion/input-sanitizer.js.map +1 -0
- package/dist/nanomind-core/scanner-bridge.d.ts +49 -0
- package/dist/nanomind-core/scanner-bridge.d.ts.map +1 -0
- package/dist/nanomind-core/scanner-bridge.js +317 -0
- package/dist/nanomind-core/scanner-bridge.js.map +1 -0
- package/dist/nanomind-core/security/defense-in-depth.d.ts +99 -0
- package/dist/nanomind-core/security/defense-in-depth.d.ts.map +1 -0
- package/dist/nanomind-core/security/defense-in-depth.js +206 -0
- package/dist/nanomind-core/security/defense-in-depth.js.map +1 -0
- package/dist/nanomind-core/security/integrity-verifier.d.ts +132 -0
- package/dist/nanomind-core/security/integrity-verifier.d.ts.map +1 -0
- package/dist/nanomind-core/security/integrity-verifier.js +437 -0
- package/dist/nanomind-core/security/integrity-verifier.js.map +1 -0
- package/dist/nanomind-core/types.d.ts +125 -0
- package/dist/nanomind-core/types.d.ts.map +1 -0
- package/dist/nanomind-core/types.js +22 -0
- package/dist/nanomind-core/types.js.map +1 -0
- package/dist/output/asff.d.ts.map +1 -1
- package/dist/output/asff.js +2 -1
- package/dist/output/asff.js.map +1 -1
- package/dist/semantic/index.d.ts +4 -0
- package/dist/semantic/index.d.ts.map +1 -1
- package/dist/semantic/index.js +13 -1
- package/dist/semantic/index.js.map +1 -1
- package/dist/semantic/nanomind-analyzer.d.ts +77 -0
- package/dist/semantic/nanomind-analyzer.d.ts.map +1 -0
- package/dist/semantic/nanomind-analyzer.js +165 -0
- package/dist/semantic/nanomind-analyzer.js.map +1 -0
- package/dist/semantic/nanomind-enhancer.d.ts +50 -0
- package/dist/semantic/nanomind-enhancer.d.ts.map +1 -0
- package/dist/semantic/nanomind-enhancer.js +203 -0
- package/dist/semantic/nanomind-enhancer.js.map +1 -0
- package/dist/simulation/engine.d.ts +69 -0
- package/dist/simulation/engine.d.ts.map +1 -0
- package/dist/simulation/engine.js +297 -0
- package/dist/simulation/engine.js.map +1 -0
- package/dist/simulation/index.d.ts +15 -0
- package/dist/simulation/index.d.ts.map +1 -0
- package/dist/simulation/index.js +31 -0
- package/dist/simulation/index.js.map +1 -0
- package/dist/simulation/llm-executor.d.ts +58 -0
- package/dist/simulation/llm-executor.d.ts.map +1 -0
- package/dist/simulation/llm-executor.js +297 -0
- package/dist/simulation/llm-executor.js.map +1 -0
- package/dist/simulation/mock-tools.d.ts +35 -0
- package/dist/simulation/mock-tools.d.ts.map +1 -0
- package/dist/simulation/mock-tools.js +181 -0
- package/dist/simulation/mock-tools.js.map +1 -0
- package/dist/simulation/probes.d.ts +17 -0
- package/dist/simulation/probes.d.ts.map +1 -0
- package/dist/simulation/probes.js +295 -0
- package/dist/simulation/probes.js.map +1 -0
- package/dist/simulation/types.d.ts +79 -0
- package/dist/simulation/types.d.ts.map +1 -0
- package/dist/simulation/types.js +25 -0
- package/dist/simulation/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Code Analyzer -- AST-based AST-CODE-* checks
|
|
4
|
+
*
|
|
5
|
+
* Queries the SecurityAST for source code security issues including
|
|
6
|
+
* command injection, unsafe deserialization, and path traversal.
|
|
7
|
+
* Uses the structured AST to correlate code patterns with declared
|
|
8
|
+
* capabilities and risk surfaces instead of regex-matching raw text.
|
|
9
|
+
*
|
|
10
|
+
* Checks:
|
|
11
|
+
* AST-CODE-001: Command injection (exec, spawn with user input)
|
|
12
|
+
* AST-CODE-002: Unsafe deserialization (eval, Function constructor)
|
|
13
|
+
* AST-CODE-003: Path traversal (unsanitized file paths)
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.analyzeCode = analyzeCode;
|
|
17
|
+
const defense_in_depth_js_1 = require("../security/defense-in-depth.js");
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Public API
|
|
20
|
+
// ============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* Analyze a SecurityAST for source code security issues.
|
|
23
|
+
* Verifies AST integrity before processing.
|
|
24
|
+
*/
|
|
25
|
+
function analyzeCode(ast, verifier) {
|
|
26
|
+
(0, defense_in_depth_js_1.assertASTIntegrity)(ast, verifier);
|
|
27
|
+
const findings = [];
|
|
28
|
+
findings.push(...checkCommandInjection(ast));
|
|
29
|
+
findings.push(...checkUnsafeDeserialization(ast));
|
|
30
|
+
findings.push(...checkPathTraversal(ast));
|
|
31
|
+
return findings;
|
|
32
|
+
}
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// AST-CODE-001: Command injection
|
|
35
|
+
// ============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Detects command injection vulnerabilities where user-controlled input
|
|
38
|
+
* reaches shell execution functions (exec, spawn, execSync, etc.).
|
|
39
|
+
*
|
|
40
|
+
* Checks AST.inferredCapabilities for shell/exec capabilities and
|
|
41
|
+
* AST.inferredRiskSurface for command injection attack surfaces.
|
|
42
|
+
* Also checks AST.evidenceSpans for direct evidence of injection patterns.
|
|
43
|
+
*/
|
|
44
|
+
function checkCommandInjection(ast) {
|
|
45
|
+
const findings = [];
|
|
46
|
+
// Only relevant for source code and skill artifacts
|
|
47
|
+
if (!isCodeArtifact(ast)) {
|
|
48
|
+
return findings;
|
|
49
|
+
}
|
|
50
|
+
// Check inferred capabilities for shell execution
|
|
51
|
+
const execCapabilities = ast.inferredCapabilities.filter(c => isExecCapability(c));
|
|
52
|
+
// Check risk surfaces for command injection
|
|
53
|
+
const cmdInjectionSurfaces = ast.inferredRiskSurface.filter(r => r.attackClass === 'CMD-INJECT' ||
|
|
54
|
+
r.attackClass === 'COMMAND-INJECTION' ||
|
|
55
|
+
r.attackClass === 'RCE');
|
|
56
|
+
// Check evidence spans for exec-related patterns
|
|
57
|
+
const execEvidence = ast.evidenceSpans.filter(e => e.supports === 'command_injection' ||
|
|
58
|
+
e.supports === 'shell_execution' ||
|
|
59
|
+
e.supports === 'RCE');
|
|
60
|
+
// Combine signals: capabilities + risk surfaces + evidence
|
|
61
|
+
if (execCapabilities.length > 0 || cmdInjectionSurfaces.length > 0) {
|
|
62
|
+
// Determine if user input reaches the exec call
|
|
63
|
+
const hasUserInput = hasUserInputDataFlow(ast);
|
|
64
|
+
const hasExecRisk = cmdInjectionSurfaces.length > 0;
|
|
65
|
+
// Exec capability with no user input = lower risk (static commands)
|
|
66
|
+
// Exec capability with user input = command injection
|
|
67
|
+
if (hasExecRisk || hasUserInput) {
|
|
68
|
+
const bestEvidence = cmdInjectionSurfaces[0]?.evidence ??
|
|
69
|
+
execEvidence[0]?.text ??
|
|
70
|
+
execCapabilities.map(c => c.name).join(', ');
|
|
71
|
+
findings.push({
|
|
72
|
+
checkId: 'AST-CODE-001',
|
|
73
|
+
name: 'Command Injection',
|
|
74
|
+
description: 'User-controlled input can reach shell execution functions. ' +
|
|
75
|
+
'Functions like exec(), spawn(), execSync(), or child_process are called ' +
|
|
76
|
+
'with data that may originate from untrusted sources (user input, tool ' +
|
|
77
|
+
'outputs, retrieved documents).',
|
|
78
|
+
category: 'Code Security',
|
|
79
|
+
severity: 'critical',
|
|
80
|
+
passed: false,
|
|
81
|
+
message: `Command injection: ${truncate(bestEvidence, 80)}`,
|
|
82
|
+
fixable: true,
|
|
83
|
+
file: ast.artifactPath,
|
|
84
|
+
fix: 'Replace shell execution with safer alternatives: ' +
|
|
85
|
+
'1. Use execFile() or spawn() with an argument array instead of exec() with string interpolation. ' +
|
|
86
|
+
'2. Validate and sanitize all inputs before passing to shell commands. ' +
|
|
87
|
+
'3. Use allowlists for permitted commands rather than blocklists. ' +
|
|
88
|
+
'4. Consider removing shell execution entirely and using native APIs.',
|
|
89
|
+
guidance: 'Command injection is consistently rated a top vulnerability. ' +
|
|
90
|
+
'Never concatenate user input into shell command strings. ' +
|
|
91
|
+
'Even "harmless" commands become dangerous with shell metacharacters (;, |, $()).',
|
|
92
|
+
attackClass: 'CMD-INJECT',
|
|
93
|
+
confidence: hasExecRisk ? 0.9 : 0.7,
|
|
94
|
+
evidence: bestEvidence,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (execCapabilities.length > 0) {
|
|
98
|
+
// Exec capability without detected user input -- still flag as medium
|
|
99
|
+
findings.push({
|
|
100
|
+
checkId: 'AST-CODE-001',
|
|
101
|
+
name: 'Shell Execution Capability',
|
|
102
|
+
description: 'The code exercises shell execution capabilities. While no direct user ' +
|
|
103
|
+
'input flow was detected, shell execution in an agent context is risky ' +
|
|
104
|
+
'because prompt injection can influence arguments indirectly.',
|
|
105
|
+
category: 'Code Security',
|
|
106
|
+
severity: 'medium',
|
|
107
|
+
passed: false,
|
|
108
|
+
message: `Shell execution: ${execCapabilities.map(c => c.name).join(', ')}`,
|
|
109
|
+
fixable: true,
|
|
110
|
+
file: ast.artifactPath,
|
|
111
|
+
fix: 'Audit all shell execution calls to ensure no user-controlled data reaches them. ' +
|
|
112
|
+
'Use execFile() with argument arrays instead of exec() with string concatenation. ' +
|
|
113
|
+
'Add input validation for any data that flows into shell commands.',
|
|
114
|
+
attackClass: 'CMD-INJECT',
|
|
115
|
+
confidence: 0.5,
|
|
116
|
+
evidence: execCapabilities[0]?.evidence,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return findings;
|
|
121
|
+
}
|
|
122
|
+
// ============================================================================
|
|
123
|
+
// AST-CODE-002: Unsafe deserialization
|
|
124
|
+
// ============================================================================
|
|
125
|
+
/**
|
|
126
|
+
* Detects unsafe deserialization patterns including eval(), Function
|
|
127
|
+
* constructor, and dynamic code execution from untrusted sources.
|
|
128
|
+
*
|
|
129
|
+
* Checks AST.inferredCapabilities for code execution capabilities and
|
|
130
|
+
* AST.inferredRiskSurface for deserialization attack surfaces.
|
|
131
|
+
* Also checks evidence spans for eval/Function patterns.
|
|
132
|
+
*/
|
|
133
|
+
function checkUnsafeDeserialization(ast) {
|
|
134
|
+
const findings = [];
|
|
135
|
+
if (!isCodeArtifact(ast)) {
|
|
136
|
+
return findings;
|
|
137
|
+
}
|
|
138
|
+
// Check capabilities for dynamic code execution
|
|
139
|
+
const codeExecCapabilities = ast.inferredCapabilities.filter(c => isCodeExecCapability(c));
|
|
140
|
+
// Check risk surfaces for deserialization issues
|
|
141
|
+
const deserialSurfaces = ast.inferredRiskSurface.filter(r => r.attackClass === 'UNSAFE-DESER' ||
|
|
142
|
+
r.attackClass === 'DESERIALIZATION' ||
|
|
143
|
+
r.attackClass === 'CODE-EXEC' ||
|
|
144
|
+
r.attackClass === 'EVAL');
|
|
145
|
+
// Check evidence spans
|
|
146
|
+
const evalEvidence = ast.evidenceSpans.filter(e => e.supports === 'unsafe_deserialization' ||
|
|
147
|
+
e.supports === 'eval_usage' ||
|
|
148
|
+
e.supports === 'dynamic_code_execution');
|
|
149
|
+
if (codeExecCapabilities.length > 0 || deserialSurfaces.length > 0 || evalEvidence.length > 0) {
|
|
150
|
+
const bestEvidence = deserialSurfaces[0]?.evidence ??
|
|
151
|
+
evalEvidence[0]?.text ??
|
|
152
|
+
codeExecCapabilities.map(c => c.name).join(', ');
|
|
153
|
+
const hasRiskSurface = deserialSurfaces.length > 0;
|
|
154
|
+
const hasUserInput = hasUserInputDataFlow(ast);
|
|
155
|
+
findings.push({
|
|
156
|
+
checkId: 'AST-CODE-002',
|
|
157
|
+
name: 'Unsafe Deserialization',
|
|
158
|
+
description: 'Dynamic code execution detected (eval, Function constructor, or equivalent). ' +
|
|
159
|
+
'These patterns execute arbitrary code at runtime, which in an agent context ' +
|
|
160
|
+
'means prompt injection can achieve remote code execution.' +
|
|
161
|
+
(hasUserInput
|
|
162
|
+
? ' User-controlled data flows into the execution context.'
|
|
163
|
+
: ''),
|
|
164
|
+
category: 'Code Security',
|
|
165
|
+
severity: hasRiskSurface || hasUserInput ? 'critical' : 'high',
|
|
166
|
+
passed: false,
|
|
167
|
+
message: `Unsafe deserialization: ${truncate(bestEvidence, 80)}`,
|
|
168
|
+
fixable: true,
|
|
169
|
+
file: ast.artifactPath,
|
|
170
|
+
fix: 'Remove eval(), new Function(), and similar dynamic code execution: ' +
|
|
171
|
+
'1. Replace eval(jsonString) with JSON.parse(jsonString). ' +
|
|
172
|
+
'2. Replace new Function(code) with a safe interpreter or allowlisted operations. ' +
|
|
173
|
+
'3. For template evaluation, use a sandboxed template engine. ' +
|
|
174
|
+
'4. Never deserialize untrusted data with eval or pickle/marshal equivalents.',
|
|
175
|
+
guidance: 'eval() is the most dangerous function in any language. In an agent context, ' +
|
|
176
|
+
'it turns any prompt injection into remote code execution. There is almost ' +
|
|
177
|
+
'always a safer alternative.',
|
|
178
|
+
attackClass: 'UNSAFE-DESER',
|
|
179
|
+
confidence: hasRiskSurface ? 0.9 : 0.7,
|
|
180
|
+
evidence: bestEvidence,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return findings;
|
|
184
|
+
}
|
|
185
|
+
// ============================================================================
|
|
186
|
+
// AST-CODE-003: Path traversal
|
|
187
|
+
// ============================================================================
|
|
188
|
+
/**
|
|
189
|
+
* Detects path traversal vulnerabilities where user input controls file
|
|
190
|
+
* paths without sanitization. In an agent context, prompt injection can
|
|
191
|
+
* manipulate file paths to read/write outside the intended directory.
|
|
192
|
+
*
|
|
193
|
+
* Checks AST.inferredCapabilities for file access capabilities and
|
|
194
|
+
* AST.inferredRiskSurface for path traversal attack surfaces.
|
|
195
|
+
*/
|
|
196
|
+
function checkPathTraversal(ast) {
|
|
197
|
+
const findings = [];
|
|
198
|
+
if (!isCodeArtifact(ast)) {
|
|
199
|
+
return findings;
|
|
200
|
+
}
|
|
201
|
+
// Check capabilities for file operations
|
|
202
|
+
const fileCapabilities = ast.inferredCapabilities.filter(c => isFileCapability(c));
|
|
203
|
+
// Check risk surfaces for path traversal
|
|
204
|
+
const pathTraversalSurfaces = ast.inferredRiskSurface.filter(r => r.attackClass === 'PATH-TRAVERSAL' ||
|
|
205
|
+
r.attackClass === 'DIR-TRAVERSAL' ||
|
|
206
|
+
r.attackClass === 'FILE-ACCESS');
|
|
207
|
+
// Check evidence spans
|
|
208
|
+
const pathEvidence = ast.evidenceSpans.filter(e => e.supports === 'path_traversal' ||
|
|
209
|
+
e.supports === 'unsanitized_path' ||
|
|
210
|
+
e.supports === 'file_access');
|
|
211
|
+
// Direct path traversal risk surfaces
|
|
212
|
+
if (pathTraversalSurfaces.length > 0) {
|
|
213
|
+
for (const surface of pathTraversalSurfaces) {
|
|
214
|
+
findings.push({
|
|
215
|
+
checkId: 'AST-CODE-003',
|
|
216
|
+
name: 'Path Traversal',
|
|
217
|
+
description: `Path traversal detected: ${surface.surface}. ` +
|
|
218
|
+
'User-controlled input can manipulate file paths to escape the intended ' +
|
|
219
|
+
'directory, potentially reading sensitive files (/etc/passwd, .env) or ' +
|
|
220
|
+
'writing to critical locations.',
|
|
221
|
+
category: 'Code Security',
|
|
222
|
+
severity: surface.confidence >= 0.7 ? 'critical' : 'high',
|
|
223
|
+
passed: false,
|
|
224
|
+
message: `Path traversal: ${truncate(surface.evidence, 80)}`,
|
|
225
|
+
fixable: true,
|
|
226
|
+
file: ast.artifactPath,
|
|
227
|
+
fix: surface.mitigation ??
|
|
228
|
+
'Sanitize all file paths: ' +
|
|
229
|
+
'1. Use path.resolve() and verify the result is within the allowed directory. ' +
|
|
230
|
+
'2. Reject paths containing ".." segments. ' +
|
|
231
|
+
'3. Use path.basename() to strip directory components from user input. ' +
|
|
232
|
+
'4. Maintain an allowlist of accessible directories.',
|
|
233
|
+
attackClass: 'PATH-TRAVERSAL',
|
|
234
|
+
confidence: surface.confidence,
|
|
235
|
+
evidence: surface.evidence,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// File capabilities + user input but no explicit traversal surface
|
|
240
|
+
if (pathTraversalSurfaces.length === 0 && fileCapabilities.length > 0) {
|
|
241
|
+
const hasUserInput = hasUserInputDataFlow(ast);
|
|
242
|
+
const hasWriteCapability = fileCapabilities.some(c => c.name.includes('write') || c.name.includes('delete') || c.name.includes('create'));
|
|
243
|
+
if (hasUserInput || hasWriteCapability) {
|
|
244
|
+
const bestEvidence = pathEvidence[0]?.text ??
|
|
245
|
+
fileCapabilities.map(c => c.name).join(', ');
|
|
246
|
+
findings.push({
|
|
247
|
+
checkId: 'AST-CODE-003',
|
|
248
|
+
name: hasWriteCapability ? 'Unsanitized File Write' : 'Unsanitized File Access',
|
|
249
|
+
description: `File ${hasWriteCapability ? 'write' : 'access'} capabilities detected ` +
|
|
250
|
+
`(${fileCapabilities.map(c => c.name).join(', ')}) ` +
|
|
251
|
+
(hasUserInput
|
|
252
|
+
? 'with user-controlled input in the data flow. '
|
|
253
|
+
: 'in an agent context where prompt injection can influence paths. ') +
|
|
254
|
+
'Without path sanitization, this creates a traversal risk.',
|
|
255
|
+
category: 'Code Security',
|
|
256
|
+
severity: hasWriteCapability ? 'high' : 'medium',
|
|
257
|
+
passed: false,
|
|
258
|
+
message: `File ${hasWriteCapability ? 'write' : 'access'} without path sanitization`,
|
|
259
|
+
fixable: true,
|
|
260
|
+
file: ast.artifactPath,
|
|
261
|
+
fix: 'Add path sanitization: ' +
|
|
262
|
+
'1. Resolve paths with path.resolve() and check they stay within the project root. ' +
|
|
263
|
+
'2. Use a chroot or sandboxed filesystem for agent operations. ' +
|
|
264
|
+
'3. Reject path inputs containing "..", "~", or absolute paths from user input.',
|
|
265
|
+
guidance: 'In an agent context, path traversal is especially dangerous because prompt ' +
|
|
266
|
+
'injection can craft paths like "../../../../etc/passwd" indirectly through ' +
|
|
267
|
+
'tool outputs or retrieved documents.',
|
|
268
|
+
attackClass: 'PATH-TRAVERSAL',
|
|
269
|
+
confidence: hasUserInput ? 0.7 : 0.5,
|
|
270
|
+
evidence: bestEvidence,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return findings;
|
|
275
|
+
}
|
|
276
|
+
// ============================================================================
|
|
277
|
+
// Helpers
|
|
278
|
+
// ============================================================================
|
|
279
|
+
/**
|
|
280
|
+
* Determine if the artifact is a code artifact.
|
|
281
|
+
*/
|
|
282
|
+
function isCodeArtifact(ast) {
|
|
283
|
+
return (ast.artifactType === 'source_code' ||
|
|
284
|
+
ast.artifactType === 'skill' ||
|
|
285
|
+
ast.artifactType === 'agent_config');
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Check if a capability represents shell execution.
|
|
289
|
+
*/
|
|
290
|
+
function isExecCapability(cap) {
|
|
291
|
+
const name = cap.name.toLowerCase();
|
|
292
|
+
return (name.includes('exec') ||
|
|
293
|
+
name.includes('spawn') ||
|
|
294
|
+
name.includes('shell') ||
|
|
295
|
+
name.includes('command') ||
|
|
296
|
+
name.includes('process') ||
|
|
297
|
+
name.includes('system'));
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Check if a capability represents dynamic code execution (eval-like).
|
|
301
|
+
*/
|
|
302
|
+
function isCodeExecCapability(cap) {
|
|
303
|
+
const name = cap.name.toLowerCase();
|
|
304
|
+
const evidence = (cap.evidence ?? '').toLowerCase();
|
|
305
|
+
return (name.includes('eval') ||
|
|
306
|
+
name.includes('dynamic_code') ||
|
|
307
|
+
name.includes('code_exec') ||
|
|
308
|
+
name.includes('deserialize') ||
|
|
309
|
+
evidence.includes('eval(') ||
|
|
310
|
+
evidence.includes('new function(') ||
|
|
311
|
+
evidence.includes('function('));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Check if a capability represents file system access.
|
|
315
|
+
*/
|
|
316
|
+
function isFileCapability(cap) {
|
|
317
|
+
const name = cap.name.toLowerCase();
|
|
318
|
+
return (name.includes('file') ||
|
|
319
|
+
name.includes('fs.') ||
|
|
320
|
+
name.includes('read') ||
|
|
321
|
+
name.includes('write') ||
|
|
322
|
+
name.includes('path') ||
|
|
323
|
+
name.includes('directory'));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Check if the AST indicates user-controlled input in the data flow.
|
|
327
|
+
* This is a heuristic based on data access patterns and capabilities.
|
|
328
|
+
*/
|
|
329
|
+
function hasUserInputDataFlow(ast) {
|
|
330
|
+
// Check data access patterns for external data sources
|
|
331
|
+
const hasExternalRead = ast.declaredDataAccess.some(d => d.accessMode === 'read' && (d.dataType === 'general' || d.dataType === 'pii'));
|
|
332
|
+
// Check for capabilities that accept external input
|
|
333
|
+
const hasInputCapability = ast.inferredCapabilities.some(c => {
|
|
334
|
+
const name = c.name.toLowerCase();
|
|
335
|
+
return (name.includes('input') ||
|
|
336
|
+
name.includes('request') ||
|
|
337
|
+
name.includes('param') ||
|
|
338
|
+
name.includes('query') ||
|
|
339
|
+
name.includes('api'));
|
|
340
|
+
});
|
|
341
|
+
// Check risk surfaces that indicate user input flow
|
|
342
|
+
const hasInputRisk = ast.inferredRiskSurface.some(r => r.surface.toLowerCase().includes('user input') || r.surface.toLowerCase().includes('untrusted'));
|
|
343
|
+
return hasExternalRead || hasInputCapability || hasInputRisk;
|
|
344
|
+
}
|
|
345
|
+
function truncate(text, maxLen) {
|
|
346
|
+
if (text.length <= maxLen)
|
|
347
|
+
return text;
|
|
348
|
+
return text.slice(0, maxLen - 3) + '...';
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=code-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-analyzer.js","sourceRoot":"","sources":["../../../src/nanomind-core/analyzers/code-analyzer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAcH,kCAaC;AAvBD,yEAAqE;AAErE,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;GAGG;AACH,SAAgB,WAAW,CACzB,GAAgB,EAChB,QAAuC;IAEvC,IAAA,wCAAkB,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAElC,MAAM,QAAQ,GAAiB,EAAE,CAAC;IAElC,QAAQ,CAAC,IAAI,C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CAAC,WAAW,CAAC,CACrG,CAAC;IAEF,OAAO,eAAe,IAAI,kBAAkB,IAAI,YAAY,CAAC;AAC/D,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,MAAc;IAC5C,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM;QAAE,OAAO,IAAI,CAAC;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential Analyzer -- AST-based AST-CRED-* checks
|
|
3
|
+
*
|
|
4
|
+
* Queries the SecurityAST for credential exposure patterns instead of
|
|
5
|
+
* regex-matching raw text. Understands data flow through AST.declaredDataAccess
|
|
6
|
+
* and distinguishes real credentials from test fixtures and documentation.
|
|
7
|
+
*
|
|
8
|
+
* Checks:
|
|
9
|
+
* AST-CRED-001: Credentials in non-environment contexts
|
|
10
|
+
* AST-CRED-002: Credential forwarding to external destinations
|
|
11
|
+
* AST-CRED-003: Hardcoded secrets in artifact content
|
|
12
|
+
*/
|
|
13
|
+
import type { SecurityAST } from '../types.js';
|
|
14
|
+
import type { ASTFinding } from './capability-analyzer.js';
|
|
15
|
+
/**
|
|
16
|
+
* Analyze a SecurityAST for credential-related security issues.
|
|
17
|
+
* Verifies AST integrity before processing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function analyzeCredentials(ast: SecurityAST, verifier: (ast: SecurityAST) => boolean): ASTFinding[];
|
|
20
|
+
//# sourceMappingURL=credential-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-analyzer.d.ts","sourceRoot":"","sources":["../../../src/nanomind-core/analyzers/credential-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAmC,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAO3D;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,GACtC,UAAU,EAAE,CAUd"}
|