Repository navigation
logsafe: redact() masks e-mail addresses; anchor the quadratic URL-password rule - #28
Merged
Merged
Conversation
mask_email() existed, but only remote.py's Access denial used it (by hand), so an e-mail address anywhere else in a log line survived: a library's error message, a repr of a config, MCP_ALLOWED_EMAILS logged at debug. redact() now masks every address it finds the way mask_email() does: the first character of the local part, then ***, and the domain kept (it tells which IdP). It is an identifier rule, like IPs and MACs, not a secret: with --no-redact / <NAME>_LOG_UNREDACTED=1 addresses show. Left alone, each with a test: URL userinfo (ssh://git@host, https://user@host; mqtt://user:pass@host is still _URL_PASSWORD's), scp-style git remotes (git@github.com:owner/repo), decorators in tracebacks, a JWT next to an @ (it is already [jwt redacted]), base64 padding before an @, and "domains" without a letters-only TLD (user@localhost, admin@192.0.2.5:22). redact() stays idempotent: the masked local part "u***" can't match again. Property tests (skipped where hypothesis isn't installed, as in the siblings): no local part longer than one character survives, and the rule is idempotent over an @/./:-heavy alphabet; the existing idempotence test's alphabet gains +, _ and *. Possessive quantifiers keep the rule linear on long tokens. Default log output changes for all 9 siblings: an address that used to show in full now shows as u***@Domain. Nothing else changes; no sibling test asserts an unmasked address in a redacted log line. Refs #16 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a flaky property test
_URL_PASSWORD began with an unanchored \w+, so on a long run of word
characters with no "://" (a hex dump, a base64 blob) the engine rescanned
from every offset: 0.8 s for 20 KB, 20 s for 100 KB, 78 s for 200 KB.
Logging is synchronous on the event loop, so one such debug line stalls the
server. It now starts only at a word boundary (?<!\w) and the scheme is
possessive; what it matches is unchanged (a later start inside the same word
reaches the same "://" or fails the same way). Every other rule was timed on
the same shapes and is linear. New test: four 100 KB blobs redact in < 2 s
(the old rule fails three of them).
test_no_ipv6_survives_redact failed when hypothesis drew an address with a
dotted 0.x/127.x tail ("::ffff:0.0.0.1"): the IPv4 rule keeps those tails on
purpose, as it keeps bare 0.x/127.x. The test now assumes them away, as
test_no_ipv4_survives_redact already does. Pre-existing on main.
Refs #16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 10, 2026
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #16 (the open item "e-mail masking as a general
redact()identifier rule").Non-breaking, but it changes default log output in all 9 siblings: an e-mail address that used to appear in full now appears as
u***@example.com.1. E-mail rule (d1a68f6)
mask_email()existed, but nothing applied it outsideremote.py's Access denial.redact()now masks every address the waymask_email()does: the first character of the local part,***, and the domain kept, since the domain says which IdP.It is an identifier rule (like IPs and MACs), not a secret. With
--no-redact/<NAME>_LOG_UNREDACTED=1, addresses show.redact_secrets()is unchanged.denied: user@example.comdenied: u***@example.comMCP_ALLOWED_EMAILS=a@example.com,bob@example.com…=a***@example.com,b***@example.commqtt://user:hunter2@broker.example.commqtt://user:***@broker.example.com(_URL_PASSWORD, unchanged)ssh://git@git.example.com/x,https://user@example.com/://)git@github.com:owner/repo.git:+ non-space after the domain = scp remote)@app.route(...),@functools.wraps(fn)eyJ….…@example.com[jwt redacted]@example.com(the JWT rule runs first)dGVzdA==@example.com,user@localhost,admin@192.0.2.5:22@; no letters-only TLD)u***can't match again.skipif), notpytest.importorskip. A module-levelimportorskipwould skip the whole file in siblings, which don't install hypothesis. The new tests check that no local part longer than one character survives (st.emails()) and that the rule is idempotent over an@./:-heavy alphabet. The existing idempotence alphabet gains+_*.remote.py's denial comment is updated. It still masks by hand because shared modules can't import each other.2. Found while testing:
_URL_PASSWORDwas quadratic (cd092c0)_URL_PASSWORDstarted with an unanchored\w+, so on a long word with no://(a hex dump, a base64 blob) the engine rescanned from every offset. A 100 KB blob took 20 s, and 200 KB took 78 s. Logging is synchronous on the event loop, so one such debug line stalls the server.The rule now starts only at a word boundary (
(?<!\w), possessive scheme). What it matches is unchanged. I timed every logsafe rule over 23 token shapes × 6 tails at 20 KB, and this was the only slow one. New test: four 100 KB blobs must redact in < 2 s. The old rule fails three of them, taking 68 s in total.The same commit fixes a flaky property test that was already on main.
test_no_ipv6_survives_redactfailed whenever hypothesis drew::ffff:0.0.0.1-style addresses, whose 0.x/127.x tail is kept on purpose. The test now makes the same assumptiontest_no_ipv4_survives_redactalready does.Checks
345 passed; coverage 99%;
ruff check/ruff format --checkclean, including--no-respect-gitignore tests; mypy clean.🤖 Generated with Claude Code