T09 · Insecure Skill Coding Practices
- Location
brain_enhance.py:10- Finding
Untrusted Python Module Loading from a Shared Absolute Path
- Content
View full analysis
Vulnerability Details
File Location:
brain_enhance.py:10-16
Vulnerability Type: Unsafe Python import-path manipulation and out-of-package code execution
Risk Level: Highpython brain_path = Path("/data/.openclaw/workspace/company-brain") if str(brain_path) not in sys.path: sys.path.insert(0, str(brain_path)) try: from brain_wrapper import Brain _brain = Brain() except Exception: _brain = NoneTechnical Analysis
The module prepends
/data/.openclaw/workspace/company-braintosys.pathand then importsbrain_wrapperfrom that externally managed location. Python executes module-level code during import, so importingbrain_enhance.pycan execute arbitrary code supplied throughbrain_wrapper.py.The imported implementation is outside the reviewed Skill package and can change independently of it. If the directory or module is writable by another user, process, workspace component, or compromised service, the import creates a code-execution boundary that is not protected by package pinning, integrity verification, or provenance validation.
Instantiating
Brain()immediately at module scope increases exposure because execution occurs merely by importingbrain_enhance.py; no explicit feature invocation is required. The broadexcept Exceptionalso suppresses failures, reducing visibility into unexpected or malicious module-loading behavior.This integration is not required for the declared local, line-based scanning functionality and is not used by
scripts/vetter.py, so it exceeds the minimum behavior necessary for the scanner.Attack Path
- An attacker obtains write access to
/data/.openclaw/workspace/company-brain, or compromises a process that can modify files in that directory. - The attacker creates or replaces
/data/.openclaw/workspace/company-brain/brain_wrapper.py. - The malicious module places its payload in module-level ...[truncated 1459 chars]
- An attacker obtains write access to
- Remediation
View remediation
Remediation Suggestions
- Remove
brain_enhance.pyand the external Brain integration if it is not required by the scanner. The main scanner currently operates without it. - Do not prepend shared or workspace directories to
sys.path. - If the integration is required, distribute
brain_wrapperas a normal, reviewed dependency from a trusted source and pin it to an exact version and integrity hash. - Keep dependencies inside a controlled virtual environment or package namespace whose files are not writable by untrusted users or unrelated workspace components.
- Verify dependency provenance and integrity before loading it, using a trusted manifest or cryptographic signature.
- Avoid module-scope initialization. Load and instantiate the optional component only after an explicit, authorized request.
- Restrict ownership and permissions on any directory from which executable Python modules are loaded.
- Replace the blanket exception handler with narrowly scoped exception handling and security-relevant logging so unexpected import behavior is visible.
- If external policy text continues to be consumed, treat it as untrusted data, validate its structure and length, and prevent it from being interpreted as authoritative Agent instructions.
- Remove
