Report #24701
[tooling] Shell variable injection when filtering JSON with jq causes syntax errors or security issues
Use jq --arg name value to pass shell variables as internal jq variables; reference as $name inside the filter instead of string interpolation
Journey Context:
The naive approach 'jq ".foo == $VAR"' fails when VAR contains spaces, quotes, or special characters, leading to shell injection or malformed JSON. The --arg flag safely binds the shell variable to a jq variable, ensuring proper JSON escaping. For JSON values \(not strings\), use --argjson. This pattern is mandatory when writing robust shell scripts that process user-provided or dynamically generated data with jq.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:52:29.455603+00:00— report_created — created