Restrict go2rtc ffmpeg and ngrok options without arbitrary exec (#24709)
CI / AMD64 Build (push) Canceled after 0s
CI / ARM Build (push) Canceled after 0s
CI / Jetson Jetpack 6 (push) Canceled after 0s
CI / AMD64 Extra Build (push) Canceled after 0s
CI / ARM Extra Build (push) Canceled after 0s
CI / Synaptics Build (push) Canceled after 0s
CI / Assemble and push default build (push) Canceled after 0s

* restrict go2rtc ffmpeg and ngrok options without arbitrary exec

The GO2RTC_ALLOW_ARBITRARY_EXEC checks only looked at go2rtc.streams, so an admin could save a config with a custom ffmpeg.bin or ngrok.command and run any command as the go2rtc user after a restart. go2rtc builds every ffmpeg: source into a command that starts with ffmpeg.bin, and it runs ngrok.command at startup. A custom template also brought back arbitrary ffmpeg arguments, since a stream can reference any template key with #video=<name>.

config/save and config/set now reject any added or changed key under go2rtc.ffmpeg or go2rtc.ngrok unless arbitrary exec is enabled. Keys already in the saved config are left alone, the same as stream sources. At startup, ffmpeg.bin is always Frigate's ffmpeg and ngrok is dropped unless arbitrary exec is enabled. Templates already in the config file, such as the documented vaapi global, keep working.

* reject ffmpeg paths with spaces, quotes or shell characters

ffmpeg.path was used as-is when absolute, and several ffmpeg commands are built as strings and split on spaces before running. A path like `/bin/sh -c <cmd>;#` ran a shell command instead of ffmpeg in the preview and export processes, and in go2rtc through the birdseye restream exec source. The path is now validated as a version alias or an absolute path of plain characters, so config/save and config/set reject an unsafe value. resolve_ffmpeg_path falls back to the default ffmpeg for one, and the go2rtc startup script prints an error.
This commit is contained in:
Josh Hawkins
2026-10-18 06:41:38 -10:00
committed by GitHub
parent aa42b17911
commit cf418dd6b6
8 changed files with 328 additions and 35 deletions
+16 -3
View File
@@ -3,6 +3,7 @@
import asyncio
import logging
import os
import re
import shutil
from typing import Any
@@ -23,6 +24,15 @@ logger = logging.getLogger(__name__)
CURRENT_CONFIG_VERSION = "0.18-0"
DEFAULT_CONFIG_FILE = os.path.join(CONFIG_DIR, "config.yml")
# ffmpeg commands are built as strings and split on whitespace, so a custom path
# must stay a single plain token
_CUSTOM_FFMPEG_PATH = re.compile(r"/[\w.+@/-]+")
def is_valid_ffmpeg_path(path: str) -> bool:
"""Check that a custom ffmpeg path has no whitespace, quotes or shell syntax."""
return not path.startswith("/") or _CUSTOM_FFMPEG_PATH.fullmatch(path) is not None
def resolve_ffmpeg_path(path: str, binary: str = "ffmpeg") -> str:
"""Resolve an ffmpeg version alias or custom path to a binary path.
@@ -30,10 +40,13 @@ def resolve_ffmpeg_path(path: str, binary: str = "ffmpeg") -> str:
A bare version alias that is no longer bundled (for example one that was
dropped when the default version changed) falls back to the default
bundled version so existing configs keep working across an upgrade or a
revert. Custom install paths (anything absolute) are used as-is.
revert. Custom install paths (anything absolute) are used as-is, unless
they fail `is_valid_ffmpeg_path`, which also falls back to the default.
"""
if path == "default" or (
not path.startswith("/") and path not in INCLUDED_FFMPEG_VERSIONS
if (
path == "default"
or not is_valid_ffmpeg_path(path)
or (not path.startswith("/") and path not in INCLUDED_FFMPEG_VERSIONS)
):
version = DEFAULT_FFMPEG_VERSION
elif path in INCLUDED_FFMPEG_VERSIONS: