T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/gen_visuals.sh:72
- Finding
- Arbitrary Python Code Execution Through Visual Generation Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/gen_visuals.sh:72-101`, with additional unsafe interpolation at `scripts/gen_visuals.sh:143-160`, `170-181`, and `476-533` **Vulnerability Type**: Command/code injection through dynamically constructed Python source **Risk Level**: High ### Vulnerable Code ```bash get_image_cost() { local provider="$1" quality="$2" size="$3" case "$provider" in openai) # Token-based calculation for OpenAI models # Output tokens by quality: low=272, medium=1056, high=4160 # Size multiplier: 1024x1024=1x, 1536x1024/1024x1536=1.5x python3 -c " model = '$IMAGE_MODEL' quality = '$quality' size = '$size' # Image output token rates (per 1M tokens) rates = { 'gpt-image-1': {'text_in': 5.00, 'img_out': 40.00}, 'gpt-image-1-mini': {'text_in': 2.00, 'img_out': 8.00}, } # Output tokens by quality (measured empirically for 1024x1024) output_tokens = {'low': 272, 'medium': 1056, 'high': 4160} # Size multiplier for output tokens size_mult = 1.5 if size != '1024x1024' else 1.0 r = rates.get(model, rates['gpt-image-1-mini']) text_tokens = 80 # typical prompt, negligible img_tokens = int(output_tokens.get(quality, 1056) * size_mult) cost = (text_tokens * r['text_in'] + img_tokens * r['img_out']) / 1_000_000 print(f'{cost:.6f}') " ;; ``` Another affected block writes attacker-controlled values into Python source: ```bash if [[ "$DRY_RUN" = true ]]; then # Write estimate to JSON python3 -c " import json est = { 'mode': '$MODE', 'num_images': $NUM_IMAGES, 'num_videos': $NUM_VIDEOS, 'image_provider': '$IMAGE_PROVIDER', 'image_model': '$IMAGE_MODEL', 'video_provider': '$VIDEO_PROVIDER', 'image_quality': '$IMAGE_QUALITY', 'image_size': '$IMAGE_SIZE', 'image_cost_each': $IMG_COST, 'video_cost_each': $VID_COST, 'total_image_cost': $TOTAL_IMG, 'total_video_cost': $TOTAL_VID, 'total_cost': $TOTAL, 'pricing_method': 'token-based' } with open('$OUTDIR/co ...[truncated 2257 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Never interpolate command-line data into a `python3 -c` program. 2. Pass values as positional arguments and read them through `sys.argv`, for example: ```bash python3 - "$IMAGE_MODEL" "$quality" "$size" <<'PY' import sys model, quality, size = sys.argv[1:4] # Process values strictly as data. PY ``` 3. Pass complex request data through JSON files, stdin, or environment variables rather than embedding it in Python syntax. 4. Enforce explicit allowlists before any processing: - Models: `gpt-image-1`, `gpt-image-1-mini` - Modes: `slideshow`, `video`, `hybrid` - Image providers: `openai`, `seedream`, `google-together` - Quality: `low`, `medium`, `high` - Sizes: the documented supported dimensions - Video providers: the documented provider identifiers 5. Supply output paths through `sys.argv` and use `pathlib.Path`; do not place paths inside Python literals. 6. Apply the same correction to every `python3 -c` block at lines `143-160`, `170-181`, and `476-533`. 7. Add regression tests containing single quotes, triple quotes, backslashes, newlines, semicolons, and Python-like payload text. Verify that these values are rejected or treated only as inert data. ]]>
