T09 · Insecure Skill Coding Practices
Error
- Location
memory-guard.sh:127- Finding
Arbitrary Python Code Execution Through Untrusted Integrity Registry Keys
- Content
View full analysis
/dev/null) [ "$stored_hash" = "UNTRACKED" ] && continue checked=$((checked + 1)) local current_hash current_hash=$(hash_file "$fname") local is_critical is_critical=$(python3 -c " import json d = json.load(open('$HASH_FILE')) print(d.get('$fname', {}).get('critical', False)) " 2>/dev/null) ``` The value assigned to `fname` comes directly from keys in the JSON registry: ```bash done < <(python3 -c " import json for k in json.load(open('$HASH_FILE')): print(k) " 2>/dev/null) ``` ### Technical Analysis The `verify` command reads property names from `.memory-guard/hashes.json` and assigns each property name to the shell variable `fname`. It then embeds that value directly inside Python source passed to `python3 -c`: ```python print(d.get('$fname', {}).get('hash', 'UNTRACKED')) ``` No quoting, escaping, or structural validation is performed before interpolation. A malicious JSON property name containing quote characters, line breaks, and Python statements can terminate the intended Python string literal and introduce attacker-controlled Python code. This is source-code injection rather than ordinary argument injection: the untrusted value is inserted into the program text itself. Shell quoting around the multiline `python3 -c` argument does not protect the Python interpreter from malicious Python syntax embedded through variable expansion. The configured registry path, `HASH_FILE`, is also interpolated into Python source in the same code blocks. Because it is derived from the externally config ...[truncated 2042 chars]- Remediation
View remediation
