mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-08-02 09:02:15 +03:00
Fixes (#23235)
* use stable empty object reference for swr metadata default * version bump * Refactor get_min_region_size for dimension normalization Refactor get_min_region_size to normalize dimensions for smaller models and ensure minimum region size is 320 for larger models. * reject restricted go2rtc stream sources when added via api * add env var check function * fix typing --------- Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>
This commit is contained in:
co-authored by
Nicolas Mowen
parent
2cfb530dbf
commit
0013555528
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi import HTTPException, Request
|
||||
@@ -357,6 +358,51 @@ class TestGo2rtcStreamAccess(BaseTestHttp):
|
||||
f"got {resp.status_code}"
|
||||
)
|
||||
|
||||
def test_add_stream_rejects_restricted_source(self):
|
||||
"""PUT /go2rtc/streams must reject exec:/echo:/expr: sources even for
|
||||
admins"""
|
||||
app = self._make_app(_MULTI_CAMERA_CONFIG)
|
||||
with AuthTestClient(app) as client:
|
||||
for src in (
|
||||
"exec:/tmp/rev.sh",
|
||||
"echo:foo",
|
||||
"expr:bar",
|
||||
" exec:/tmp/rev.sh",
|
||||
):
|
||||
resp = client.put(f"/go2rtc/streams/revshell?src={src}")
|
||||
assert resp.status_code == 400, (
|
||||
f"Expected 400 for restricted src {src!r}; got {resp.status_code}"
|
||||
)
|
||||
assert resp.json().get("success") is False
|
||||
|
||||
def test_add_stream_allows_non_restricted_source(self):
|
||||
"""A normal stream URL should pass the restricted-source check and reach
|
||||
the (unavailable in tests) go2rtc proxy — so we expect 500, not 400."""
|
||||
app = self._make_app(_MULTI_CAMERA_CONFIG)
|
||||
with AuthTestClient(app) as client:
|
||||
resp = client.put("/go2rtc/streams/legit?src=rtsp://10.0.0.1:554/video")
|
||||
assert resp.status_code != 400, (
|
||||
f"Non-restricted source should not be rejected with 400; got {resp.status_code}"
|
||||
)
|
||||
|
||||
def test_add_stream_allows_restricted_source_when_override_set(self):
|
||||
"""When GO2RTC_ALLOW_ARBITRARY_EXEC is set, the API must defer to operator
|
||||
intent and forward the request to go2rtc instead of short-circuiting with 400."""
|
||||
app = self._make_app(_MULTI_CAMERA_CONFIG)
|
||||
mock_response = type("R", (), {"ok": True, "status_code": 200, "text": "ok"})()
|
||||
with patch.dict(os.environ, {"GO2RTC_ALLOW_ARBITRARY_EXEC": "true"}):
|
||||
with patch(
|
||||
"frigate.api.camera.requests.put", return_value=mock_response
|
||||
) as mock_put:
|
||||
with AuthTestClient(app) as client:
|
||||
resp = client.put("/go2rtc/streams/legit?src=exec:/tmp/something")
|
||||
assert resp.status_code == 200, (
|
||||
f"Restricted src should be forwarded when override set; got {resp.status_code}"
|
||||
)
|
||||
mock_put.assert_called_once()
|
||||
forwarded_src = mock_put.call_args.kwargs["params"]["src"]
|
||||
assert forwarded_src == "exec:/tmp/something"
|
||||
|
||||
def test_stream_alias_blocked_when_owning_camera_disallowed(self):
|
||||
"""limited_user cannot access a stream alias that belongs to a camera they
|
||||
are not allowed to see."""
|
||||
|
||||
Reference in New Issue
Block a user