add check if accessed storage file_id is a uuid and when not send them to a 404 error page
Build and Push Docker Container / build-and-push (push) Successful in 1m31s

This commit is contained in:
2026-01-01 10:29:45 +01:00
parent 9b69069367
commit b7ec488b44
2 changed files with 24 additions and 7 deletions
+19 -6
View File
@@ -1,15 +1,14 @@
from quart import has_request_context, request, has_websocket_context, websocket
from flask_limiter import Limiter
from uuid import UUID
import subprocess, aiohttp
# Get IPs
def get_ip():
if has_request_context():
xff = request.headers.get("X-Forwarded-For", "")
return xff.split(",")[0].strip() if xff else request.remote_addr
elif has_websocket_context():
xff = websocket.headers.get("X-Forwarded-For", "")
return xff.split(",")[0].strip() if xff else websocket.remote_addr
context = get_request_context()
if context:
xff = context.headers.get("X-Forwarded-For", "")
return xff.split(",")[0].strip() if xff else context.remote_addr
return None # No active request or websocket context
async def get_my_ip_address():
@@ -61,3 +60,17 @@ def replace_last_ip_segment(ip:str, new_value:str="1") -> str:
parts[-1] = str(new_value)
return '.'.join(parts)
raise ValueError("Invalid IP address format")
def get_request_context():
if has_request_context():
return request
elif has_websocket_context():
return websocket
return None
def is_valid_uuid(value: str) -> bool:
try:
UUID(value)
return True
except ValueError:
return False