From 7f93712e7328ce3f90205411ddf1e83a1a4fd592 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Sat, 26 Nov 2022 07:41:13 -0700 Subject: [PATCH] Clean http passwords too --- frigate/const.py | 3 ++- frigate/util.py | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/frigate/const.py b/frigate/const.py index 1cc14293e..d7dd8f197 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -9,4 +9,5 @@ PLUS_API_HOST = "https://api.frigate.video" # Regex Consts REGEX_CAMERA_NAME = "^[a-zA-Z0-9_-]+$" -REGEX_CAMERA_USER_PASS = ":\/\/[a-zA-Z0-9_-]+:[\S]+@" +REGEX_RTSP_CAMERA_USER_PASS = ":\/\/[a-zA-Z0-9_-]+:[\S]+@" +REGEX_HTTP_CAMERA_USER_PASS = "user=[a-zA-Z0-9_-]+&password=[\S]+" diff --git a/frigate/util.py b/frigate/util.py index 05e5fec29..cff8a3f6d 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -20,7 +20,7 @@ import numpy as np import os import psutil -from frigate.const import REGEX_CAMERA_USER_PASS +from frigate.const import REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS logger = logging.getLogger(__name__) @@ -666,14 +666,16 @@ def load_labels(path, encoding="utf-8"): def clean_camera_user_pass(line: str) -> str: """Removes user and password from line.""" - # todo also remove http password like reolink - return re.sub(REGEX_CAMERA_USER_PASS, "://*:*@", line) + if line.startswith("rtsp://"): + return re.sub(REGEX_RTSP_CAMERA_USER_PASS, "://*:*@", line) + else: + return re.sub(REGEX_HTTP_CAMERA_USER_PASS, "user=*&password=*", line) def escape_special_characters(path: str) -> str: """Cleans reserved characters to encodings for ffmpeg.""" try: - found = re.search(REGEX_CAMERA_USER_PASS, path).group(0)[3:-1] + found = re.search(REGEX_RTSP_CAMERA_USER_PASS, path).group(0)[3:-1] pw = found[(found.index(":") + 1) :] return path.replace(pw, urllib.parse.quote_plus(pw)) except AttributeError: