T09 · Insecure Skill Coding Practices
- Location
SKILL.md:126- Finding
Unsafe Evaluation of Untrusted JSON-Like Input as JavaScript
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 126-154
Vulnerability Type: Unsafe dynamic JavaScript evaluation
Risk Level: MediumVulnerable Documentation Excerpt
The following excerpt is an English translation of the relevant instructions:
markdown - **Eval sandbox**: Uses `vm.runInNewContext` for parsing, ensuring that the global scope and `process` cannot be accessed; it is safer than direct `eval`. | `vm.runInNewContext` exception | Malicious code injection attempt | The sandbox has isolated it; verify whether the input file comes from a trusted source | - Although `vm.runInNewContext` is safe, it should not process untrusted malicious files.Technical Analysis
The skill directs the agent to repair malformed JSON by evaluating it as JavaScript through
vm.runInNewContext. This permits JavaScript expressions rather than limiting input to passive JSON data.A new VM context restricts direct access to the host global scope, but it does not make arbitrary JavaScript evaluation equivalent to safe JSON parsing. Crafted input can contain function calls, getters, computationally expensive expressions, memory-intensive operations, or nonterminating loops. These constructs may execute while the purported JSON document is parsed.
The documentation does not require a VM timeout, process-level memory limit, syntax allowlist, isolated worker process, or output-size restriction. It also acknowledges that malicious input may trigger VM exceptions and warns against processing untrusted files, confirming that hostile input is within the relevant threat model.
No JavaScript implementation is included in the audited package, so host escape or access to specific Node.js capabilities cannot be established. The confirmed weakness is the unsafe parsing design prescribed by the skill.
Attack Path
- An attacker provides a file represented as malformed JSON requiring repa ...[truncated 1034 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not evaluate JSON-like input as JavaScript. Use a non-executing parser designed for JSON5 or tolerant JSON repair.
- Pin the parser dependency to a reviewed version and maintain an appropriate lockfile.
- Configure the parser to accept only the explicitly supported extensions: trailing commas, single quotes, unquoted keys, comments, and hexadecimal or octal numbers.
- Reject functions, calls, getters, setters, prototype-related keys, regular expressions, template expressions, and other executable JavaScript constructs.
- Apply file-size, nesting-depth, token-count, processing-time, and output-size limits before parsing.
- If dynamic evaluation cannot immediately be removed, run it in a disposable worker process with a strict timeout, memory limit, empty context, no filesystem or network capabilities, and forced termination on limit violations. This should be treated only as a temporary mitigation.
- Update the documentation to avoid claiming that
vm.runInNewContextmakes untrusted JavaScript safe. - Add negative tests using infinite loops, memory-exhaustion expressions, function calls, getters, and deeply nested input.
