T08 · Insecure Dependencies
Warning
- Location
- scripts/extract_mermaid.py:212
- Finding
- Automatic execution of an unpinned Mermaid CLI package in diagram extraction## Vulnerability Details **File Location**: `scripts/extract_mermaid.py:212-217` **Vulnerability Type**: Unpinned third-party package download and execution **Risk Level**: Medium **Vulnerable code:** ```python @staticmethod def _get_mmdc_cmd() -> Optional[List[str]]: """Find working mmdc command (direct binary or npx fallback).""" import shutil if shutil.which('mmdc'): return ['mmdc'] if shutil.which('npx'): return ['npx', '-y', '@mermaid-js/mermaid-cli'] return None ``` The resulting command is executed during validation: ```python mmdc_cmd = self._get_mmdc_cmd() or ['mmdc'] cmd = mmdc_cmd + ['-i', str(input_file), '-o', str(output_file), '-b', 'transparent'] result = subprocess.run( cmd, capture_output=True, text=True, timeout=30 ) ``` ### Technical Analysis If a trusted, preinstalled `mmdc` binary is unavailable, the script treats the presence of `npx` as sufficient and invokes: ```text npx -y @mermaid-js/mermaid-cli ``` The package version is not pinned, no lockfile or integrity value is enforced, and `-y` suppresses interactive confirmation. Consequently, npm can retrieve and execute a package version and transitive dependency set that changed after the Skill was audited. The use of an argument list rather than a shell command prevents ordinary shell metacharacter injection through file paths. The vulnerability is instead the implicit trust placed in mutable remote package contents. ### Attack Path 1. An attacker compromises the npm package, one of its transitive dependencies, or the relevant package-distribution channel. 2. The attacker publishes malicious code under a version accepted by the unversioned package request. 3. A user invokes `extract_mermaid.py --validate` on a system where `npx` exists but `mmdc` is not installed. 4. The script automatically runs `npx -y @mermaid-js/mermaid-cli`. 5. npm downloads the cu ...[truncated 607 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the automatic `npx -y` fallback. Fail safely when a trusted `mmdc` installation is unavailable. 2. Require explicit user approval before downloading or executing any package. 3. Pin Mermaid CLI to an audited exact version rather than using an unversioned package reference. 4. Install dependencies through a committed lockfile and verify package integrity before execution. 5. Prefer a project-local binary from a controlled dependency installation, such as `node_modules/.bin/mmdc`. 6. Run rendering in a sandbox with restricted filesystem access, minimal environment variables, no unnecessary credentials, and network access disabled after dependency installation. 7. Clearly document whether validation may access the network and provide an offline-only mode.
