T09 · Insecure Skill Coding Practices
- Location
scripts/get_token.sh:23- Finding
Python Code Injection Through Unsafe Configuration Path Interpolation
- Content
View full analysis
&2 APP_ID=$(python3 -c " import json, sys try: c = json.load(open('$CONFIG')) print(c['channels']['lark']['accounts']['default']['appId']) except (KeyError, FileNotFoundError): sys.exit(1) " 2>/dev/null) || true APP_SECRET=$(python3 -c " import json, sys try: c = json.load(open('$CONFIG')) print(c['channels']['lark']['accounts']['default']['appSecret']) except (KeyError, FileNotFoundError): sys.exit(1) " 2>/dev/null) || true fi ``` ### Technical Analysis The value of `OPENCLAW_CONFIG` is assigned to `CONFIG` and then interpolated directly into Python source passed to `python3 -c`. Although the shell variable is surrounded by single quotation marks in the generated Python expression, those quotation marks do not safely encode arbitrary path values. A configuration path containing a single quote and additional Python syntax can terminate the string passed to `open(...)` and inject attacker-controlled Python statements. The `[ -f "$CONFIG" ]` check limits exploitation to a value resolving to an existing file, but it does not make interpolation into executable Python source safe. On filesystems that permit quotation marks and other relevant characters in filenames, an attacker able to create a file and influence `OPENCLAW_CONFIG` can satisfy this condition. The vulnerable branch is reached when the caller does not provide both credentials through command-line arguments or environment variables. ### Attack Path 1. An attacker gains control over, or can influence, the `OPENCLAW_CONFIG` environment variable supplied to the helper. This could occur through a wrappe ...[truncated 1313 chars]- Remediation
View remediation
