Skip to content

"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/

Python

security: add codec allowlist validation in melt backends

ZJZAC8935f478c5cc
diff --git a/.gitignore b/.gitignore
index cfc7c36d6..adc3ea10d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@
!.gitignore
!/README.md
!/CONTRIBUTING.md
+!/SECURITY.md
!/assets/
!/.claude-plugin/
!/.github/
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 000000000..0e372fc28
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,45 @@
+# Security Policy
+
+## Threat Model
+
+CLI-Anything bridges AI agents and real desktop software. Unlike traditional
+CLIs where a human reviews every command, **an AI agent may autonomously
+construct and execute commands** based on untrusted input (user prompts,
+uploaded files, or other agents' output). This makes input validation
+critical — a prompt-injected agent could pass crafted arguments to software
+backends (melt, GIMP Script-Fu, LibreOffice, etc.).
+
+Key attack surfaces:
+
+| Surface | Risk | Mitigation |
+|---------|------|------------|
+| Subprocess arguments | Malicious codec names, paths, or filter params passed to melt/ffmpeg/gimp | Allowlist validation before subprocess calls |
+| Script-Fu injection | User-controlled strings embedded in GIMP batch scripts | `_script_fu_escape()` in gimp_backend.py |
+| XML/SVG content | User text injected into MLT XML, SVG, or Draw.io files | `xml_escape()` / ElementTree auto-escaping |
+| File path traversal | Agent-controlled output paths writing to arbitrary locations | `os.path.abspath()` normalization |
+| Credential exposure | API keys stored in plaintext config files | File permissions set to `0o600` |
+
+## Reporting a Vulnerability
+
+If you discover a security vulnerability, please report it responsibly:
+
+1. **Do NOT open a public GitHub issue.**
+2. Email the maintainers or use GitHub's private vulnerability reporting:
+ **Security** tab > **Report a vulnerability**.
+3. Include: affected file(s), reproduction steps, and potential impact.
+4. We aim to acknowledge reports within 48 hours and release a fix within
+ 7 days for critical issues.
+
+## Security Guidelines for Harness Developers
+
+When building a new CLI harness, follow these rules:
+
+1. **Never use `shell=True`** in `subprocess.run()` — always pass arguments
+ as a list.
+2. **Validate all subprocess arguments** against an allowlist. Do not pass
+ user-controlled strings directly to external tools.
+3. **Escape user content** before embedding it in scripts (Script-Fu, Python,
+ Lua) or structured formats (XML, SVG, HTML).
+4. **Use `os.path.abspath()`** on all file paths and consider resolving
+ symlinks with `os.path.realpath()` for sensitive write operations.
+5. **Never log or echo API keys** in error messages or JSON output.
diff --git a/kdenlive/agent-harness/cli_anything/kdenlive/utils/melt_backend.py b/kdenlive/agent-harness/cli_anything/kdenlive/utils/melt_backend.py
index 6717bb707..a1709f79a 100644
--- a/kdenlive/agent-harness/cli_anything/kdenlive/utils/melt_backend.py
+++ b/kdenlive/agent-harness/cli_anything/kdenlive/utils/melt_backend.py
@@ -14,6 +14,40 @@ import tempfile
from typing import Optional
+# Allowlisted codecs for melt/ffmpeg rendering.
+# An AI agent controls the codec parameters — accepting arbitrary strings
+# could let a compromised or prompt-injected agent pass crafted values to
+# the melt subprocess. Only codecs known to produce valid output are
+# permitted; callers can extend ALLOWED_VCODECS / ALLOWED_ACODECS if needed.
+ALLOWED_VCODECS = frozenset({
+ "libx264", "libx265", "libvpx", "libvpx-vp9",
+ "mpeg4", "mpeg2video", "mjpeg", "huffyuv", "ffv1",
+ "prores", "prores_ks", "dnxhd",
+ "png", "gif", "rawvideo",
+ "libaom-av1", "libsvtav1",
+ "h264_nvenc", "hevc_nvenc", "h264_vaapi", "hevc_vaapi",
+})
+
+ALLOWED_ACODECS = frozenset({
+ "aac", "libmp3lame", "libvorbis", "libopus",
+ "pcm_s16le", "pcm_s24le", "pcm_s32le", "pcm_f32le",
+ "flac", "alac", "ac3", "eac3",
+ "wmav2",
+})
+
+
+def _validate_codec(value: str, allowed: frozenset, label: str) -> str:
+ """Validate that a codec name is in the allowlist."""
+ if not value:
+ return value
+ if value not in allowed:
+ raise ValueError(
+ f"Unsupported {label}: '{value}'. "
+ f"Allowed values: {sorted(allowed)}"
+ )
+ return value
+
+
def find_melt() -> str:
"""Find the melt executable. Raises RuntimeError if not found."""
path = shutil.which("melt")
@@ -68,6 +102,9 @@ def render_mlt(
Returns:
Dict with output path, file size, method
"""
+ _validate_codec(vcodec, ALLOWED_VCODECS, "video codec")
+ _validate_codec(acodec, ALLOWED_ACODECS, "audio codec")
+
if not os.path.exists(mlt_path):
raise FileNotFoundError(f"MLT file not found: {mlt_path}")
@@ -129,6 +166,9 @@ def render_color_bars(
This doesn't require any input files — perfect for E2E testing.
"""
+ _validate_codec(vcodec, ALLOWED_VCODECS, "video codec")
+ _validate_codec(acodec, ALLOWED_ACODECS, "audio codec")
+
if os.path.exists(output_path) and not overwrite:
raise FileExistsError(f"Output file exists: {output_path}")
diff --git a/shotcut/agent-harness/cli_anything/shotcut/utils/melt_backend.py b/shotcut/agent-harness/cli_anything/shotcut/utils/melt_backend.py
index 6717bb707..56366fcac 100644
--- a/shotcut/agent-harness/cli_anything/shotcut/utils/melt_backend.py
+++ b/shotcut/agent-harness/cli_anything/shotcut/utils/melt_backend.py
@@ -14,6 +14,35 @@ import tempfile
from typing import Optional
+ALLOWED_VCODECS = frozenset({
+ "libx264", "libx265", "libvpx", "libvpx-vp9",
+ "mpeg4", "mpeg2video", "mjpeg", "huffyuv", "ffv1",
+ "prores", "prores_ks", "dnxhd",
+ "png", "gif", "rawvideo",
+ "libaom-av1", "libsvtav1",
+ "h264_nvenc", "hevc_nvenc", "h264_vaapi", "hevc_vaapi",
+})
+
+ALLOWED_ACODECS = frozenset({
+ "aac", "libmp3lame", "libvorbis", "libopus",
+ "pcm_s16le", "pcm_s24le", "pcm_s32le", "pcm_f32le",
+ "flac", "alac", "ac3", "eac3",
+ "wmav2",
+})
+
+
+def _validate_codec(value: str, allowed: frozenset, label: str) -> str:
+ """Validate that a codec name is in the allowlist."""
+ if not value:
+ return value
+ if value not in allowed:
+ raise ValueError(
+ f"Unsupported {label}: '{value}'. "
+ f"Allowed values: {sorted(allowed)}"
+ )
+ return value
+
+
def find_melt() -> str:
"""Find the melt executable. Raises RuntimeError if not found."""
path = shutil.which("melt")
@@ -68,6 +97,9 @@ def render_mlt(
Returns:
Dict with output path, file size, method
"""
+ _validate_codec(vcodec, ALLOWED_VCODECS, "video codec")
+ _validate_codec(acodec, ALLOWED_ACODECS, "audio codec")
+
if not os.path.exists(mlt_path):
raise FileNotFoundError(f"MLT file not found: {mlt_path}")
@@ -129,6 +161,9 @@ def render_color_bars(
This doesn't require any input files — perfect for E2E testing.
"""
+ _validate_codec(vcodec, ALLOWED_VCODECS, "video codec")
+ _validate_codec(acodec, ALLOWED_ACODECS, "audio codec")
+
if os.path.exists(output_path) and not overwrite:
raise FileExistsError(f"Output file exists: {output_path}")