Skip to content

Free, open-source AI video generator for Mac. Run LTX-2.5 and MiniMax H3 (Hailuo) locally on Apple Silicon: text-to-video and image-to-video with sound, lip-sync, character LoRA training, songs from lyrics (YuE2) and image editing (Qwen-Image-Edit). One-click install via Pinokio. Offline: no cloud, no API key, no NVIDIA GPU.

sec: code-review HIGH bugs — path-traversal + library perf

mrbizarro72989f918ca1
diff --git a/agent/tools.py b/agent/tools.py
index a8577c3..53b25cf 100644
--- a/agent/tools.py
+++ b/agent/tools.py
@@ -812,8 +812,14 @@ def _generate_shot_images(args: dict, ops: PanelOps, session: dict) -> dict:
# Reference images for multi-ref engines (Qwen-Image-Edit-2509). Each
# ref is resolved relative to ops.uploads_dir if not absolute, then
- # validated. Engines that don't support refs ignore them; the result
- # dict carries refs_ignored=True in that case.
+ # path-traversal-validated to live under uploads_dir or outputs_dir.
+ # _resolve_path alone joins-but-doesn't-validate — without
+ # _ensure_under a prompt-injected `../../etc/...` could reach the
+ # engine, which would then fail confusingly at PIL-decode time;
+ # rejecting up-front gives a clean validation message and matches
+ # the security stance extract_frame / inspect_clip already use.
+ # Engines that don't support refs ignore them; the result dict
+ # carries refs_ignored=True in that case.
refs_in = args.get("refs") or []
if not isinstance(refs_in, list):
raise _ToolValidationError("refs must be a list of image paths")
@@ -825,10 +831,16 @@ def _generate_shot_images(args: dict, ops: PanelOps, session: dict) -> dict:
for r in refs_in:
if not isinstance(r, str) or not r.strip():
raise _ToolValidationError("each ref must be a non-empty string path")
- rp = _resolve_path(r, ops.uploads_dir)
- if not Path(rp).is_file():
+ rp_str = _resolve_path(r, ops.uploads_dir)
+ try:
+ rp = _ensure_under(Path(rp_str), [ops.uploads_dir, ops.outputs_dir])
+ except _ToolValidationError as e:
+ raise _ToolValidationError(
+ f"ref path must live under uploads/outputs: {r!r} ({e})"
+ ) from e
+ if not rp.is_file():
raise _ToolValidationError(f"ref image not found: {rp}")
- refs_resolved.append(rp)
+ refs_resolved.append(str(rp))
# Image engine config travels in PanelOps.capabilities so tools.py
# stays free of panel imports.
diff --git a/mlx_ltx_panel.py b/mlx_ltx_panel.py
index e97b55e..df5c991 100644
--- a/mlx_ltx_panel.py
+++ b/mlx_ltx_panel.py
@@ -4775,6 +4775,15 @@ class Handler(BaseHTTPRequestHandler):
contains = (qs.get("contains", [""])[0] or "").strip().lower()
include_manual = (qs.get("include_manual", ["1"])[0] or "1") not in ("0", "false")
include_agent = (qs.get("include_agent", ["1"])[0] or "1") not in ("0", "false")
+ # `since` lets the modal cheaply poll for new gens after
+ # generation finishes (instead of re-scanning every PNG on
+ # disk). After months of agent use this dir is tens of
+ # thousands of files; a since-filter knocks the per-call
+ # cost down to whatever's been generated since the cursor.
+ try:
+ since = float((qs.get("since", ["0"])[0] or "0"))
+ except ValueError:
+ since = 0.0
roots: list[Path] = []
if include_agent:
@@ -4787,6 +4796,17 @@ class Handler(BaseHTTPRequestHandler):
if not root.exists():
continue
for png in root.rglob("*.png"):
+ # Cheap pre-filter: skip files whose mtime falls
+ # before `since` BEFORE doing the sidecar JSON read.
+ # On a 10K-file library this turns a 3-second walk
+ # into a sub-100ms one for incremental polls.
+ if since:
+ try:
+ mtime = png.stat().st_mtime
+ except OSError:
+ continue
+ if mtime <= since:
+ continue
sidecar = png.with_suffix(png.suffix + ".json")
meta: dict = {}
if sidecar.is_file():
@@ -4801,6 +4821,12 @@ class Handler(BaseHTTPRequestHandler):
meta["generated_at"] = png.stat().st_mtime
except OSError:
meta["generated_at"] = 0
+ # Apply since to the sidecar's logical generated_at
+ # too (sidecar may carry a slightly different ts than
+ # the file mtime — the explicit since check above
+ # used mtime, this honors the canonical sidecar ts).
+ if since and meta.get("generated_at", 0) <= since:
+ continue
if contains:
p = (meta.get("prompt") or "").lower()
if contains not in p:
@@ -4931,8 +4957,14 @@ class Handler(BaseHTTPRequestHandler):
rp = rp.resolve()
# Security: refs must live under UPLOADS or the public
# outputs dir. Prevents the JSON body from naming /etc/...
+ # Use Path.is_relative_to (3.9+) — string startswith() lets
+ # `panel_uploads_evil/` slip through because it shares the
+ # `panel_uploads` prefix without being under it. Both ends
+ # are already .resolved() so symlink/.. tricks are
+ # neutralized. Mirrors the agent-side _ensure_under
+ # convention in agent/tools.py.
allowed_roots = [UPLOADS.resolve(), OUTPUT.resolve()]
- if not any(str(rp).startswith(str(root)) for root in allowed_roots):
+ if not any(rp.is_relative_to(root) for root in allowed_roots):
self._json({"error": f"ref path not under uploads/outputs: {r}"}, 403); return
if not rp.is_file():
self._json({"error": f"ref image not found: {r}"}, 404); return