refac: split into modules I

This commit is contained in:
Alpha Nerd 2026-05-19 10:05:27 +02:00
parent 078855ba9a
commit 90b6868f5a
Signed by: alpha-nerd
SSH key fingerprint: SHA256:QkkAgVoYi9TQ0UKPkiKSfnerZy2h4qhi3SVPXJmBN+M
5 changed files with 233 additions and 199 deletions

14
security.py Normal file
View file

@ -0,0 +1,14 @@
"""Secret-masking helpers used when logging or surfacing backend errors."""
import re
def _mask_secrets(text: str) -> str:
"""
Mask common API key patterns to avoid leaking secrets in logs or error payloads.
"""
if not text:
return text
# OpenAI-style keys (sk-...) and generic "api key" mentions
text = re.sub(r"sk-[A-Za-z0-9]{4}[A-Za-z0-9_-]*", "sk-***redacted***", text)
text = re.sub(r"(?i)(api[-_ ]key\s*[:=]\s*)([^\s]+)", r"\1***redacted***", text)
return text