Back to skill

Security audit

Hook System

Security checks for vulnerabilities and agentic risk

Overview

This hook framework is not clearly malicious, but it needs review because configured hooks can run shell commands and see tool inputs, outputs, and environment secrets.

Install only if you intentionally want a local hook framework and will run hooks you fully trust. Treat hook commands as code execution with access to your agent environment and tool data; avoid using it where API keys, private files, or sensitive command output may be present unless you add strict allowlists, redaction, sandboxing, and review controls.

Vulnerability Patterns
  • Tool Hijacking and SpoofingModifies or replaces tools so legitimate-looking calls execute attacker logic
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/hook-runner.mjs:40
Finding

Arbitrary Shell Command Execution Through Untrusted Hook Configuration

Content
View full analysis

Vulnerability Details

File Location: scripts/hook-runner.mjs:40-47
Vulnerability Type: OS command injection through shell-based hook execution
Risk Level: High

Vulnerable Code

javascript
function runHookCommand(command, env) {
  return new Promise((resolve) => {
    const isWindows = process.platform === 'win32';
    const shell = isWindows ? 'cmd' : '/bin/sh';
    const shellArgs = isWindows ? ['/C', command] : ['-c', command];

    const child = spawn(shell, shellArgs, {
      env: { ...process.env, ...env },
      stdio: ['pipe', 'pipe', 'pipe']
    });

Technical Analysis

Hook definitions are accepted as strings and passed directly to cmd /C on Windows or /bin/sh -c on other platforms. The shell interprets metacharacters, substitutions, redirections, pipelines, and additional commands contained in each hook string.

Hook configuration can originate from the HookRunner constructor and, in CLI mode, from the HOOK_PRE and HOOK_POST environment variables. Therefore, any party capable of influencing these values can execute arbitrary operating-system commands with the privileges of the Node.js process.

The child process also receives a copy of the complete parent environment through ...process.env. Consequently, an untrusted hook can access credentials, API tokens, service endpoints, and other secrets present in the Agent process environment. No executable allowlist, argument separation, sandbox, privilege reduction, or environment filtering is applied.

Attack Path

  1. An attacker gains influence over the Skill configuration, the HookRunner constructor arguments, or the HOOK_PRE or HOOK_POST environment variable.
  2. The attacker supplies a hook containing an arbitrary shell payload, such as a command chain, file-read operation, or invocation of another executable.
  3. A pre-tool or post-tool event calls runHookCommand() with the attacker-controlled string.

...[truncated 1324 chars]

Remediation
View remediation

Remediation Suggestions

  • Replace shell command strings with structured hook definitions containing an approved executable path and an argument array.
  • Invoke hooks with spawn(executable, args, { shell: false }); do not use /bin/sh -c or cmd /C.
  • Validate executable paths against an explicit allowlist and reject relative paths, unexpected interpreters, and writable executables.
  • Do not inherit the complete parent environment. Construct a minimal environment containing only variables required by the hook.
  • Remove credentials, tokens, proxy secrets, and unrelated service configuration from child-process environments.
  • Require explicit administrative approval before enabling or changing hooks.
  • Protect configuration sources with appropriate filesystem permissions and deployment controls.
  • Execute hooks under a dedicated, low-privilege identity or inside a sandbox with restricted filesystem, process, and network access.
  • Apply execution timeouts, output-size limits, and process termination handling to prevent resource exhaustion.
  • Record the approved hook identifier rather than logging an untrusted command string.

T07 · Tool Hijacking and Spoofing

Warning
Location
scripts/hook-runner.mjs:96
Finding

Unrestricted Tool Data Disclosure and Untrusted Hook Output Injection

Content
View full analysis

Vulnerability Details

File Location: scripts/hook-runner.mjs:96-103 and scripts/hook-runner.mjs:205-220
Vulnerability Type: Tool interception, sensitive data exposure, and result spoofing
Risk Level: Medium

Vulnerable Code

javascript
_buildEnv(event, toolName, toolInput, toolOutput = '', isError = false) {
  return {
    HOOK_EVENT: event,
    HOOK_TOOL_NAME: toolName,
    HOOK_TOOL_INPUT: toolInput,
    HOOK_TOOL_INPUT_PARSED: parseToolInput(toolInput),
    HOOK_TOOL_OUTPUT: toolOutput,
    HOOK_TOOL_IS_ERROR: isError ? '1' : '0'
  };
}
javascript
static mergeOutput(hookMessages, toolOutput, isError = false) {
  if (hookMessages.length === 0) {
    return toolOutput;
  }

  const sections = [];
  if (toolOutput && toolOutput.trim()) {
    sections.push(toolOutput);
  }

  const label = isError ? 'Hook feedback (denied)' : 'Hook feedback';
  sections.push(`${label}:\n${hookMessages.join('\n')}`);

  return sections.join('\n\n');
}

Technical Analysis

Each configured hook receives the complete raw tool input. Post-tool hooks additionally receive the complete raw tool output. These values may contain file contents, command results, credentials, personal data, internal paths, or other sensitive information. The implementation does not provide field-level authorization, data minimization, or secret redaction before exposing the data to hook processes.

Hook standard output and standard error are collected as messages. mergeOutput() can then append those attacker-controlled messages to the legitimate tool result. Although the messages receive a generic hook-feedback label, no trust-boundary metadata, content validation, escaping, or instruction isolation is enforced. A malicious or compromised hook can therefore generate deceptive content that appears adjacent to a legitimate tool response and may influence an Agent or user consuming the merged res ...[truncated 1619 chars]

Remediation
View remediation

Remediation Suggestions

  • Define explicit per-hook permissions identifying which tools and which input or output fields each hook may access.
  • Pass only the minimum required data to each hook rather than complete raw tool payloads.
  • Redact API keys, authorization headers, tokens, passwords, private keys, and other recognized secrets before hook invocation.
  • Avoid passing large or sensitive values through environment variables; use a controlled IPC channel with explicit schemas and size limits.
  • Keep hook diagnostics in a separate structured result field instead of concatenating them with legitimate tool output.
  • Mark hook-generated content as untrusted data and prevent it from being interpreted as Agent instructions.
  • Validate hook responses against a strict schema and reject unexpected control directives or oversized output.
  • Authenticate, review, and integrity-check hook files and configurations before execution.
  • Allow post-processing hooks to return narrowly scoped transformations rather than unrestricted replacement or feedback text.
  • Maintain audit logs identifying which hook accessed which tool event, without recording the sensitive payload itself.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
Findings (10)

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 32)May include surrounding context.

md
const { HookRunner } = require('./scripts/hook-runner.mjs');

Credential Access

High
Category
Privilege Escalation
Confidence
96% confidence
Finding

The child process inherits the full parent environment via env: { ...process.env, ...env }, which can expose API keys, cloud credentials, tokens, and other secrets to every configured hook. Because this is a hook system meant to run around tool invocations, the context makes it more dangerous: hooks receive both sensitive tool data and ambient credentials, enabling straightforward credential theft or exfiltration.

Content

Scanner excerpt · scripts/hook-runner.mjs (reported line 55)May include surrounding context.

js
const shellArgs = isWindows ? ['/C', command] : ['-c', command];

    const child = spawn(shell, shellArgs, {
      env: { ...process.env, ...env },
      stdio: ['pipe', 'pipe', 'pipe']
    });

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
89% confidence
Finding

The skill documents executable hook behavior and environment-variable exposure, but it does not declare any explicit tool scope, permissions, or allowed-tools boundary. In a hook system that can inspect and alter tool inputs/outputs, missing scope increases the risk of unintended access to sensitive context or unsafe execution assumptions.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The trigger phrases are broad enough to activate the skill for generic requests like 'hook' or '拦截工具', which can cause the agent to enter a powerful interception workflow unexpectedly. Because this skill is specifically about pre/post tool interception and output modification, accidental triggering raises the chance of unauthorized logging, blocking, or tampering behavior.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The documented hooks can read raw tool input/output and write them to logs or modify returned content, yet the skill provides no explicit user-facing warning or consent mechanism for data exposure and tampering. This is especially risky because tool inputs/outputs may contain secrets, file contents, tokens, or other sensitive operational data, and post-hooks can silently alter results.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The runner executes hook definitions as arbitrary shell commands via /bin/sh -c or cmd /C, while also passing full process environment and tool input/output into the child environment. In this skill context, hooks are specifically designed to intercept tool activity, so a malicious or compromised hook can execute arbitrary OS commands and exfiltrate secrets, tokens, or sensitive tool data with little isolation.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The manifest says PreToolUse can modify input and PostToolUse can modify output. In the implementation, tool input/output are exposed to hook commands through environment variables, but there is no mechanism to read back a transformed input or output from hook results and substitute it into execution; the only post-processing behavior implemented is collecting stdout/stderr as messages and, separately, mergeOutput appending those messages to the tool output.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The inline comment explicitly states 'PostToolUse 钩子不能阻止执行,但可以修改输出'. However, the function does not rewrite or return a modified output value; it only normalizes allowed/denied flags and returns hook messages. This is an active contradiction between documentation and implementation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
80% confidence
Finding

The natural-language description and trigger phrases are presented only in Chinese, with no indication that other languages are supported or that the Chinese locale is an intentional, documented constraint. This can violate language-choice policy when users are not given an opt-in or alternative.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
96% confidence
Finding

Multiple comments and CLI help strings are written in Chinese, creating a fixed language experience for users who interact with the script. The file does not indicate that this is a region-specific tool or provide any opt-in or fallback for other languages.

Content

No source excerpt is available for this finding.