feat: define mail connector framework

This commit is contained in:
Christian Krakau-Louis
2026-05-23 15:56:47 +02:00
parent 39cd54eabf
commit c029574717
9 changed files with 403 additions and 88 deletions
+5 -1
View File
@@ -7,11 +7,14 @@ import re
SENSITIVE_VALUE = "**redacted**"
_SENSITIVE_KEY_PATTERN = re.compile(
r"(?i)([\"']?\b(?:access_token|api_key|apikey|authorization|bearer|client_secret|"
r"(?i)([\"']?\b(?:access_token|api_key|apikey|bearer|client_secret|"
r"gmail_client_secret|id_token|passwd|password|refresh_token|secret|token)\b[\"']?"
r"\s*[:=]\s*[\"']?)([^\"'\s,;&}]+)([\"']?)"
)
_BEARER_TOKEN_PATTERN = re.compile(r"(?i)\b(bearer)\s+([A-Za-z0-9._~+/=-]{8,})")
_AUTHORIZATION_BEARER_PATTERN = re.compile(
r"(?i)\b(authorization\s*[:=]\s*bearer)\s+([A-Za-z0-9._~+/=-]{8,})"
)
def sanitize_for_log(value: object) -> str:
@@ -22,5 +25,6 @@ def sanitize_for_log(value: object) -> str:
def redact_sensitive_text(value: object) -> str:
"""Sanitize text and redact common secret-bearing key/value fragments."""
text = sanitize_for_log(value)
text = _AUTHORIZATION_BEARER_PATTERN.sub(r"\1 " + SENSITIVE_VALUE, text)
text = _SENSITIVE_KEY_PATTERN.sub(r"\1" + SENSITIVE_VALUE + r"\3", text)
return _BEARER_TOKEN_PATTERN.sub(r"\1 " + SENSITIVE_VALUE, text)