Back to skill

Security audit

Karpathy Lint

Security checks for vulnerabilities and agentic risk

Overview

This skill is a coherent knowledge-base linting tool, but its Python helpers can read or overwrite files outside the intended knowledge directory if given an unsafe filename.

Review before installing. Use it only in a controlled workspace, avoid passing user-supplied paths or filenames into its parser/save helpers, and patch filename validation before relying on any repair/write behavior. Expect Chinese documentation and output. No network access, credential use, or background service behavior was found.

Vulnerability Patterns
  • 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
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/__init__.py:96
Finding

Path Traversal Allows Arbitrary Local File Reading

Content
View full analysis

Vulnerability Details

File Location: scripts/__init__.py, lines 96-100
Vulnerability Type: Path traversal and unrestricted file read
Risk Level: Medium

Vulnerable Code

python
filepath = self.kp_path / filename
if not filepath.exists():
    return []

content = filepath.read_text(encoding="utf-8")

Technical Analysis

The parse_kp_file() method accepts a caller-supplied filename and joins it directly to self.kp_path without checking whether the resulting path remains inside the configured knowledge-point directory.

A filename containing parent-directory components, such as ../../sensitive-file, can escape the intended directory. In addition, Python's pathlib discards the preceding base path when the second operand is absolute, so an absolute filename can directly select another file.

The existence check does not mitigate this issue because it occurs only after the unsafe path has been constructed. The subsequent read_text() operation reads the selected file under the privileges of the running process. The file must be readable as UTF-8 for the method to return its contents successfully.

Attack Path

  1. An attacker gains control over the filename argument passed to KnowledgePointParser.parse_kp_file().
  2. The attacker supplies a traversal path such as ../../outside-directory/file.md, or an absolute path.
  3. self.kp_path / filename resolves to a location outside the intended knowledge-point directory.
  4. The existence check succeeds for an accessible target.
  5. read_text() reads the target file.
  6. The file content is passed to the Markdown parser, potentially exposing parsed content to the caller or downstream report processing.

Impact Assessment

An attacker can cause the process to read arbitrary UTF-8 text files that are accessible to the operating-system account running the skill. The scope is limited by that account's filesystem permissions and by ...[truncated 255 chars]

Remediation
View remediation

Remediation Suggestions

Resolve and validate all caller-provided paths before reading:

python
base = self.kp_path.resolve()
supplied = Path(filename)

if supplied.is_absolute() or ".." in supplied.parts:
    raise ValueError("Invalid knowledge-point filename")

target = (base / supplied).resolve()
if target.parent != base:
    raise ValueError("File must remain in the knowledge-point directory")

content = target.read_text(encoding="utf-8")

Additional hardening measures:

  • Accept only simple filenames rather than paths.
  • Enforce the documented naming convention, such as knowledge-points-YYYY-MM-DD.md.
  • Reject path separators, absolute paths, . components, and .. components.
  • If subdirectories must be supported, use target.is_relative_to(base) after resolving both paths.
  • Check that the resolved target is a regular file and apply an appropriate maximum file-size limit.
  • Add tests covering absolute paths, traversal paths, symbolic links, invalid encodings, and paths outside the configured base directory.

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/__init__.py:190
Finding

Path Traversal Allows Arbitrary Local File Overwrite

Content
View full analysis

Vulnerability Details

File Location: scripts/__init__.py, lines 190-218
Vulnerability Type: Path traversal and unrestricted file write
Risk Level: Medium

Vulnerable Code

python
filepath = self.kp_path / filename

lines = [
    f"# Knowledge Points - {datetime.now().strftime('%Y-%m-%d')}",
    "",
    f"Knowledge points count: {len(points)}",
    "",
    "---",
    ""
]

for kp in points:
    lines.append(f"## {kp['title']}")
    lines.append("")
    lines.append(f"**核心概念**: {kp.get('core_concept', '')}")
    lines.append(f"**来源**: {kp.get('source', '')}")
    lines.append(f"**可信度**: {kp.get('confidence', 'medium')}")
    lines.append("")
    if kp.get('detailed_explanation'):
        lines.append("### 详细说明")
        lines.append(kp['detailed_explanation'])
        lines.append("")
    lines.append(f"**标签**: {', '.join(kp.get('tags', []))}")
    lines.append(f"**创建时间**: {kp.get('created_at', '')}")
    lines.append("")
    lines.append("---")
    lines.append("")

with open(filepath, "w", encoding="utf-8") as f:
    f.write("\n".join(lines))

Technical Analysis

The save_kp_file() method uses a caller-supplied filename to construct the output path without validating or containing that path. Parent-directory traversal components can escape self.kp_path, and an absolute path replaces the configured base path entirely.

The file is opened in "w" mode, which creates a new file or truncates an existing file before writing. Consequently, any file writable by the process can potentially be replaced with generated Markdown content. Several fields in that content are derived from the caller-provided points collection, giving the caller partial control over the data written to the selected target.

Attack Path

  1. An attacker controls the filename argument passed to KnowledgePointParser.save_kp_file().
  2. The attacker supplies a path such as `.. ...[truncated 995 chars]
Remediation
View remediation

Remediation Suggestions

Restrict output to validated filenames beneath the configured directory:

python
base = self.kp_path.resolve()
supplied = Path(filename)

if supplied.is_absolute() or len(supplied.parts) != 1:
    raise ValueError("Invalid knowledge-point filename")

if not re.fullmatch(r"knowledge-points-\d{4}-\d{2}-\d{2}\.md", supplied.name):
    raise ValueError("Unexpected knowledge-point filename")

target = (base / supplied.name).resolve()
if target.parent != base:
    raise ValueError("Output must remain in the knowledge-point directory")

Additional hardening measures:

  • Create and permission the intended output directory explicitly.
  • Reject absolute paths, traversal components, and path separators.
  • Defend against symbolic-link attacks by validating the resolved path and, where supported, opening files with no-follow and exclusive-creation safeguards.
  • Avoid overwriting existing files unless explicitly requested and authorized.
  • Use a temporary file in the same validated directory followed by an atomic replacement when updates are required.
  • Apply restrictive file permissions appropriate to the stored data.
  • Add tests proving that traversal paths, absolute paths, symbolic links, and unexpected filename formats are rejected.
Vulnerability Patterns
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (4)

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The skill description and workflow are written in Chinese without indicating language flexibility or offering an opt-in, which can exclude or mislead users who expect interaction in another language. In an agent skill context, this can cause incorrect use, misunderstanding of outputs, or degraded accessibility, though it does not directly enable code execution or privilege abuse.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
89% confidence
Finding

The top-level documentation says this phase performs both quality checking and self-repair. In the actual executable flow, main() runs run_lint() and writes a markdown report, but never calls fix_duplicates() or persists any repaired knowledge points, so the advertised self-repair behavior is not actually performed.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
91% confidence
Finding

This code file contains user-facing and descriptive natural-language text in multiple places that assumes Chinese, such as module docstrings and report labels, without indicating that the user can choose their preferred language. That can violate a language/locale policy when a skill implicitly forces a specific language rather than making it optional or clearly documenting a justified locale constraint.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
94% confidence
Finding

The generated markdown report includes several fixed Chinese labels and headings such as '生成时间', '知识点数', and '发现的问题', making the output language non-optional. Because the file does not offer a locale selection mechanism or document that the tool is intentionally region-specific, this is a natural-language locale-policy concern.

Content

No source excerpt is available for this finding.