Back to skill

Security audit

Codegraph Assistant

Security checks for vulnerabilities and agentic risk

Overview

The skill is a code-indexing helper, but its memory-writing command can persist untrusted project/tool output into MEMORY.md without confirmation or containment.

Install only if you are comfortable letting the skill index the chosen project and run the globally installed CodeGraph executable. Avoid using inject on untrusted repositories, inspect MEMORY.md after use, and prefer adding confirmation, backups, explicit markers, and untrusted-output delimiters before relying on this in agent memory workflows.

Vulnerability Patterns
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
Findings (1)

T02 · Agent Memory Poisoning

Warning
Location
codegraph_assist.py:66
Finding
Untrusted CodeGraph Output Written to Persistent Agent Memory<![CDATA[ ## Vulnerability Details **File Location**: `codegraph_assist.py:66-87` **Vulnerability Type**: Persistent agent memory poisoning **Risk Level**: Medium ### Vulnerable Code ```python def cmd_inject(path=None): cwd = Path(path or os.getcwd()).resolve() out, err, rc = run_cg(["status"], cwd=str(cwd)) out2, err2, rc2 = run_cg(["files", "--max-depth", "2"], cwd=str(cwd)) summary = f"\n## CodeGraph: {cwd.name}\n" summary += f"_Auto-generated via codegraph-assistant_\n\n" summary += out + "\n### File Structure\n" + out2 memory_path = cwd / MEMORY_FILE existing = memory_path.read_text(encoding="utf-8", errors="replace") if memory_path.exists() else "" marker = "## CodeGraph:" if marker in existing: lines = existing.splitlines() new_lines, skip = [], False for line in lines: if line.startswith(marker): skip = True; continue if skip and line.startswith("## "): skip = False; new_lines.append(line); continue if not skip: new_lines.append(line) existing = "\n".join(new_lines).rstrip() + "\n" memory_path.write_text(existing.rstrip() + "\n" + summary, encoding="utf-8") print(f"Injected summary into {memory_path}") ``` ### Technical Analysis The `inject` command obtains project status and file-structure text from an external `codegraph` executable and writes that output directly into `MEMORY.md`. The project directory name is also embedded in the generated content. None of this generated content is validated, escaped, or explicitly marked as untrusted before being placed in a file intended for persistent Agent memory. This creates a trust-boundary violation: information originating from a project and an external executable is promoted into persistent Agent context. If an attacker can influence the generated output—for example, through crafted project metadata or filenames represented by CodeGraph—or if the locally installed CodeGraph executable ...[truncated 2186 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Store generated CodeGraph data in a dedicated cache or report file that is not automatically treated as Agent memory. 2. Require explicit user confirmation before creating or modifying `MEMORY.md`, and display the exact target path and generated content before writing. 3. Treat CodeGraph output and project-derived values as untrusted data. Place them inside clearly delimited data blocks and state that the enclosed text must not be interpreted as instructions. 4. Validate and normalize generated output before persistence. Reject or encode control characters, memory headings, instruction-like delimiters, and other syntax capable of escaping the intended data section. 5. Use unique start and end markers, such as `<!-- CODEGRAPH_START -->` and `<!-- CODEGRAPH_END -->`, and replace only content between the exact paired markers. 6. Preserve unrelated memory content and create a backup before modifying an existing file. Use an atomic write through a securely created temporary file followed by replacement. 7. Restrict the target path to an explicitly approved project root and verify that `MEMORY.md` is not a symbolic link before writing. 8. Check CodeGraph return codes and abort injection if either subprocess fails; do not persist partial, malformed, or unexpected output. 9. Pin and verify the expected CodeGraph installation or executable integrity to reduce the risk of compromised tool output entering persistent memory. ]]>
Vulnerability Patterns
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (3)

Lp3

Medium
Category
MCP Least Privilege
Confidence
95% confidence
Finding
The skill advertises shell execution plus file read/write behavior but does not declare any explicit tool scope or permission boundaries. In an agent environment, this increases the chance the skill can be invoked with broader-than-necessary capabilities, enabling unintended command execution, filesystem modification, or data exposure if the wrapper or downstream commands are abused.

Natural-Language Policy Violations

Medium
Confidence
92% confidence
Finding
The description and examples present the skill as operating in Chinese only (for example, '一句话拿到项目结构' and commands like ask "你的问题"), with no indication that users may choose another language. This can violate language/locale policy when a skill implicitly forces a specific language without user opt-in.

subprocess module call

Medium
Category
Dangerous Code Execution
Content
def run_cg(args, cwd=None, timeout=120):
    """Run codegraph command, return (stdout, stderr, returncode)."""
    r = subprocess.run(
        [CODEGRAPH_BIN] + args, cwd=cwd,
        capture_output=True, text=True, timeout=timeout
    )
Confidence
70% confidence
Finding
subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Static analysis

No suspicious patterns detected.