T07 · Tool Hijacking and Spoofing
- Location
scripts/script_gen.py:14- Finding
External Module Search Path Allows Local Configuration Hijacking
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script_gen.py, lines 14–21
Vulnerability Type: Untrusted Python module search path
Risk Level: Mediumpython HERE = pathlib.Path(__file__).resolve() # _shared/ 定位:优先 bundled(scripts/_shared/),fallback monorepo 根 for _cand in (HERE.parent / "_shared", HERE.parents[2] / "_shared"): if (_cand / "config.py").exists(): sys.path.insert(0, str(_cand)) break from config import DEFAULTS, STYLE_PRESETS, GENRE_PRESETSTechnical Analysis
The script first searches for the bundled
scripts/_shared/config.py, but if that file is absent, it searches an_shareddirectory outside the Skill package and prepends the selected directory tosys.path. It then importsconfigby its unqualified module name.Python executes top-level module code during import. Consequently, an attacker who can place a malicious
config.pyin the fallback directory can cause arbitrary Python code to run whenscript_gen.pystarts. The existence check verifies only the filename and does not validate ownership, permissions, expected content, or whether the resolved file remains within the trusted Skill root.The bundled module normally takes precedence, which limits exploitation to installations where the bundled file is missing, removed, or incompletely packaged. Nevertheless, falling back to a location outside the package violates the trust boundary and permits local tool/module spoofing.
Attack Path
- The Skill is installed or copied without
scripts/_shared/config.py, or that bundled file is removed. - An attacker with write access to the fallback location creates
_shared/config.pyat the path represented byHERE.parents[2] / "_shared". - The malicious file defines the expected names so execution can continue, while placing an arbitrary payload in its top-level code.
- A user or Agent invokes
python scripts/script_gen.py .... - The fallback directory is inserted at the beginning ...[truncated 806 chars]
- The Skill is installed or copied without
- Remediation
View remediation
Remediation Suggestions
- Remove the external fallback and fail closed if the bundled configuration is unavailable.
- Package
_sharedas a proper Python package and use an explicit package-relative import rather than modifyingsys.path. - If development-mode fallback support is essential, require an explicit opt-in setting and resolve the candidate path before use.
- Verify that any fallback path is within a predefined trusted repository root and reject symlinks or path traversal outside that root.
- Check ownership and permissions so untrusted users cannot modify the fallback module.
- Add packaging and startup tests that confirm the bundled configuration is present and that execution fails safely when it is absent.
A preferred structure is:
python try: from scripts._shared.config import DEFAULTS, STYLE_PRESETS, GENRE_PRESETS except ImportError as exc: raise RuntimeError("Bundled Skill configuration is unavailable") from exc
