T08 · Insecure Dependencies
Warning
- Location
- scripts/chord_identifier.py:267
- Finding
- Execution of an Unverified External Cargo Project## Vulnerability Details **File Location**: `scripts/chord_identifier.py:267-288` **Vulnerability Type**: Untrusted external dependency execution **Risk Level**: Medium ### Complete Code Snippet ```python def get_ascii_chord(chord_name): """调用 ascii_chord 获取和弦图""" import os # 转换和弦名格式 chord_name = chord_name.replace('bb', '#') try: home = os.path.expanduser('~') cwd = os.path.join(home, 'workspace', 'ascii_chord') result = subprocess.run( ['cargo', 'run', '--', 'get', chord_name], cwd=cwd, capture_output=True, text=True, timeout=10 ) if result.returncode == 0: return result.stdout else: return None except Exception as e: return None ``` ### Technical Analysis When diagram rendering is requested, the Skill executes `cargo run` inside `~/workspace/ascii_chord`. This project is outside the audited Skill package and is not pinned, authenticated, or checked for integrity before execution. Running a Cargo project may execute its compiled binary, build scripts such as `build.rs`, procedural macros, and code from resolved dependencies. Consequently, possession or modification of the expected directory provides a code-execution path. The subprocess uses an argument list rather than `shell=True`, so the user-provided chord name does not directly create a shell-command injection vulnerability. The issue is instead the unconditional trust placed in a mutable, unaudited external project and its dependency graph. The ten-second timeout limits waiting time but does not prevent code execution or reverse actions already performed. ### Attack Path 1. An attacker creates or modifies `~/workspace/ascii_chord`, its Cargo configuration, source files, build script, or resolved dependencies. 2. The user or Agent invokes a diagram-related operation, such as a chord lookup with `--diagram` or an inversion with dia ...[truncated 940 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the runtime dependency on a mutable project under the user's home directory. Implement diagram generation directly in the audited package where feasible. 2. If the Rust component is required, include its reviewed source in the Skill package and invoke a fixed, packaged artifact rather than using `cargo run`. 3. Pin all Rust dependencies with a committed `Cargo.lock`, review build scripts and procedural macros, and verify the packaged component using a trusted cryptographic digest. 4. Resolve and validate the component's canonical path before execution. Reject symbolic links and paths outside an explicitly approved installation directory. 5. Build the component during a trusted installation phase and run only the verified binary at runtime; do not permit runtime dependency resolution or compilation. 6. Execute the helper with a minimal environment and least privileges, restrict filesystem and network access through sandboxing, and retain the existing argument-array invocation. 7. Require explicit user consent before invoking an external executable and report failures clearly rather than silently suppressing every exception.
