mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-24 22:37:08 +03:00
scope review lookup by event id to allowed cameras
The review lookup by event id matched the id with GLOB, so wildcard characters in the id matched other ids, and the camera check ran on whichever row matched first, returning a 403 that named a camera the user can't access. The id now matches literally and the query only searches the user's allowed cameras, so a review item on another camera returns the same 404 as a missing one.
This commit is contained in:
Vendored
+6
-8
@@ -2311,8 +2311,8 @@ paths:
|
||||
$ref: '#/components/schemas/HTTPValidationError'
|
||||
security:
|
||||
- frigateUserAuth: []
|
||||
x-required-role: camera
|
||||
description: '**Access:** Authenticated user with access to the referenced camera.'
|
||||
x-required-role: any
|
||||
description: '**Access:** Any authenticated user.'
|
||||
/review/{review_id}:
|
||||
get:
|
||||
tags:
|
||||
@@ -6152,9 +6152,7 @@ paths:
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: 'null'
|
||||
type: string
|
||||
title: Camera Name
|
||||
- name: frame_time
|
||||
in: path
|
||||
@@ -6175,9 +6173,9 @@ paths:
|
||||
schema:
|
||||
$ref: '#/components/schemas/HTTPValidationError'
|
||||
security:
|
||||
- frigateUserAuth: []
|
||||
x-required-role: camera
|
||||
description: '**Access:** Authenticated user with access to the referenced camera.'
|
||||
- frigateAdminAuth: []
|
||||
x-required-role: admin
|
||||
description: '**Access:** Admin role required.'
|
||||
/{camera_name}/start/{start_ts}/end/{end_ts}/clip.mp4:
|
||||
get:
|
||||
tags:
|
||||
|
||||
@@ -713,12 +713,18 @@ def motion_activity(
|
||||
response_model=ReviewSegmentResponse,
|
||||
dependencies=[Depends(allow_any_authenticated())],
|
||||
)
|
||||
async def get_review_from_event(request: Request, event_id: str):
|
||||
async def get_review_from_event(
|
||||
event_id: str,
|
||||
allowed_cameras: list[str] = Depends(get_allowed_cameras_for_filter),
|
||||
):
|
||||
try:
|
||||
review = ReviewSegment.get(
|
||||
ReviewSegment.data["detections"].cast("text") % f'*"{event_id}"*'
|
||||
(ReviewSegment.camera << allowed_cameras)
|
||||
& (
|
||||
fn.instr(ReviewSegment.data["detections"].cast("text"), f'"{event_id}"')
|
||||
> 0
|
||||
)
|
||||
)
|
||||
await require_camera_access(review.camera, request=request)
|
||||
return JSONResponse(model_to_dict(review))
|
||||
except DoesNotExist:
|
||||
return JSONResponse(
|
||||
|
||||
@@ -840,6 +840,42 @@ class TestHttpReview(BaseTestHttp):
|
||||
response_json,
|
||||
)
|
||||
|
||||
def test_review_event_wildcards_match_literally(self):
|
||||
now = datetime.now().timestamp()
|
||||
super().insert_mock_review_segment(
|
||||
"123456.review.random",
|
||||
now + 1,
|
||||
now + 2,
|
||||
data={"detections": ["1763812345.0-abc123"]},
|
||||
)
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
for pattern in ["1763812345*", "176381234?.0-abc123", "176381234[0-9]*"]:
|
||||
response = client.get(f"/review/event/{pattern}")
|
||||
assert response.status_code == 404
|
||||
|
||||
response = client.get("/review/event/1763812345.0-abc123")
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_review_event_on_forbidden_camera_is_not_found(self):
|
||||
now = datetime.now().timestamp()
|
||||
event_id = "1763812345.0-abc123"
|
||||
super().insert_mock_review_segment(
|
||||
"123456.review.random",
|
||||
now + 1,
|
||||
now + 2,
|
||||
data={"detections": [event_id]},
|
||||
camera="back_door",
|
||||
)
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
response = client.get(f"/review/event/{event_id}")
|
||||
assert response.status_code == 404
|
||||
self.assertDictEqual(
|
||||
{"success": False, "message": "Review item not found"},
|
||||
response.json(),
|
||||
)
|
||||
|
||||
####################################################################################################################
|
||||
################################### GET /review/{review_id} Endpoint #######################################
|
||||
####################################################################################################################
|
||||
|
||||
Reference in New Issue
Block a user