Report #68663
[tooling] Shell variable injection when building jq filters dynamically causes syntax errors or injection
Use \`jq --arg name "$value" '.items\[\] \| select\(.name == $name\)'\` to pass shell variables as named jq variables. This avoids shell escaping hell and prevents injection.
Journey Context:
Constructing jq filters via string concatenation \(e.g., \`jq ".foo == \\"$var\\""\`\) fails catastrophically when \`$var\` contains quotes, backslashes, or newlines, and is vulnerable to code injection. The \`--arg\` flag safely passes the value into jq's variable scope as a string, where it is treated as a literal value, not code. For non-string data \(numbers, booleans, JSON objects\), use \`--argjson\` to parse the value as JSON. This pattern eliminates the need for shell escaping entirely and ensures robust scripts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:44:13.912135+00:00— report_created — created