T08 · Insecure Dependencies
- Location
- scripts/run.py:247
- Finding
- Untrusted External Python Module Execution During Preprocessing Fallback<![CDATA[ ## Vulnerability Details **File Location**: `scripts/run.py:247-253` **Vulnerability Type**: Unsafe dynamic loading of an external dependency **Risk Level**: High ### Vulnerable Code ```python _shared_dir = Path(__file__).resolve().parent.parents[3] / "_shared" / "doc-preprocess" / "scripts" if not _shared_dir.exists(): print(f"ERROR: 无法读取输入文件,本地预处理失败且 _shared/doc-preprocess 不可用。原因:{exc}", file=sys.stderr) return 1 import importlib.util as _iu _spec = _iu.spec_from_file_location("_shared_preprocess", _shared_dir / "preprocess.py") _sp = _iu.module_from_spec(_spec) _spec.loader.exec_module(_sp) ``` ### Technical Analysis When local preprocessing raises `PreprocessError`, the application dynamically loads and executes `_shared/doc-preprocess/scripts/preprocess.py`, which is outside the audited skill directory. Calling `exec_module()` executes all top-level statements in the selected Python file with the privileges and environment of the current skill process. The application does not verify the module's cryptographic digest, signature, owner, permissions, or expected package identity before execution. Consequently, the security of this skill depends on an external mutable file that is not included in the reviewed artifact. An attacker who can create or modify that file can convert a normal preprocessing failure into arbitrary Python code execution. ### Attack Path 1. The attacker obtains write access to the expected `_shared/doc-preprocess/scripts/` directory or its `preprocess.py` file. 2. The attacker inserts malicious top-level Python code into `preprocess.py`. 3. The attacker or a user supplies an input that causes the local preprocessor to raise `PreprocessError`, such as an input requiring unavailable parsing support. 4. The exception handler reaches the fallback logic. 5. `spec_from_file_location()` selects the attacker-controlled file. 6. `exec_module()` executes its top-level code. 7. The malicious code runs with the same opera ...[truncated 574 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the dynamic external-file fallback and package the required preprocessing implementation inside the audited skill or as a pinned, trusted dependency. 2. Import dependencies through the normal Python package mechanism from a controlled environment rather than by filesystem path. 3. If external loading is unavoidable: - Verify the file against a pinned cryptographic digest or trusted digital signature. - Resolve the path and confirm that it remains within an approved directory. - Verify that the file and all parent directories are owned by a trusted account. - Reject files or directories writable by untrusted users or groups. 4. Run document preprocessing in a sandbox with minimal filesystem, environment, and network access. 5. Fail closed when dependency integrity cannot be established. 6. Record the exact trusted dependency version and integrity value in deployment configuration. ]]>
