Implement Monlet MVP stack and UI updates
This commit is contained in:
26
server/monlet_server/redaction.py
Normal file
26
server/monlet_server/redaction.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import re
|
||||
|
||||
_PATTERNS: list[tuple[re.Pattern[str], object]] = [
|
||||
(
|
||||
re.compile(r"(?i)(authorization|set-cookie|cookie)([\"'=:]+\s*)([^\r\n]+)"),
|
||||
lambda m: f"{m.group(1)}{m.group(2)}***",
|
||||
),
|
||||
(
|
||||
re.compile(r"(?i)(token|secret|password|api[_-]?key|credential)([\"'=:]+\s*)([^\s\"',;]+)"),
|
||||
lambda m: f"{m.group(1)}{m.group(2)}***",
|
||||
),
|
||||
(re.compile(r"(?i)(bearer)\s+\S+"), r"\1 ***"),
|
||||
]
|
||||
|
||||
|
||||
def redact(value: str | None) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
out = value
|
||||
for pat, repl in _PATTERNS:
|
||||
out = pat.sub(repl, out)
|
||||
return out
|
||||
|
||||
|
||||
def redact_dict(d: dict) -> dict:
|
||||
return {k: redact(v) if isinstance(v, str) else v for k, v in d.items()}
|
||||
Reference in New Issue
Block a user