privacy: redact member emails from portal logs (audit M1)
The _RedactWebhookPath filter now also strips email-shaped strings from every log record — messages, %-format args (recursing into tuple/list/ dict args), and any exception text already attached to the record — the same retention discipline the webhook token got in ops/security#2. _send_email recipients, listmonk failures, Loomio invite lists and provisioning/credit lines carry member addresses into container logs, which persist on the host and ride the backups. MXIDs, counts, slugs and amounts stay readable; the daily digest's own sanitisation is unchanged. Filter keeps its never-break-logging guarantee (all redaction inside try/except; non-string args untouched). Live pre-state measured: 99 email-bearing lines in the current app log.
This commit is contained in:
1 parent
2b501b75be
commit
d63f702ec3
2 files changed
+97
-6
No files matched your search
@@ -205,5 +205,61 @@ try:
|
||||
finally:
|
||||
urllib.request.urlopen = _real_urlopen
|
||||
|
||||
# ------------------------------------------------------- M1: log redaction ---
|
||||
# The webhook token and member emails must not survive into portal logs. The
|
||||
# guard must FIRE: feed a record with both a token and an email and read back
|
||||
# the formatted line.
|
||||
import logging # noqa: E402
|
||||
|
||||
from app.main import _EMAIL_RE, _RedactWebhookPath # noqa: E402
|
||||
|
||||
flt = _RedactWebhookPath()
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1,
|
||||
"Credit pack: +%s for %s (balance %s)", (20.0, "member@example.org", 30.0), None)
|
||||
flt.filter(rec)
|
||||
check("email in %-args redacted", rec.getMessage(), "Credit pack: +20.0 for <email> (balance 30.0)")
|
||||
check("argument tuple preserved", isinstance(rec.args, tuple), True)
|
||||
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1,
|
||||
"Provisioned member hidden@example.org ok", (), None)
|
||||
flt.filter(rec)
|
||||
check("email embedded via f-string (msg) redacted", rec.getMessage(), "Provisioned member <email> ok")
|
||||
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1, "Loomio invites: %s",
|
||||
(["a@example.org", "b@example.org"],), None)
|
||||
flt.filter(rec)
|
||||
check("list args redacted, list type kept",
|
||||
(rec.getMessage(), type(rec.args[0]).__name__), ("Loomio invites: ['<email>', '<email>']", "list"))
|
||||
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1,
|
||||
'POST /webhook/opencollective/sekret123?x=1 HTTP/1.1', (), None)
|
||||
filt_result = flt.filter(rec)
|
||||
check("webhook token redacted, filter returns True",
|
||||
(rec.getMessage(), filt_result), ("POST /webhook/opencollective/<redacted>?x=1 HTTP/1.1", True))
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1,
|
||||
"Credit pack for member@example.org via /webhook/opencollective/tok9", (), None)
|
||||
flt.filter(rec)
|
||||
check("token and email redacted in one line",
|
||||
"<email>" in rec.getMessage() and "<redacted>" in rec.getMessage()
|
||||
and "member@example.org" not in rec.getMessage() and "tok9" not in rec.getMessage(), True)
|
||||
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1, "Matrix invite for @someuser:inference.coop", (), None)
|
||||
flt.filter(rec)
|
||||
check("MXIDs are not emails and stay readable",
|
||||
rec.getMessage(), "Matrix invite for @someuser:inference.coop")
|
||||
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1, "counter=%d", (7,), None)
|
||||
flt.filter(rec)
|
||||
check("non-string args untouched", rec.getMessage(), "counter=7")
|
||||
|
||||
rec = logging.LogRecord("t", logging.INFO, "p", 1, "boom", (), None)
|
||||
rec.exc_text = "ValueError: No member account for lost@example.org"
|
||||
flt.filter(rec)
|
||||
check("already-formatted exception text redacted",
|
||||
rec.exc_text, "ValueError: No member account for <email>")
|
||||
|
||||
check("regex matches a real-shaped address",
|
||||
bool(_EMAIL_RE.search("contact info@a.b-stuff.coop today")), True)
|
||||
|
||||
print(f"\n{'FAILED' if failures else 'OK'} — {failures} failure(s)")
|
||||
sys.exit(1 if failures else 0)
|
||||
Reference in new issue
Block a user