refac: split into modules I
This commit is contained in:
parent
078855ba9a
commit
90b6868f5a
5 changed files with 233 additions and 199 deletions
14
security.py
Normal file
14
security.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue