Skip to content

Malicious Long Unicode filenames may cause a Multiple Application-level Denial of Service

Moderate
blakeblackshear published GHSA-w4h6-9wrp-v5jq May 9, 2024

Package

pip frigate (pip)

Affected versions

below 0.13.2 Release

Patched versions

None

Description

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.

Summary

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.

Vulnerable Paths

Path with 2 steps
  1. frigate/api/media.py

    @MediaBp.route("/<camera_name>/start/<int:start_ts>/end/<int:end_ts>/clip.mp4")
    @MediaBp.route("/<camera_name>/start/<float:start_ts>/end/<float:end_ts>/clip.mp4")
    def recording_clip(camera_name, start_ts, end_ts):
        download = request.args.get("download", type=bool)
    
    
  2. frigate/api/media.py

                playlist_lines.append(f"outpoint {int(end_ts - clip.start_time)}")
    
        file_name = secure_filename(f"clip_{camera_name}_{start_ts}-{end_ts}.mp4")
        path = os.path.join(CACHE_DIR, file_name)
    
    

frigate/api/media.py

            playlist_lines.append(f"outpoint {int(end_ts - clip.start_time)}")

    file_name = secure_filename(f"clip_{camera_name}_{start_ts}-{end_ts}.mp4")
    path = os.path.join(CACHE_DIR, file_name)

This user-provided value can reach a costly Unicode normalization operation.

Paths

Path with 2 steps
  1. frigate/api/media.py

    @MediaBp.route("/<camera_name>/start/<int:start_ts>/end/<int:end_ts>/clip.mp4")
    @MediaBp.route("/<camera_name>/start/<float:start_ts>/end/<float:end_ts>/clip.mp4")
    def recording_clip(camera_name, start_ts, end_ts):
        download = request.args.get("download", type=bool)
    
    
  2. frigate/api/media.py

                playlist_lines.append(f"outpoint {int(end_ts - clip.start_time)}")
    
        file_name = secure_filename(f"clip_{camera_name}_{start_ts}-{end_ts}.mp4")
        path = os.path.join(CACHE_DIR, file_name)
    
    

frigate/api/media.py

            playlist_lines.append(f"outpoint {int(end_ts - clip.start_time)}")

    file_name = secure_filename(f"clip_{camera_name}_{start_ts}-{end_ts}.mp4")
    path = os.path.join(CACHE_DIR, file_name)

This user-provided value can reach a costly Unicode normalization operation.

Paths

Path with 2 steps
  1. frigate/api/media.py

    @MediaBp.route("/<camera_name>/start/<int:start_ts>/end/<int:end_ts>/clip.mp4")
    @MediaBp.route("/<camera_name>/start/<float:start_ts>/end/<float:end_ts>/clip.mp4")
    def recording_clip(camera_name, start_ts, end_ts):
        download = request.args.get("download", type=bool)
    
    
  2. frigate/api/media.py

                playlist_lines.append(f"outpoint {int(end_ts - clip.start_time)}")
    
        file_name = secure_filename(f"clip_{camera_name}_{start_ts}-{end_ts}.mp4")
        path = os.path.join(CACHE_DIR, file_name)
    
    

frigate/api/media.py

        current_app.frigate_config,
        camera_name,
        secure_filename(name.replace(" ", "_")) if name else None,
        int(start_time),
        int(end_time),

This user-provided value can reach a costly Unicode normalization operation.

Paths

