|
8 | 8 | import psutil |
9 | 9 | from fastapi import APIRouter, Depends, Request |
10 | 10 | from fastapi.responses import JSONResponse |
| 11 | +from pathvalidate import sanitize_filepath |
11 | 12 | from peewee import DoesNotExist |
12 | 13 | from playhouse.shortcuts import model_to_dict |
13 | 14 |
|
14 | 15 | from frigate.api.auth import require_role |
15 | 16 | from frigate.api.defs.request.export_recordings_body import ExportRecordingsBody |
16 | 17 | from frigate.api.defs.request.export_rename_body import ExportRenameBody |
17 | 18 | from frigate.api.defs.tags import Tags |
18 | | -from frigate.const import EXPORT_DIR |
| 19 | +from frigate.const import CLIPS_DIR, EXPORT_DIR |
19 | 20 | from frigate.models import Export, Previews, Recordings |
20 | 21 | from frigate.record.export import ( |
21 | 22 | PlaybackFactorEnum, |
@@ -54,7 +55,14 @@ def export_recording( |
54 | 55 | playback_factor = body.playback |
55 | 56 | playback_source = body.source |
56 | 57 | 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 | + ) |
58 | 66 |
|
59 | 67 | if playback_source == "recordings": |
60 | 68 | recordings_count = ( |
|
0 commit comments