fixing command injection and path traversal

security fix command injection and path traversal in name_normalize
pull/2486/head
CoderShady 1 day ago committed by GitHub
parent 569f25098a
commit ccae640478
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -68,12 +68,17 @@ class ProgressFfmpeg(threading.Thread):
def name_normalize(name: str) -> str:
name = re.sub(r'[?\\"%*:|<>]', "", name)
name = re.sub(r"( [w,W]\s?\/\s?[o,O,0])", r" without", name)
name = re.sub(r"( [w,W]\s?\/)", r" with", name)
name = re.sub(r"(\d+)\s?\/\s?(\d+)", r"\1 of \2", name)
name = re.sub(r"(\w+)\s?\/\s?(\w+)", r"\1 or \2", name)
name = re.sub(r"\/", r"", name)
# Change: Remove all characters except letters, numbers, spaces, hyphens, and underscores.
# This prevents shell injection ($(command)) and path traversal (../../)
name = re.sub(r'[^\w\s\-_]', '', name)
# Remove leading/trailing spaces to prevent invalid names
name = name.strip()
lang = settings.config["reddit"]["thread"]["post_lang"]
if lang:
@ -84,6 +89,7 @@ def name_normalize(name: str) -> str:
return name
def prepare_background(reddit_id: str, W: int, H: int) -> str:
output_path = f"assets/temp/{reddit_id}/background_noaudio.mp4"
output = (

Loading…
Cancel
Save