Clean http passwords too

This commit is contained in:
Nick Mowen 2022-11-26 07:41:13 -07:00
parent 39c8564750
commit 7f93712e73
2 changed files with 8 additions and 5 deletions

View File

@ -9,4 +9,5 @@ PLUS_API_HOST = "https://api.frigate.video"
# Regex Consts # Regex Consts
REGEX_CAMERA_NAME = "^[a-zA-Z0-9_-]+$" 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]+"

View File

@ -20,7 +20,7 @@ import numpy as np
import os import os
import psutil 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__) logger = logging.getLogger(__name__)
@ -666,14 +666,16 @@ def load_labels(path, encoding="utf-8"):
def clean_camera_user_pass(line: str) -> str: def clean_camera_user_pass(line: str) -> str:
"""Removes user and password from line.""" """Removes user and password from line."""
# todo also remove http password like reolink if line.startswith("rtsp://"):
return re.sub(REGEX_CAMERA_USER_PASS, "://*:*@", line) 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: def escape_special_characters(path: str) -> str:
"""Cleans reserved characters to encodings for ffmpeg.""" """Cleans reserved characters to encodings for ffmpeg."""
try: 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) :] pw = found[(found.index(":") + 1) :]
return path.replace(pw, urllib.parse.quote_plus(pw)) return path.replace(pw, urllib.parse.quote_plus(pw))
except AttributeError: except AttributeError: