T07 · Tool Hijacking and Spoofing
- Location
__init__.py:9- Finding
Unreviewed Parent-Level Modules Can Hijack Skill Imports
- Content
View full analysis
Vulnerability Details
File Location:
__init__.py:9-14;tools/__init__.py:8-12
Vulnerability Type: Python import-path manipulation and tool implementation spoofing
Risk Level: MediumVulnerable Code
__init__.py:9-14:python # DataVault - 使用相对导入定位核心 app # DataVault/skill/__init__.py -> DataVault/app/ sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from app.data import get_data_service from app.onchain.service import OnChainService from app.external.defillama import get_defillama_clienttools/__init__.py:8-12:python # DataVault - 使用相对导入 # DataVault/skill/tools/__init__.py -> DataVault/ sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent)) from skill import get_skill, call_tool, get_all_toolsTechnical Analysis
The Skill prepends directories outside its package boundary to Python's global module search path. Entries inserted at index zero take precedence over normal installed-package locations.
The
appimplementation imported by__init__.pyis absent from the audited artifact. The local package therefore does not contain the implementations behind its advertised market-data, on-chain, and DeFi tools. Its effective behavior is determined by whichever matchingappmodules are present in the parent directory at runtime.The tools adapter similarly imports the generic top-level module name
skillafter placing another parent directory first in the search path. This can resolve to code other than the reviewed package when the runtime directory structure differs from the expected repository layout.Because Python executes module-level code during imports, resolving either import to attacker-controlled code results in immediate code execution. This is a conditional local hijacking vulnerability: exploitation requires an attacker or another compromised component to control a matching module in one of the inserted directories.
...[truncated 1781 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove both
sys.path.insert(...)calls. -
Package all required implementation modules inside the distributed Skill artifact.
-
Use explicit package-relative imports, for example:
python from .app.data import get_data_service from .app.onchain.service import OnChainService from .app.external.defillama import get_defillama_client -
In
tools/__init__.py, use a relative import tied to the reviewed package rather than the generic top-level nameskill. -
Define a proper Python package and installation manifest so imports do not depend on the current working directory or repository layout.
-
Fail closed with a clear error when packaged implementation modules are unavailable.
-
Add tests that install the built artifact into an isolated environment and verify the resolved module paths using each module's
__file__. -
Avoid all process-wide import-path changes in library initialization code.
-
