Skip to content

Adds an optional log_dns_record configuration key (default 0) to the - #182

Open
pacellig wants to merge 1 commit into
fastmail:masterfrom
pacellig:feat/log_dns_records
Open

Adds an optional log_dns_record configuration key (default 0) to the#182
pacellig wants to merge 1 commit into
fastmail:masterfrom
pacellig:feat/log_dns_records

Conversation

@pacellig

@pacellig pacellig commented Aug 4, 2026

Copy link
Copy Markdown

SPF, DKIM and DMARC handlers. When enabled, each handler performs one additional DNS TXT lookup after the authentication check and appends the raw record content as a comment node to the Authentication-Results entry:

Authentication-Results: mail.example.com;
  spf=softfail smtp.mailfrom=sender@example.com
        (x-dns-record=v=spf1 redirect=_spf.google.com);
  dmarc=fail policy.applied-disposition=none header.from=example.com
        (x-dns-record=v=DMARC1; p=reject; rua=mailto:dmarc@example.com)

Comment nodes are permitted by RFC 8601 and are ignored by standards-compliant downstream parsers and mail clients.

When investigating authentication failures it is useful to see the actual DNS policy that drove the decision without having to perform a manual DNS lookup. This is particularly valuable in automated processing pipelines where the raw record is needed alongside the authentication result.

  • The DNS lookup uses the handler's existing get_object('resolver') mechanism, so it respects any mock resolver configured in tests.
  • Failures (NXDOMAIN, timeout, resolver error) are caught with eval and forwarded to handle_exception — they never affect the authentication result or cause the milter to tempfail.
  • The option defaults to 0 so there is no behaviour change for existing deployments.
  • One extra DNS round-trip per enabled handler per message when the option is on.

SPF, DKIM and DMARC handlers. When enabled, each handler performs one
additional DNS TXT lookup after the authentication check and appends the
raw record content as a comment node to the Authentication-Results entry:

Authentication-Results: mail.example.com;
  spf=softfail smtp.mailfrom=sender@example.com
        (x-dns-record=v=spf1 redirect=_spf.google.com);
  dmarc=fail policy.applied-disposition=none header.from=example.com
        (x-dns-record=v=DMARC1; p=reject; rua=mailto:dmarc@example.com)

Comment nodes are permitted by RFC 8601 and are ignored by
standards-compliant downstream parsers and mail clients.

When investigating authentication failures it is useful to see the actual
DNS policy that drove the decision without having to perform a manual DNS
lookup. This is particularly valuable in automated processing pipelines
where the raw record is needed alongside the authentication result.

- The DNS lookup uses the handler's existing get_object('resolver')
  mechanism, so it respects any mock resolver configured in tests.
- Failures (NXDOMAIN, timeout, resolver error) are caught with eval
  and forwarded to handle_exception — they never affect the
  authentication result or cause the milter to tempfail.
- The option defaults to 0 so there is no behaviour change for existing
  deployments.
- One extra DNS round-trip per enabled handler per message when the
  option is on.

| File | Change |
|---|---|
| lib/Mail/Milter/Authentication/Handler/SPF.pm | log_dns_record option: default_config, lookup block, pod docs |
| lib/Mail/Milter/Authentication/Handler/DKIM.pm | Same |
| lib/Mail/Milter/Authentication/Handler/DMARC.pm | Same |
| share/authentication_milter.json | Add "log_dns_record": 0 to SPF, DKIM, DMARC sections |
| t/04-unit-handler-log-dns-record.t | New — 6 subtests (3 handlers × enabled/disabled) |
@pacellig
pacellig marked this pull request as ready for review August 4, 2026 10:51
@pacellig

pacellig commented Aug 4, 2026

Copy link
Copy Markdown
Author

@notbrokenjemma would appreciate a review when you have a moment, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant