T07 · Tool Hijacking and Spoofing
- Location
scripts/smyx_crop_specific_disease_analysis.py:2- Finding
Shared Temporary Directory Precedence Enables Python Import Hijacking
- Content
View full analysis
Vulnerability Details
File Location:
scripts/smyx_crop_specific_disease_analysis.py, lines 2–20
Vulnerability Type: Python module search-path hijacking
Risk Level: HighVulnerable Code
python import sys import os current_dir = os.path.dirname(os.path.abspath(__file__)) parent_dir = os.path.dirname(os.path.dirname(os.path.dirname(current_dir))) sys.path.insert(0, parent_dir) import argparse import json import mimetypes import traceback from datetime import datetime import requests import sys import os from .config import * from .skill import skill from skills.smyx_common.scripts.util import RequestUtil, OpenIdUtilTechnical Analysis
The entry point calculates a directory three levels above
scripts/smyx_crop_specific_disease_analysis.pyand inserts it at the beginning ofsys.path.In the audited installation layout, the entry point is located at:
text /tmp/clawhub-codex-scan-v57c67drb9prnrz2q1cfgtp4s58g8afa-TIpVpc/artifact/scripts/smyx_crop_specific_disease_analysis.pyThe three parent traversals resolve as follows:
.../artifact/scripts→.../artifact.../artifact→.../clawhub-codex-scan-v57c67drb9prnrz2q1cfgtp4s58g8afa-TIpVpc.../clawhub-codex-scan-v57c67drb9prnrz2q1cfgtp4s58g8afa-TIpVpc→/tmp
Consequently,
/tmpis placed at index zero of Python’s module search path. The entry point subsequently performs absolute imports from theskillspackage:python from skills.smyx_common.scripts.util import RequestUtil, OpenIdUtilA separate local user who can create
/tmp/skillscan therefore provide a counterfeitskillspackage. Python may resolve the absolute import from that shared temporary location before reaching the legitimate project package. Module-level code in the counterfeit package executes immediately during import with the privileges of the user or Agent invoking the Skill.This is an exploitable coding defect; the reviewed evidence does not establish that the ...[truncated 1860 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove the
sys.pathmodification. Package and install the project normally, then rely on package-relative imports. -
Use relative imports for project-owned modules where appropriate, rather than resolving the top-level
skillspackage through a dynamically modified search path. -
If path initialization is unavoidable, derive the canonical project root precisely. For example, resolve the directory that actually contains the trusted
skillspackage rather than traversing a fixed number of parents:python from pathlib import Path project_root = Path(__file__).resolve().parents[1] -
Do not add shared writable directories such as
/tmptosys.path, especially not at index zero. -
Validate the resolved import root before modifying the search path:
- Canonicalize it with
Path.resolve(). - Confirm that the expected project marker files and package directories exist.
- Reject roots that are shared temporary directories.
- Verify that the path is owned by and not writable by unauthorized users.
- Canonicalize it with
-
Run the Skill from a protected installation directory with permissions preventing modification by unrelated local users.
-
Add a regression test that imports the entry point from representative installation paths and asserts that:
python skills.smyx_common.scripts.util.__file__resolves beneath the trusted project or installed package directory, never beneath
/tmpor another shared writable location.
-