Path with 8 steps
  1. frigate/api/media.py

        jsonify,
        make_response,
        request,
    )
    from peewee import DoesNotExist, fn
    
  2. frigate/api/media.py

        jsonify,
        make_response,
        request,
    )
    from peewee import DoesNotExist, fn
    
  3. frigate/api/media.py

            )
    
        json: dict[str, any] = request.get_json(silent=True) or {}
        playback_factor = json.get("playback", "realtime")
        name: Optional[str] = json.get("name")
    
  4. frigate/api/media.py

            )
    
        json: dict[str, any] = request.get_json(silent=True) or {}
        playback_factor = json.get("playback", "realtime")
        name: Optional[str] = json.get("name")
    
  5. frigate/api/media.py

        json: dict[str, any] = request.get_json(silent=True) or {}
        playback_factor = json.get("playback", "realtime")
        name: Optional[str] = json.get("name")
    
        recordings_count = (
    
  6. frigate/api/media.py

        json: dict[str, any] = request.get_json(silent=True) or {}
        playback_factor = json.get("playback", "realtime")
        name: Optional[str] = json.get("name")
    
        recordings_count = (
    
  7. frigate/api/media.py

        json: dict[str, any] = request.get_json(silent=True) or {}
        playback_factor = json.get("playback", "realtime")
        name: Optional[str] = json.get("name")
    
        recordings_count = (
    
  8. frigate/api/media.py

            current_app.frigate_config,
            camera_name,
            secure_filename(name.replace(" ", "_")) if name else None,
            int(start_time),
            int(end_time),
    

frigate/api/media.py

def export_rename(file_name_current, file_name_new: str):
    safe_file_name_current = secure_filename(
        export_filename_check_extension(file_name_current)
    )
    file_current = os.path.join(EXPORT_DIR, safe_file_name_current)

This user-provided value can reach a costly Unicode normalization operation.

Paths

Path with 5 steps
  1. frigate/api/media.py

    
    @MediaBp.route("/export/<file_name_current>/<file_name_new>", methods=["PATCH"])
    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
    
  2. frigate/api/media.py

    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
        )
        file_current = os.path.join(EXPORT_DIR, safe_file_name_current)
    
  3. frigate/api/media.py

    
    
    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
    
  4. frigate/api/media.py

    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
        else:
            return filename + ".mp4"
    
  5. frigate/api/media.py

    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
        )
        file_current = os.path.join(EXPORT_DIR, safe_file_name_current)
    
Path with 5 steps
  1. frigate/api/media.py

    
    @MediaBp.route("/export/<file_name_current>/<file_name_new>", methods=["PATCH"])
    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
    
  2. frigate/api/media.py

    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
        )
        file_current = os.path.join(EXPORT_DIR, safe_file_name_current)
    
  3. frigate/api/media.py

    
    
    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
    
  4. frigate/api/media.py

            return filename
        else:
            return filename + ".mp4"
    
    
    
  5. frigate/api/media.py

    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
        )
        file_current = os.path.join(EXPORT_DIR, safe_file_name_current)
    

frigate/api/media.py

        )

    safe_file_name_new = secure_filename(export_filename_check_extension(file_name_new))
    file_new = os.path.join(EXPORT_DIR, safe_file_name_new)

This user-provided value can reach a costly Unicode normalization operation.

Paths

Path with 5 steps
  1. frigate/api/media.py

    
    @MediaBp.route("/export/<file_name_current>/<file_name_new>", methods=["PATCH"])
    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
    
  2. frigate/api/media.py

            )
    
        safe_file_name_new = secure_filename(export_filename_check_extension(file_name_new))
        file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
    
    
  3. frigate/api/media.py

    
    
    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
    
  4. frigate/api/media.py

    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
        else:
            return filename + ".mp4"
    
  5. frigate/api/media.py

            )
    
        safe_file_name_new = secure_filename(export_filename_check_extension(file_name_new))
        file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
    
    
Path with 5 steps
  1. frigate/api/media.py

    
    @MediaBp.route("/export/<file_name_current>/<file_name_new>", methods=["PATCH"])
    def export_rename(file_name_current, file_name_new: str):
        safe_file_name_current = secure_filename(
            export_filename_check_extension(file_name_current)
    
  2. frigate/api/media.py

            )
    
        safe_file_name_new = secure_filename(export_filename_check_extension(file_name_new))
        file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
    
    
  3. frigate/api/media.py

    
    
    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
    
  4. frigate/api/media.py

            return filename
        else:
            return filename + ".mp4"
    
    
    
  5. frigate/api/media.py

            )
    
        safe_file_name_new = secure_filename(export_filename_check_extension(file_name_new))
        file_new = os.path.join(EXPORT_DIR, safe_file_name_new)
    
    

