T09 · Insecure Skill Coding Practices
- Location
- scripts/doubao.sh:90
- Finding
- Unescaped User Input Allows JSON Request-Body Injection<![CDATA[ ## Vulnerability Details **File Location**: `scripts/doubao.sh:90-98`, `scripts/doubao.sh:140-149`, and `scripts/doubao.sh:196-225` **Vulnerability Type**: Improper encoding of user-controlled data in JSON request bodies **Risk Level**: Medium ### Vulnerable Code ```bash # Image generation local payload=$(cat <<EOF { "model": "doubao-seedream-3-0-t2i-250415", "prompt": "${prompt}", "n": 1 } EOF ) ``` ```bash # Image editing local payload=$(cat <<EOF { "model": "doubao-seedream-4-0-250828", "image": "${image_url}", "prompt": "${prompt}", "n": 1, "strength": 0.3 } EOF ) ``` ```bash # Video generation with a reference image payload=$(cat <<EOF { "model": "doubao-seedance-1-0-pro-fast-251015", "content": [ {"type": "text", "text": "${prompt}"}, {"type": "image_url", "image_url": {"url": "${image_url}"}} ], "resolution": "720p", "ratio":"16:9", "duration": 5, "seed": 11, "camera_fixed": false, "watermark": true } EOF ) ``` ### Technical Analysis The script interpolates the user-controlled `prompt` and `image_url` values directly into JSON heredocs without applying JSON string encoding. Characters such as double quotes, backslashes, newlines, and control characters can terminate or alter the intended JSON string. For example, a prompt containing a value structurally similar to: ```text test", "n": 10, "extra": " ``` would modify the generated request body rather than remaining a single prompt string. Depending on the remote API's handling of duplicate or unexpected properties, this may cause request rejection or manipulation of accepted request parameters. This is request-body injection rather than shell-command injection. The input remains inside a shell variable and is passed to `curl` as a quoted argument, so the reviewed code does not establish arbitrary local command execution through this flaw. ### Attack Path 1. An attacker supplies a crafted prompt or image URL through an application or agent th ...[truncated 1009 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Construct every request body with a JSON-aware encoder such as `jq`, rather than textual interpolation: ```bash payload="$(jq -n \ --arg model "doubao-seedream-3-0-t2i-250415" \ --arg prompt "$prompt" \ '{model: $model, prompt: $prompt, n: 1}')" ``` For image-editing requests: ```bash payload="$(jq -n \ --arg model "doubao-seedream-4-0-250828" \ --arg image "$image_url" \ --arg prompt "$prompt" \ '{ model: $model, image: $image, prompt: $prompt, n: 1, strength: 0.3 }')" ``` Apply the same approach to both video payload variants. Additionally: 1. Validate `image_url` with a strict URL parser or allow only expected `https://` URLs. 2. Reject control characters where they are not operationally required. 3. Validate `sync_mode` against an explicit `sync|async` allowlist. 4. Enforce reasonable input-length limits. 5. Add tests containing quotes, backslashes, Unicode, and line breaks to verify that input remains a single JSON string. 6. Validate the generated payload with `jq -e .` before sending it. ]]>
