Check ownership before stopping a camera watch from chat (#24776)
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

* check ownership before stopping a camera watch from chat

The stop_camera_watch chat tool cancelled the active VLM watch job without checking who started it, so any authenticated user could cancel another user's job by calling /chat/completion directly. The tool now uses the same admin-or-creator check as DELETE /vlm/monitor, and chat-started jobs record their creator so non-admins can still stop their own.

* Added a test that calls `_execute_start_camera_watch` and checks `start_vlm_watch_job` receives the caller's username, so removing that argument now fails it.
This commit is contained in:
Josh Hawkins
2026-10-26 06:23:53 -06:00
committed by GitHub
parent 748cdc5eb2
commit 94e570017c
2 changed files with 79 additions and 7 deletions
+16 -7
View File
@@ -45,6 +45,7 @@ from frigate.genai.prompts import (
)
from frigate.genai.utils import build_assistant_message_for_conversation
from frigate.jobs.vlm_watch import (
VLMWatchJob,
get_vlm_watch_job,
start_vlm_watch_job,
stop_vlm_watch_job,
@@ -765,7 +766,7 @@ async def _execute_tool_internal(
elif tool_name == "start_camera_watch":
return await _execute_start_camera_watch(request, arguments)
elif tool_name == "stop_camera_watch":
return _execute_stop_camera_watch()
return _execute_stop_camera_watch(request)
elif tool_name == "get_profile_status":
return _execute_get_profile_status(request)
elif tool_name == "get_recap":
@@ -819,6 +820,7 @@ async def _execute_start_camera_watch(
dispatcher=request.app.dispatcher,
labels=labels,
zones=zones,
username=request.headers.get("remote-user", ""),
)
except RuntimeError as e:
logger.exception("Failed to start VLM watch job: %s", e)
@@ -834,7 +836,18 @@ async def _execute_start_camera_watch(
}
def _execute_stop_camera_watch() -> dict[str, Any]:
def _can_cancel_watch_job(request: Request, job: VLMWatchJob) -> bool:
"""Admins can cancel any watch job; other users only jobs they started."""
role = request.headers.get("remote-role", "viewer")
username = request.headers.get("remote-user", "")
return role == "admin" or username == job.username
def _execute_stop_camera_watch(request: Request) -> dict[str, Any]:
job = get_vlm_watch_job()
if job is not None and not _can_cancel_watch_job(request, job):
return {"success": False, "message": "Not authorized to cancel this watch job."}
cancelled = stop_vlm_watch_job()
if cancelled:
return {"success": True, "message": "Watch job cancelled."}
@@ -1548,11 +1561,7 @@ async def cancel_vlm_monitor(request: Request) -> JSONResponse:
status_code=404,
)
role = request.headers.get("remote-role", "viewer")
username = request.headers.get("remote-user", "")
# Admin can cancel any job; other users can only cancel jobs they started.
if role != "admin" and username != job.username:
if not _can_cancel_watch_job(request, job):
return JSONResponse(
content={
"success": False,