Report #30466
[tooling] Shell script injection when passing variables to jq filters
Use \`jq --arg name "$value" '. \+ \{key: $name\}'\` to safely bind shell variables as jq variables, avoiding string concatenation that breaks on quotes or special characters.
Journey Context:
The naive approach—\`jq ".foo = \\"$VAR\\""\`—fails catastrophically when \`$VAR\` contains quotes, backslashes, or newlines, leading to syntax errors or injection vulnerabilities. The \`--arg\` flag passes the value as a jq variable \(\`$name\` in the filter\), automatically handling escaping. For JSON values \(not strings\), use \`--argjson\` to parse the variable as JSON. The \`-n\` \(null input\) flag pairs well here to construct JSON from scratch using only variables. This pattern is essential for robust shell/jq interop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:31:19.939285+00:00— report_created — created