Skip to content

Commit 4d58206

Browse files
authored
Ensure that a user must provide an image in an expected location (#20491)
* Ensure that a user must provide an image in an expected location * Use const
1 parent e0a8445 commit 4d58206

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

frigate/api/export.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
import psutil
99
from fastapi import APIRouter, Depends, Request
1010
from fastapi.responses import JSONResponse
11+
from pathvalidate import sanitize_filepath
1112
from peewee import DoesNotExist
1213
from playhouse.shortcuts import model_to_dict
1314

1415
from frigate.api.auth import require_role
1516
from frigate.api.defs.request.export_recordings_body import ExportRecordingsBody
1617
from frigate.api.defs.request.export_rename_body import ExportRenameBody
1718
from frigate.api.defs.tags import Tags
18-
from frigate.const import EXPORT_DIR
19+
from frigate.const import CLIPS_DIR, EXPORT_DIR
1920
from frigate.models import Export, Previews, Recordings
2021
from frigate.record.export import (
2122
PlaybackFactorEnum,
@@ -54,7 +55,14 @@ def export_recording(
5455
playback_factor = body.playback
5556
playback_source = body.source
5657
friendly_name = body.name
57-
existing_image = body.image_path
58+
existing_image = sanitize_filepath(body.image_path) if body.image_path else None
59+
60+
# Ensure that existing_image is a valid path
61+
if existing_image and not existing_image.startswith(CLIPS_DIR):
62+
return JSONResponse(
63+
content=({"success": False, "message": "Invalid image path"}),
64+
status_code=400,
65+
)
5866

5967
if playback_source == "recordings":
6068
recordings_count = (

0 commit comments

Comments
 (0)