T09 · Insecure Skill Coding Practices
Warning
- Location
- simple_test.py:4
- Finding
- Arbitrary Python Execution from an Unverified External File<![CDATA[ ## Vulnerability Details **File Location**: `simple_test.py:4-7` **Vulnerability Type**: Execution of unverified external Python source **Risk Level**: Medium ### Vulnerable Code ```python import time # Directly read and execute sim_state.py exec(open('/Users/liuxing/.openclaw/workspace/skills/quadruped/scripts/sim_state.py').read()) ``` ### Technical Analysis The script reads Python source from a hardcoded absolute path outside the audited project and passes the resulting string directly to `exec()`. The external file is not authenticated, integrity-checked, or guaranteed to be the bundled `scripts/sim_state.py` reviewed during this audit. `exec()` runs the file with the privileges and execution context of the current Python process. Consequently, anyone able to create or modify the referenced file can convert a routine test invocation into arbitrary local code execution. The hardcoded developer-specific location also creates module provenance ambiguity: the code executed at runtime can differ from the version distributed in the Skill package. ### Attack Path 1. An attacker obtains write access to `/Users/liuxing/.openclaw/workspace/skills/quadruped/scripts/sim_state.py`, or creates the path in an environment where it does not already exist. 2. The attacker inserts arbitrary Python statements into that file. 3. A user runs `simple_test.py`, believing it executes the simulator included in the audited project. 4. `open()` reads the attacker-controlled source. 5. `exec()` executes that source without validation or isolation. This path requires the attacker to control the referenced local file or its containing directory; no remote retrieval mechanism was identified. ### Impact Assessment Successful exploitation provides arbitrary code execution with the privileges of the user running `simple_test.py`. Within those privileges, malicious code could read or alter accessible files, execute processes, access locally available credentials, or in ...[truncated 150 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove dynamic source execution entirely. 2. Import the bundled simulator through a normal, package-relative import, for example: ```python from scripts.sim_state import QuadrupedSimulator ``` 3. Package `scripts` as a Python package where necessary and use a controlled project root rather than modifying search paths to point to developer-specific directories. 4. Do not use `exec()` to load project modules. 5. If loading external code is an explicit requirement, require a trusted path, verify the file against a pinned cryptographic digest, and execute it in an appropriately isolated process with minimal permissions. 6. Add a test that confirms the imported module resolves inside the installed project directory. ]]>
