Important: Exploiting this vulnerability requires the attacker to have access to your Frigate instance, which means they could also just delete all of your recordings or perform any other action. If you have configured authentication in front of Frigate via a reverse proxy, then this vulnerability is not exploitable without first getting around your authentication method. For many obvious reasons in addition to this one, please don't expose your Frigate instance publicly without any kind of authentication.
When uploading a file or retrieving the filename, a user may intentionally use a large Unicode filename which would lead to a application-level denial of service. This is due to no limitation set on the length of the filename and the costy use of the Unicode normalization with the form NFKD under the hood of secure_filename()
.
I idenfied multiple vulnerable paths on blakeblackshear/frigate repository. In all of those paths, it was possible for a malicious user to send a filename equals to the output of : python3 -c "print('℀' * 1_000_000)"
which would reach the werkzeug secure_filename()
call , which in turn under the hood uses a compatibility Unicode normalization with NFKC/NFKD form. In sum, the latter call would be costly in matter of CPU resource and may lead to the application-level denial of service.
<details> <summary>Path with 2 steps</summary>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/<cameraname>/start/<int:startts>/end/<int:endts>/clip.mp4") @MediaBp.route("/<cameraname>/start/<float:startts>/end/<float:endts>/clip.mp4") def recordingclip(<strong>cameraname</strong>, startts, endts): download = request.args.get("download", type=bool)
</code></pre>
frigate/api/media.py <pre><code class="python"> playlistlines.append(f"outpoint {int(endts - clip.start_time)}")
file_name = secure_filename(<strong>f"clip_{camera_name}_{start_ts}-{end_ts}.mp4"</strong>)
path = os.path.join(CACHE_DIR, file_name)
</code></pre>
</details>
<pre><code class="python"> playlistlines.append(f"outpoint {int(endts - clip.start_time)}")
file_name = secure_filename(<strong>f"clip_{camera_name}_{start_ts}-{end_ts}.mp4"</strong>)
path = os.path.join(CACHE_DIR, file_name)
</code></pre>
This user-provided value can reach a costly Unicode normalization operation.
<details> <summary>Path with 2 steps</summary>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/<cameraname>/start/<int:startts>/end/<int:endts>/clip.mp4") @MediaBp.route("/<cameraname>/start/<float:startts>/end/<float:endts>/clip.mp4") def recordingclip(cameraname, <strong>startts</strong>, endts): download = request.args.get("download", type=bool)
</code></pre>
frigate/api/media.py <pre><code class="python"> playlistlines.append(f"outpoint {int(endts - clip.start_time)}")
file_name = secure_filename(<strong>f"clip_{camera_name}_{start_ts}-{end_ts}.mp4"</strong>)
path = os.path.join(CACHE_DIR, file_name)
</code></pre>
</details>
<pre><code class="python"> playlistlines.append(f"outpoint {int(endts - clip.start_time)}")
file_name = secure_filename(<strong>f"clip_{camera_name}_{start_ts}-{end_ts}.mp4"</strong>)
path = os.path.join(CACHE_DIR, file_name)
</code></pre>
This user-provided value can reach a costly Unicode normalization operation.
<details> <summary>Path with 2 steps</summary>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/<cameraname>/start/<int:startts>/end/<int:endts>/clip.mp4") @MediaBp.route("/<cameraname>/start/<float:startts>/end/<float:endts>/clip.mp4") def recordingclip(cameraname, startts, <strong>endts</strong>): download = request.args.get("download", type=bool)
</code></pre>
frigate/api/media.py <pre><code class="python"> playlistlines.append(f"outpoint {int(endts - clip.start_time)}")
file_name = secure_filename(<strong>f"clip_{camera_name}_{start_ts}-{end_ts}.mp4"</strong>)
path = os.path.join(CACHE_DIR, file_name)
</code></pre>
</details>
<pre><code class="python"> currentapp.frigateconfig, cameraname, securefilename(<strong>name.replace(" ", "")</strong>) if name else None, int(starttime), int(end_time), </code></pre>
This user-provided value can reach a costly Unicode normalization operation.
<details> <summary>Path with 8 steps</summary>
frigate/api/media.py <pre><code class="python"> jsonify, make_response, <strong>request</strong>, ) from peewee import DoesNotExist, fn </code></pre>
frigate/api/media.py <pre><code class="python"> jsonify, make_response, <strong>request</strong>, ) from peewee import DoesNotExist, fn </code></pre>
frigate/api/media.py <pre><code class="python"> )
json: dict[str, any] = <strong>request</strong>.get_json(silent=True) or {}
playback_factor = json.get("playback", "realtime")
name: Optional[str] = json.get("name")
</code></pre>
frigate/api/media.py <pre><code class="python"> )
<strong>json</strong>: dict[str, any] = request.get_json(silent=True) or {}
playback_factor = json.get("playback", "realtime")
name: Optional[str] = json.get("name")
</code></pre>
frigate/api/media.py <pre><code class="python"> json: dict[str, any] = request.getjson(silent=True) or {} playbackfactor = json.get("playback", "realtime") name: Optional[str] = <strong>json</strong>.get("name")
recordings_count = (
</code></pre>
frigate/api/media.py <pre><code class="python"> json: dict[str, any] = request.getjson(silent=True) or {} playbackfactor = json.get("playback", "realtime") name: Optional[str] = <strong>json.get("name")</strong>
recordings_count = (
</code></pre>
frigate/api/media.py <pre><code class="python"> json: dict[str, any] = request.getjson(silent=True) or {} playbackfactor = json.get("playback", "realtime") <strong>name</strong>: Optional[str] = json.get("name")
recordings_count = (
</code></pre>
frigate/api/media.py <pre><code class="python"> currentapp.frigateconfig, cameraname, securefilename(<strong>name.replace(" ", "")</strong>) if name else None, int(starttime), int(end_time), </code></pre>
</details>
<pre><code class="python">def exportrename(filenamecurrent, filenamenew: str): safefilenamecurrent = securefilename( <strong>exportfilenamecheckextension(filenamecurrent)</strong> ) filecurrent = os.path.join(EXPORTDIR, safefilename_current) </code></pre>
This user-provided value can reach a costly Unicode normalization operation.
<details> <summary>Path with 5 steps</summary>
frigate/api/media.py <pre><code class="python"> @MediaBp.route("/export/<filenamecurrent>/<filenamenew>", methods=["PATCH"]) def exportrename(<strong>filenamecurrent</strong>, filenamenew: str): safefilenamecurrent = securefilename( exportfilenamecheckextension(filenamecurrent) </code></pre>
frigate/api/media.py <pre><code class="python">def exportrename(filenamecurrent, filenamenew: str): safefilenamecurrent = securefilename( exportfilenamecheckextension(<strong>filenamecurrent</strong>) ) filecurrent = os.path.join(EXPORTDIR, safefilename_current) </code></pre>
frigate/api/media.py <pre><code class="python">
def exportfilenamecheck_extension(<strong>filename</strong>: str): if filename.endswith(".mp4"): return filename </code></pre>
frigate/api/media.py <pre><code class="python">def exportfilenamecheck_extension(filename: str): if filename.endswith(".mp4"): return <strong>filename</strong> else: return filename + ".mp4" </code></pre>
frigate/api/media.py <pre><code class="python">def exportrename(filenamecurrent, filenamenew: str): safefilenamecurrent = securefilename( <strong>exportfilenamecheckextension(filenamecurrent)</strong> ) filecurrent = os.path.join(EXPORTDIR, safefilename_current) </code></pre>
</details>
<details> <summary>Path with 5 steps</summary>
frigate/api/media.py <pre><code class="python"> @MediaBp.route("/export/<filenamecurrent>/<filenamenew>", methods=["PATCH"]) def exportrename(<strong>filenamecurrent</strong>, filenamenew: str): safefilenamecurrent = securefilename( exportfilenamecheckextension(filenamecurrent) </code></pre>
frigate/api/media.py <pre><code class="python">def exportrename(filenamecurrent, filenamenew: str): safefilenamecurrent = securefilename( exportfilenamecheckextension(<strong>filenamecurrent</strong>) ) filecurrent = os.path.join(EXPORTDIR, safefilename_current) </code></pre>
frigate/api/media.py <pre><code class="python">
def exportfilenamecheck_extension(<strong>filename</strong>: str): if filename.endswith(".mp4"): return filename </code></pre>
frigate/api/media.py <pre><code class="python"> return filename else: return <strong>filename + ".mp4"</strong>
</code></pre>
frigate/api/media.py <pre><code class="python">def exportrename(filenamecurrent, filenamenew: str): safefilenamecurrent = securefilename( <strong>exportfilenamecheckextension(filenamecurrent)</strong> ) filecurrent = os.path.join(EXPORTDIR, safefilename_current) </code></pre>
</details>
<pre><code class="python"> )
safe_file_name_new = secure_filename(<strong>export_filename_check_extension(file_name_new)</strong>)
file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
</code></pre>
This user-provided value can reach a costly Unicode normalization operation.
<details> <summary>Path with 5 steps</summary>
frigate/api/media.py <pre><code class="python"> @MediaBp.route("/export/<filenamecurrent>/<filenamenew>", methods=["PATCH"]) def exportrename(filenamecurrent, <strong>filenamenew</strong>: str): safefilenamecurrent = securefilename( exportfilenamecheckextension(filenamecurrent) </code></pre>
frigate/api/media.py <pre><code class="python"> )
safe_file_name_new = secure_filename(export_filename_check_extension(<strong>file_name_new</strong>))
file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
</code></pre>
frigate/api/media.py <pre><code class="python">
def exportfilenamecheck_extension(<strong>filename</strong>: str): if filename.endswith(".mp4"): return filename </code></pre>
frigate/api/media.py <pre><code class="python">def exportfilenamecheck_extension(filename: str): if filename.endswith(".mp4"): return <strong>filename</strong> else: return filename + ".mp4" </code></pre>
frigate/api/media.py <pre><code class="python"> )
safe_file_name_new = secure_filename(<strong>export_filename_check_extension(file_name_new)</strong>)
file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
</code></pre>
</details>
<details> <summary>Path with 5 steps</summary>
frigate/api/media.py <pre><code class="python"> @MediaBp.route("/export/<filenamecurrent>/<filenamenew>", methods=["PATCH"]) def exportrename(filenamecurrent, <strong>filenamenew</strong>: str): safefilenamecurrent = securefilename( exportfilenamecheckextension(filenamecurrent) </code></pre>
frigate/api/media.py <pre><code class="python"> )
safe_file_name_new = secure_filename(export_filename_check_extension(<strong>file_name_new</strong>))
file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
</code></pre>
frigate/api/media.py <pre><code class="python">
def exportfilenamecheck_extension(<strong>filename</strong>: str): if filename.endswith(".mp4"): return filename </code></pre>
frigate/api/media.py <pre><code class="python"> return filename else: return <strong>filename + ".mp4"</strong>
</code></pre>
frigate/api/media.py <pre><code class="python"> )
safe_file_name_new = secure_filename(<strong>export_filename_check_extension(file_name_new)</strong>)
file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
</code></pre>
</details>
<pre><code class="python">@MediaBp.route("/export/<filename>", methods=["DELETE"]) def exportdelete(filename: str): safefilename = securefilename(<strong>exportfilenamecheckextension(filename)</strong>) file = os.path.join(EXPORTDIR, safefile_name)
</code></pre>
This user-provided value can reach a costly Unicode normalization operation.
<details> <summary>Path with 5 steps</summary>
frigate/api/media.py <pre><code class="python"> @MediaBp.route("/export/<filename>", methods=["DELETE"]) def exportdelete(<strong>filename</strong>: str): safefilename = securefilename(exportfilenamecheckextension(filename)) file = os.path.join(EXPORTDIR, safefile_name) </code></pre>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/export/<filename>", methods=["DELETE"]) def exportdelete(filename: str): safefilename = securefilename(exportfilenamecheckextension(<strong>filename</strong>)) file = os.path.join(EXPORTDIR, safefile_name)
</code></pre>
frigate/api/media.py <pre><code class="python">
def exportfilenamecheck_extension(<strong>filename</strong>: str): if filename.endswith(".mp4"): return filename </code></pre>
frigate/api/media.py <pre><code class="python">def exportfilenamecheck_extension(filename: str): if filename.endswith(".mp4"): return <strong>filename</strong> else: return filename + ".mp4" </code></pre>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/export/<filename>", methods=["DELETE"]) def exportdelete(filename: str): safefilename = securefilename(<strong>exportfilenamecheckextension(filename)</strong>) file = os.path.join(EXPORTDIR, safefile_name)
</code></pre>
</details>
<details> <summary>Path with 5 steps</summary>
frigate/api/media.py <pre><code class="python"> @MediaBp.route("/export/<filename>", methods=["DELETE"]) def exportdelete(<strong>filename</strong>: str): safefilename = securefilename(exportfilenamecheckextension(filename)) file = os.path.join(EXPORTDIR, safefile_name) </code></pre>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/export/<filename>", methods=["DELETE"]) def exportdelete(filename: str): safefilename = securefilename(exportfilenamecheckextension(<strong>filename</strong>)) file = os.path.join(EXPORTDIR, safefile_name)
</code></pre>
frigate/api/media.py <pre><code class="python">
def exportfilenamecheck_extension(<strong>filename</strong>: str): if filename.endswith(".mp4"): return filename </code></pre>
frigate/api/media.py <pre><code class="python"> return filename else: return <strong>filename + ".mp4"</strong>
</code></pre>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/export/<filename>", methods=["DELETE"]) def exportdelete(filename: str): safefilename = securefilename(<strong>exportfilenamecheckextension(filename)</strong>) file = os.path.join(EXPORTDIR, safefile_name)
</code></pre>
</details>
<pre><code class="python">def previewthumbnail(filename: str): """Get a thumbnail from the cached preview frames.""" safefilenamecurrent = securefilename(<strong>filename</strong>) previewdir = os.path.join(CACHEDIR, "previewframes")
</code></pre>
This user-provided value can reach a costly Unicode normalization operation.
<details> <summary>Path with 2 steps</summary>
frigate/api/media.py <pre><code class="python">@MediaBp.route("/preview/<filename>/thumbnail.jpg") @MediaBp.route("/preview/<filename>/thumbnail.webp") def previewthumbnail(<strong>filename</strong>: str): """Get a thumbnail from the cached preview frames.""" safefilenamecurrent = securefilename(file_name) </code></pre>
frigate/api/media.py <pre><code class="python">def previewthumbnail(filename: str): """Get a thumbnail from the cached preview frames.""" safefilenamecurrent = securefilename(<strong>filename</strong>) previewdir = os.path.join(CACHEDIR, "previewframes")
</code></pre>
</details>
{ "nvd_published_at": "2024-05-14T15:37:13Z", "cwe_ids": [ "CWE-770" ], "severity": "CRITICAL", "github_reviewed": true, "github_reviewed_at": "2024-05-09T15:13:49Z" }