T09 · Insecure Skill Coding Practices
- Location
aemet.sh:133- Finding
User-Controlled jq Program Injection in Municipality Lookup
- Content
View full analysis
/dev/null | head -1) if [[ -n "$result" ]]; then echo "$result" | cut -d':' -f1 return fi ``` ### Technical Analysis The user-controlled `query` value is interpolated directly into a jq program enclosed in a shell double-quoted string. The value is therefore treated as jq source code rather than as data. An attacker can include quotation marks, jq operators, and a jq comment marker to terminate the intended `test()` expression and inject a different pipeline. jq provides built-ins such as `env`, which exposes the executing process's environment variables. This is jq expression injection rather than shell command injection: the attacker cannot directly execute arbitrary operating-system commands through jq, but can alter jq processing, read accessible data exposed by jq built-ins, manipulate lookup results, or consume excessive resources. ### Attack Path 1. An attacker supplies a crafted municipality name to the forecast command. 2. `get_municipio_code` stores the attacker-controlled argument in `query`. 3. The script inserts `query` directly into the jq source expression. 4. The crafted value closes the intended regular expression and appends attacker-selected jq filters. 5. The injected jq expression executes with the environment and file access already available to the Skill process. 6. Results can influence municipality selection or expose environment-derived information through command output. For example, a payload using a jq comment marker can terminate the fixed remainder of the expression after inserting another jq pipeline. Exploitation does not require shell metacharacter interpretation because the vulnerabl ...[truncated 639 chars]- Remediation
View remediation
/dev/null | head -1) ``` Additional hardening should include: 1. Restrict municipality-query length to a reasonable maximum. 2. If regular-expression behavior is unnecessary, use a literal case-insensitive comparison instead of `test()`. 3. Handle invalid regular expressions explicitly if regex search remains supported. 4. Run the Skill with a minimal environment so unrelated credentials are not exposed to child processes. 5. Add regression tests containing quotation marks, jq operators, comment markers, and malformed regular expressions. ]]>
