T08 · Insecure Dependencies
- Location
scripts/generate_word.py:17- Finding
Untrusted External Python Module Loading Through Search-Path Precedence
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_word.py, lines 17–25
Vulnerability Type: Untrusted dependency loading / Python module search-path manipulation
Risk Level: HighVulnerable Code
python import sys sys.path.insert(0, r"C:\Users\qu669\.openclaw\workspace-yoyo") sys.stdout.reconfigure(encoding='utf-8') import os, json, datetime, logging, re from docx import Document from docx.shared import Pt, RGBColor, Inches from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn import configTechnical Analysis
The script prepends an external user-workspace directory to
sys.pathand then imports the generically namedconfigmodule. Because index zero has the highest module-resolution priority, Python will loadconfig.pyor a compatibleconfigpackage from that external directory before searching lower-priority locations.A Python import executes the imported module's top-level code. The referenced module is outside the audited project and cannot be integrity-verified from this package. If an attacker can create or replace the external
configmodule, arbitrary Python code will run immediately whengenerate_word.pystarts.This configuration module also supplies sensitive runtime paths such as
LOG_FILE,MARKET_DATA_FILE, andOUTPUT_DIR. Consequently, even without an overt executable payload, a malicious configuration module could redirect data reads, report writes, or logs to attacker-selected filesystem locations.Attack Path
- The attacker obtains write access to
C:\Users\qu669\.openclaw\workspace-yoyo, whether through another compromised process, unsafe directory permissions, or an existing foothold in the same user account. - The attacker creates or modifies
config.pyin that directory. - The malicious module includes attacker-controlled top-level Python code and may expose the attributes expected by the report generator.
- A user or agent invokes `scripts/generate_word. ...[truncated 762 chars]
- The attacker obtains write access to
- Remediation
View remediation
Remediation Suggestions
-
Remove the external search-path insertion and package required configuration with the project:
python # Remove: # sys.path.insert(0, r"C:\Users\qu669\.openclaw\workspace-yoyo") -
Prefer a non-executable configuration format such as JSON or TOML and parse it with a standard parser. Validate every configured path before use.
-
If Python-based configuration is unavoidable, place it inside a uniquely named, trusted project package and use an explicit package-relative import rather than the generic module name
config. -
If external configuration must remain supported:
- Resolve and validate the canonical configuration path.
- Restrict accepted paths to an administrator-controlled directory.
- Verify ownership and permissions before loading.
- Reject writable-by-untrusted-user files and directories.
- Apply an integrity check or trusted signature.
- Avoid executing configuration as Python code.
-
Validate
LOG_FILE,MARKET_DATA_FILE, andOUTPUT_DIRagainst approved base directories to prevent unintended file reads or writes.
-