frigate/api/media.py

@MediaBp.route("/export/<file_name>", methods=["DELETE"])
def export_delete(file_name: str):
    safe_file_name = secure_filename(export_filename_check_extension(file_name))
    file = os.path.join(EXPORT_DIR, safe_file_name)

This user-provided value can reach a costly Unicode normalization operation.

Paths

Path with 5 steps
  1. frigate/api/media.py

    
    @MediaBp.route("/export/<file_name>", methods=["DELETE"])
    def export_delete(file_name: str):
        safe_file_name = secure_filename(export_filename_check_extension(file_name))
        file = os.path.join(EXPORT_DIR, safe_file_name)
    
  2. frigate/api/media.py

    @MediaBp.route("/export/<file_name>", methods=["DELETE"])
    def export_delete(file_name: str):
        safe_file_name = secure_filename(export_filename_check_extension(file_name))
        file = os.path.join(EXPORT_DIR, safe_file_name)
    
    
  3. frigate/api/media.py

    
    
    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
    
  4. frigate/api/media.py

    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
        else:
            return filename + ".mp4"
    
  5. frigate/api/media.py

    @MediaBp.route("/export/<file_name>", methods=["DELETE"])
    def export_delete(file_name: str):
        safe_file_name = secure_filename(export_filename_check_extension(file_name))
        file = os.path.join(EXPORT_DIR, safe_file_name)
    
    
Path with 5 steps
  1. frigate/api/media.py

    
    @MediaBp.route("/export/<file_name>", methods=["DELETE"])
    def export_delete(file_name: str):
        safe_file_name = secure_filename(export_filename_check_extension(file_name))
        file = os.path.join(EXPORT_DIR, safe_file_name)
    
  2. frigate/api/media.py

    @MediaBp.route("/export/<file_name>", methods=["DELETE"])
    def export_delete(file_name: str):
        safe_file_name = secure_filename(export_filename_check_extension(file_name))
        file = os.path.join(EXPORT_DIR, safe_file_name)
    
    
  3. frigate/api/media.py

    
    
    def export_filename_check_extension(filename: str):
        if filename.endswith(".mp4"):
            return filename
    
  4. frigate/api/media.py

            return filename
        else:
            return filename + ".mp4"
    
    
    
  5. frigate/api/media.py

    @MediaBp.route("/export/<file_name>", methods=["DELETE"])
    def export_delete(file_name: str):
        safe_file_name = secure_filename(export_filename_check_extension(file_name))
        file = os.path.join(EXPORT_DIR, safe_file_name)
    
    

frigate/api/media.py

def preview_thumbnail(file_name: str):
    """Get a thumbnail from the cached preview frames."""
    safe_file_name_current = secure_filename(file_name)
    preview_dir = os.path.join(CACHE_DIR, "preview_frames")

This user-provided value can reach a costly Unicode normalization operation.

Paths

Path with 2 steps
  1. frigate/api/media.py

    @MediaBp.route("/preview/<file_name>/thumbnail.jpg")
    @MediaBp.route("/preview/<file_name>/thumbnail.webp")
    def preview_thumbnail(file_name: str):
        """Get a thumbnail from the cached preview frames."""
        safe_file_name_current = secure_filename(file_name)
    
  2. frigate/api/media.py

    def preview_thumbnail(file_name: str):
        """Get a thumbnail from the cached preview frames."""
        safe_file_name_current = secure_filename(file_name)
        preview_dir = os.path.join(CACHE_DIR, "preview_frames")
    
    

Impact

  • Application-level Denial of Service, the web app would hung undefinetly and not process any further request due to the use of the malicious payload.

Mitigation

  • Limiting the length of the incoming filename, similar to this commit fix.

References

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
High
User interaction
None
Scope
Changed
Confidentiality
None
Integrity
None
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:N/I:N/A:H

CVE ID

CVE-2024-32874

Weaknesses

Credits