T09 · Insecure Skill Coding Practices
- Location
scripts/multi-lang-subtitles.sh:85- Finding
Arbitrary Python Code Execution Through the Target Language Argument
- Content
View full analysis
00:00:05,000 {text} 2 00:00:05,000 --> 00:00:10,000 [Translation needed] 3 00:00:10,000 --> 00:00:15,000 [Translation needed] """ with open('/tmp/translated-subtitles.srt', 'w', encoding='utf-8') as f: f.write(srt_content) print(f"✅ {target_lang} 字幕已生成:/tmp/translated-subtitles.srt") PYTHON_SCRIPT ``` ### Technical Analysis The heredoc delimiter is unquoted, so the shell performs parameter expansion before passing the generated source code to Python. The attacker-controlled `TARGET_LANG` argument is inserted directly into two Python string literals without escaping: ```python target_lang = "$TARGET_LANG" text = translations.get('$TARGET_LANG', ...) ``` An input containing matching quotation marks, Python statements, and a comment marker can terminate the intended string and introduce executable Python code. This is not merely malformed-data injection: the supplied content is parsed by the Python interpreter as source code. The script does not validate `TARGET_LANG` against the documented language set of `en`, `ja`, `ko`, `fr`, `de`, and `es`. ### Attack Path 1. An attacker causes a user, automation workflow, or Agent to invo ...[truncated 1299 chars]- Remediation
View remediation
&2 exit 1 ;; esac python3 - "$TARGET_LANG" <<'PYTHON_SCRIPT' import sys target_lang = sys.argv[1] translations = { "en": "Welcome to this video", "ja": "このビデオへようこそ", "ko": "이 비디오에 오신 것을 환영합니다", "fr": "Bienvenue dans cette vidéo", "de": "Willkommen zu diesem Video", "es": "Bienvenido a este video", } text = translations[target_lang] # Continue generating the subtitle using target_lang as data. PYTHON_SCRIPT ``` Apply the same design rule wherever shell variables are passed to Python, JavaScript, AppleScript, or another interpreter: pass values through arguments, standard input, or a safely serialized data format rather than generating source code. ]]>
