T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/text-to-image.sh:93
- Finding
- Unescaped prompt permits JSON request-body injection in text-to-image workflow<![CDATA[ ## Vulnerability Details **File Location**: `scripts/text-to-image.sh`, lines 93-102 **Vulnerability Type**: Untrusted data embedded into JSON without serialization **Risk Level**: Medium ### Vulnerable Code ```bash # 构建JSON请求体 - 使用 BizyAir GPT_IMAGE_2 T2I API (web_app_id: 52416) JSON_PAYLOAD=$(cat <<EOF { "web_app_id": 52416, "suppress_preview_output": false, "input_values": { "4:BizyAir_GPT_IMAGE_2_T2I_API.prompt": "$PROMPT", "4:BizyAir_GPT_IMAGE_2_T2I_API.aspect_ratio": "$ASPECT_RATIO" } } EOF ) ``` ### Technical Analysis `PROMPT` is populated directly from the first command-line argument and interpolated into a JSON string without JSON escaping. A prompt containing quotation marks, backslashes, control characters, or JSON syntax can terminate the intended string and alter the request structure. This is not shell command injection because the expanded value remains inside the here-document and is later passed as a quoted argument to `curl`. It is, however, JSON injection into the request sent to BizyAir. The exact effect of duplicate or injected fields depends on the remote API's JSON parser and validation rules. ### Attack Path 1. An attacker supplies or persuades the agent to use a crafted image prompt containing JSON delimiters. 2. The script assigns the value to `PROMPT`. 3. The value is interpolated directly into `JSON_PAYLOAD`. 4. The resulting request can contain malformed JSON or attacker-injected fields. 5. `curl` submits the manipulated body using the configured account and API key. ### Impact Assessment An attacker may cause denial of service for the generation request or manipulate API input fields accepted by the remote workflow. Requests execute under the privileges and quota associated with the configured BizyAir API key. This issue does not directly provide local command execution or access to the full API key. ]]>
- Remediation
- <![CDATA[ ## Remediation Suggestions Construct the body using a JSON-aware serializer rather than string interpolation. For example: ```bash JSON_PAYLOAD=$(jq -n \ --arg prompt "$PROMPT" \ --arg ratio "$ASPECT_RATIO" \ '{ web_app_id: 52416, suppress_preview_output: false, input_values: { "4:BizyAir_GPT_IMAGE_2_T2I_API.prompt": $prompt, "4:BizyAir_GPT_IMAGE_2_T2I_API.aspect_ratio": $ratio } }') || exit 1 ``` Also validate that serialization succeeds before submitting the request and reject unexpectedly large prompts to control resource consumption. ]]>
