T07 · Tool Hijacking and Spoofing
- Location
scripts/handler.py:20- Finding
Execution of an Unbundled and Externally Replaceable Python Script
- Content
View full analysis
Vulnerability Details
File Location:
scripts/handler.py, lines 20-26
Vulnerability Type: Execution of an untrusted local tool outside the audited project
Risk Level: HighVulnerable Code
python BOOKMARK_PY = Path(__file__).parent.parent.parent.parent / "scripts" / "bookmark.py" def run_bookmark(*args): """Run bookmark.py with given args and return (stdout, stderr, rc).""" cmd = [sys.executable, str(BOOKMARK_PY)] + list(args) result = subprocess.run(cmd, capture_output=True, text=True) return result.stdout, result.stderr, result.returncodeTechnical Analysis
The handler constructs the path to
bookmark.pyby traversing four parent directories fromscripts/handler.py. In the supplied project layout, this resolves to/tmp/scripts/bookmark.py, which is outside the audited project directory.The referenced script is not included in the supplied package, despite
SKILL.mddescribing it as part of the Skill. Every bookmark operation invokes this external file using the current Python interpreter. Although arguments are passed as a list and are not directly vulnerable to shell injection, the executable Python source itself is unaudited and externally replaceable.This creates a local tool-hijacking boundary: a file placed at the expected external path is treated as a legitimate project component and executed without path containment, ownership, permission, or integrity validation.
Attack Path
- An attacker obtains the ability to create or replace
/tmp/scripts/bookmark.py, such as through another process operating in the shared temporary directory. - The attacker writes a malicious Python payload to that location.
- A user invokes any supported bookmark operation, such as
/save,/save list, or/save search. handler.pyconstructs a command usingsys.executableand the external script path.- Python executes the attacker-controlled script with t ...[truncated 573 chars]
- An attacker obtains the ability to create or replace
- Remediation
View remediation
Remediation Suggestions
-
Include
bookmark.pywithin the audited Skill package instead of resolving it from an external directory. -
Resolve the bundled script relative to the handler without upward traversal:
python BOOKMARK_PY = Path(__file__).resolve().with_name("bookmark.py") -
Resolve and validate the path before execution, ensuring it remains under the expected package directory.
-
Fail closed if the script is missing, is a symbolic link, has unexpected ownership or permissions, or resolves outside the Skill directory.
-
Where practical, import a trusted internal Python module and call its functions directly rather than spawning a separate interpreter.
-
Protect packaged files from modification and verify their integrity when deployed in environments where local replacement is possible.
-
