T09 · Insecure Skill Coding Practices
- Location
scripts/generate.mjs:125- Finding
OS Command Injection Through the Generator Output Path
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This Mermaid diagram skill is purpose-aligned, but it needs Review because crafted file paths could make its scripts run unintended local commands.
Install only after the command-injection issues are fixed by using non-shell process calls with argument arrays, and prefer a pinned local Mermaid CLI dependency over global npm install. Until then, do not run the generator or validator on paths, directories, or filenames influenced by someone else, and avoid sudo-based npm installation.
scripts/generate.mjs:125OS Command Injection Through the Generator Output Path
scripts/validate.mjs:82OS Command Injection Through the Validator Directory Path
scripts/install-deps.sh:115Mutable Global Dependency Installation Creates Supply-Chain Exposure
Referenced artifact was not completely inspected
node scripts/generate.mjs --content content.json --out diagrams/chapter-01
Referenced artifact was not completely inspected
node scripts/generate.mjs --content content.json --out diagrams/chapter-01
Referenced artifact was not completely inspected
node scripts/generate.mjs --content content.json --out diagrams/chapter-01
Referenced artifact was not completely inspected
node scripts/generate.mjs --content content.json --out diagrams/chapter-01
Referenced artifact was not completely inspected
node scripts/generate.mjs --content content.json --out diagrams/chapter-01
Referenced artifact was not completely inspected
node scripts/generate.mjs --content content.json --out diagrams/chapter-01
Tool calls are chained to bypass individual safety checks or escalate capabilities beyond what any single tool call would allow.
"validate": "node scripts/validate.mjs",
"test": "node scripts/run-semantic-tests.mjs && npm run test:render",
"test:semantic": "node scripts/run-semantic-tests.mjs",
"test:render": "node scripts/generate.mjs --content tests/all-templates-content.json --out test-output && node scripts/validate.mjs --dir test-output && rm -rf test-output",
"install-deps": "./scripts/install-deps.sh"
},
"dependencies": {},
YARA rule matched a known malware signature (reverse shell, backdoor, ransomware, C2 framework, or info stealer).
roubleshooting:"
echo " 1. Check npm permissions:"
echo " npm config get prefix"
echo " (Should be a writable directory)"
echo ""
echo " 2. Try with sudo (not recommended):"
echo " sudo npm install -g @mermaid-js/mermaid-cli"
echo ""
echo " 3. Fix npm permissions (recommended):"
echo " mkdir -p ~/.npm-global"
echo " npm config set prefix ~/.npm-global"
echo " echo 'export PATH=~/.npm-global/bin:\$PATH' >> ~/.bashrc"
echo " source ~/.bashrc"
echo " npm install -g @mermaid-js/mermaid-cli"
echo ""
exit 1
fi
###############################################################################
# Verify Installation
###############################################################################
print_info "Verifying installation..."
if ! command -v mmdc &> /dev/null; then
print_error "mmdc not found after installation"
echo ""
echo "Possible causes:"
echo " - npm global bin directory not in PATH"
echo " - Installation
The skill metadata includes very broad trigger phrases such as "generate diagram" and "technical illustration," which are generic enough to match many ordinary requests outside the intended Mermaid-specific workflow. This can cause unintended invocation of the skill, increasing the chance that it reads files, spawns subagents, or suggests running local scripts in contexts where the user did not explicitly ask for this capability.
Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.
assets/new-template.mmd with theme and placeholdersTEMPLATES object in scripts/generate.mjs:const TEMPLATES = {
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
echo ""
echo "Please install Node.js >= 18.0.0:"
echo " - macOS: brew install node"
echo " - Ubuntu/Debian: sudo apt install nodejs npm"
echo " - Other: https://nodejs.org/"
exit 1
fi
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
echo ""
echo "Please install Node.js >= 18.0.0:"
echo " - macOS: brew install node"
echo " - Ubuntu/Debian: sudo apt install nodejs npm"
echo " - Other: https://nodejs.org/"
exit 1
fi
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
echo ""
echo "Please install Node.js >= 18.0.0:"
echo " - macOS: brew install node"
echo " - Ubuntu/Debian: sudo apt install nodejs npm"
echo " - Other: https://nodejs.org/"
exit 1
fi
Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.
echo " sudo npm install -g @mermaid-js/mermaid-cli"
echo ""
echo " 3. Fix npm permissions (recommended):"
echo " mkdir -p ~/.npm-global"
echo " npm config set prefix ~/.npm-global"
echo " echo 'export PATH=~/.npm-global/bin:\$PATH' >> ~/.bashrc"
echo " source ~/.bashrc"
The script builds a shell command by interpolating the user-controlled diagram path directly into execSync. Because args.dir influences mmdPath, a specially crafted directory or filename containing shell metacharacters could trigger command injection when the validator re-renders diagrams. In this skill context, the validator is meant to process generated diagram files, so it is plausible it may be run on untrusted or externally sourced paths, increasing practical risk.
In the subagent usage example and description, the skill is told to read a chapter and save generated outputs to diagrams/chapter-01/, which is a file-system modifying action. The README describes the behavior but does not include any explicit warning or user-facing caution about creating or overwriting files in the destination directory.
Dependencies lack version pinning, allowing potential malicious package updates. Consider pinning versions.
},
"dependencies": {},
"peerDependencies": {
"@mermaid-js/mermaid-cli": "^11.0.0"
},
"engines": {
"node": ">=18.0.0"
Detected: suspicious.dangerous_exec