MCPcopy Index your code
hub / github.com/FIND-Lab/AgentWard / toolCallDetect

Function toolCallDetect

layers/exec-control.ts:270–318  ·  view source on GitHub ↗
(
  toolName: string,
  params: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

268}
269
270export function toolCallDetect(
271 toolName: string,
272 params: Record<string, unknown>
273): DetectionResult | null {
274 if (toolName !== "exec") return null;
275
276 const command = params.command;
277 if (typeof command !== "string") return null;
278
279 // System destruction detection
280 if (matchesAnyPattern(command, SYSTEM_DESTRUCTION_PATTERNS)) {
281 return detectBlock(SYSTEM_DESTRUCTION_DETECTED);
282 }
283
284 // Privilege escalation detection
285 if (matchesAnyPattern(command, PRIVILEGE_ESCALATION_PATTERNS)) {
286 return detectBlock(PRIVILEGE_ESCALATION_DETECTED);
287 }
288
289 // Remote code execution detection
290 if (matchesAnyPattern(command, REMOTE_CODE_EXECUTION_PATTERNS)) {
291 return detectBlock(REMOTE_CODE_EXECUTION_DETECTED);
292 }
293
294 // Reverse shell detection
295 if (matchesAnyPattern(command, REVERSE_SHELL_PATTERNS)) {
296 return detectBlock(REVERSE_SHELL_DETECTED);
297 }
298
299 // Sensitive data access detection
300 if (matchesAnyPattern(command, SENSITIVE_DATA_ACCESS_PATTERNS)) {
301 // Medium severity: require explicit operator approval.
302 return detectApprove(SENSITIVE_DATA_ACCESS_DETECTED, { timeoutMs: 300000, timeoutBehavior: "deny" });
303 }
304
305 // Resource exhaustion detection
306 if (matchesAnyPattern(command, RESOURCE_EXHAUSTION_PATTERNS)) {
307 // Potentially dangerous, but can be legitimate in limited contexts.
308 // For demo policy: require approval instead of auto-deny.
309 return detectApprove(RESOURCE_EXHAUSTION_DETECTED, { timeoutMs: 300000, timeoutBehavior: "deny" });
310 }
311
312 // Infinite loop detection
313 if (matchesAnyPattern(command, INFINITE_LOOP_PATTERNS)) {
314 return detectApprove(INFINITE_LOOP_DETECTED, { timeoutMs: 300000, timeoutBehavior: "deny" });
315 }
316
317 return null;
318}

Callers 1

registerFunction · 0.90

Calls 3

detectBlockFunction · 0.90
detectApproveFunction · 0.90
matchesAnyPatternFunction · 0.85

Tested by

no test coverage detected