fix(sender/email): don't log email body, log size instead#285
Merged
Conversation
The verify provider sends one-shot magic-link tokens by email; the
Email sender's debug log dumped the full body verbatim:
[DEBUG] send "Confirmation token: <jwt>" to victim@example.com
Anyone with log access (centralized logging, crash bundles, support
tools, mail-gateway-adjacent observability) could redeem that token
within its TTL — independently of the legitimate recipient. The
verify-replay PR (#281) limits reuse to one consumption, but the
log-reader can still race the user for that one consumption.
Log only the recipient and the body length:
[DEBUG] send 142-byte message to victim@example.com
Same fix in v1 (provider/sender/email.go:84) and v2
(v2/provider/sender/email.go:84), single PR.
Test: TestEmail_SendDoesNotLogBody captures logger output, sends a
known-secret body to a non-existent SMTP host, and asserts the body
substring is absent while the recipient is present. Added in both
modules.
Coverage Report for CI Build 25572603805Coverage increased (+0.4%) to 84.66%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
umputun
approved these changes
May 8, 2026
Member
umputun
left a comment
There was a problem hiding this comment.
lgtm.
one small nit: the new test uses func(format string, args ...interface{}) for the capturing logger, but #283 (just merged) modernized all existing interface{} to any across the codebase. Worth swapping the new test's signature to args ...any here too, otherwise it's a tiny regression on the modernization. Not blocking.
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.
Summary
The verify provider sends one-shot magic-link tokens via email. The Email sender's debug log dumped the full body verbatim:
Anyone with log access (centralized logging, crash bundles, support tools, mail-gateway observability) could redeem that token within its TTL — independently of the legitimate recipient. PR #281 (verify replay) limits reuse to one consumption, but the log reader can still race the user for that one consumption. This PR closes the leak at the source.
Change
Log the recipient and body length only:
Same redaction in v1 (
provider/sender/email.go:84) and v2 (v2/provider/sender/email.go:84), single PR.Test
TestEmail_SendDoesNotLogBodycaptures logger output, sends a known-secret body to a non-existent SMTP host (Send fails fast — that's fine, we only assert on the log line), and verifies:Added in both modules. Full
go test -race ./...green;golangci-lint run --new-from-rev=master0 issues.