T09 · Insecure Skill Coding Practices
- Location
SKILL.md:182- Finding
Unsafe JSON Construction Through Direct Variable Interpolation
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 182-190
Vulnerability Type: Improper encoding of dynamic values in a JSON request
Risk Level: MediumVulnerable Code
bash curl -sS "https://openspeech.bytedance.com/api/v1/tts" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer;${VOLC_TOKEN}" \ -d "{ \"app\": {\"appid\": \"${VOLC_APPID}\", \"token\": \"${VOLC_TOKEN}\", \"cluster\": \"volcano_tts\"}, \"user\": {\"uid\": \"podcast-maker\"}, \"audio\": {\"voice_type\": \"${VOICE_TYPE}\", \"encoding\": \"wav\", \"speed_ratio\": ${SPEED_RATIO}, \"emotion\": \"${EMOTION}\"}, \"request\": {\"reqid\": \"${REQID}\", \"text\": \"${TEXT}\", \"text_type\": \"plain\", \"operation\": \"query\"} }" > "${OUT_JSON}"Technical Analysis
The request body is assembled by directly interpolating credentials, generated content, and other dynamic values into a quoted JSON document. These values are not serialized or escaped by a JSON-aware implementation.
If
${TEXT}or another string value contains a quotation mark, backslash, newline, control character, or deliberately crafted JSON syntax, it can terminate the intended string value and alter adjacent properties or make the request invalid.${SPEED_RATIO}is inserted as an unquoted JSON fragment, increasing the risk of structural manipulation if it is not strictly validated as a numeric value.Ordinary shell parameter expansion does not recursively execute shell metacharacters contained in these variables. Therefore, the available evidence does not establish shell command injection. The confirmed issue is JSON injection and request-integrity failure against the declared ByteDance TTS endpoint.
Attack Path
- An attacker controls or influences the web page supplied as the podcast source.
- Crafted content from that page is incorporated into a generated podcast line.
- The line is assigned to
${TEXT}w ...[truncated 1061 chars]
- Remediation
View remediation
Remediation Suggestions
- Build the request with a JSON-aware serializer such as Python's
json.dumpsrather than shell string interpolation. - Pass dynamic values to the serializer through positional arguments or environment variables, and let the serializer escape all strings.
- Enforce an allowlist for
VOICE_TYPEandEMOTION. - Parse
SPEED_RATIOas a number and reject values outside the documented0.90-1.05range. - Validate
REQIDagainst a restrictive identifier format. - Check the HTTP status and validate the response schema before decoding audio data.
- Avoid including the token in the JSON body if the API supports authorization exclusively through the header; otherwise retain it only as required by the provider.
- A hardened construction pattern is:
bash python3 - "$OUT_JSON" <<'PY' import json import os import sys voice_types = { "zh_female_qingxinnvsheng_uranus_bigtts", "zh_male_taocheng_uranus_bigtts", } emotions = {"neutral", "happy", "sad", "serious", "excited"} voice_type = os.environ["VOICE_TYPE"] emotion = os.environ["EMOTION"] speed_ratio = float(os.environ["SPEED_RATIO"]) if voice_type not in voice_types: raise SystemExit("Invalid voice type") if emotion not in emotions: emotion = "neutral" if not 0.90 <= speed_ratio <= 1.05: raise SystemExit("Invalid speed ratio") payload = { "app": { "appid": os.environ["VOLC_APPID"], "token": os.environ["VOLC_TOKEN"], "cluster": "volcano_tts", }, "user": {"uid": "podcast-maker"}, "audio": { "voice_type": voice_type, "encoding": "wav", "speed_ratio": speed_ratio, "emotion": emotion, }, "request": { "reqid": os.environ["REQID"], "text": os.environ["TEXT"], "text_type": "plain", "operation": "query", }, } with open(sys.argv[1], "w", encoding="utf-8") as outpu ...[truncated 271 chars]- Build the request with a JSON-aware serializer such as Python's
