Repository navigation
smtpconn: Treat wrapped dial errors as network errors - #874
Merged
Merged
Conversation
Since fd6d880, attemptConnect wraps dial errors as "dialer: %w". wrapClientErr matched *net.OpError with a type switch, so wrapped dial errors fell through to the default case and were reported as permanent "554 5.0.0 Internal server error" instead of "450 4.4.2 Network I/O error". For LMTP this made maddy reject RCPT permanently while the LMTP server was restarting, instead of asking the sender to retry. Look for *net.OpError with errors.As in the default case, so the wrapped error is classified as before while keeping the added context. Fixes foxcpp#872 Signed-off-by: Ahmed Laban <amlaban@outlook.com>
foxcpp
force-pushed
the
smtpconn-dial-error-temporary
branch
from
November 1, 2026 13:19
faa1390 to
1dd7b84
Compare
Owner
|
Rebased onto |
Owner
|
Thanks! |
gabrielcosi
pushed a commit
to gabrielcosi/home-ops
that referenced
this pull request
Nov 5, 2026
…593) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [ghcr.io/foxcpp/maddy](https://maddy.email) ([source](https://github.com/foxcpp/maddy)) | patch | `0.9.6` → `0.9.7` | --- ### Release Notes <details> <summary>foxcpp/maddy (ghcr.io/foxcpp/maddy)</summary> ### [`v0.9.7`](https://github.com/foxcpp/maddy/releases/tag/v0.9.7): [SECURITY] maddy 0.9.7 [Compare Source](foxcpp/maddy@v0.9.6...v0.9.7) ## Summary This release includes fixes for several reported security vulnerabilities with CVSS severity ranging Low to High, including two DMARC verification bypasses. Upgrade is highly recommended. This release fixes several long-standing issues in go-imap-sql implementation. Upgrading is highly recommended for anyone using IMAP implementation. Fixes are fully compatible with 0.9.6 - messages written by 0.9.7 are readable by 0.9.6 as-is and vice versa. Now storage.imapsql can store malformed MIME messages. Such messages are stored as a single-part application/octet-stream message. This can cause display issues with most IMAP clients but no data is lost. ## Security - dmarc: Fix DMARC bypass when the From domain uses mixed case ([GHSA-qh5c-2mrx-4ppj](GHSA-qh5c-2mrx-4ppj), no CVE assigned yet). Messages whose From domain contained uppercase characters could be checked against the wrong organizational domain, so the domain’s published DMARC policy was not applied. An attacker could spoof a domain that publishes `p=reject` or `p=quarantine` and get the message delivered. Affects configurations using inbound SMTP with `dmarc yes` (default). - dmarc: Reject messages without a single valid author domain when DMARC is enabled ([GHSA-fhw2-mvqf-h69c](GHSA-fhw2-mvqf-h69c), not CVE assigned yet) ([#​879](foxcpp/maddy#879)). Messages with a malformed or multiple-address `From` header were treated as having no DMARC policy and accepted, allowing an attacker to bypass DMARC by deliberately breaking the `From` header. The new `dmarc_reject_invalid_from` option controls this behavior; it is enabled in the new default configuration, while existing deployments must enable it explicitly. Affects configurations using inbound SMTP with `dmarc yes` (default). - auth/ldap: Hide whether an LDAP username exists ([GHSA-88mq-x5xv-cmrh](GHSA-88mq-x5xv-cmrh); no CVE assigned yet) ([#​880](foxcpp/maddy#880)). Unknown usernames previously caused fewer LDAP operations than existing usernames, allowing unauthenticated clients to enumerate valid accounts through timing differences. This can aid targeted phishing and credential-stuffing attacks. Affects all configurations using `auth.ldap`. - proxy_protocol: Trust only the configured host for bare IPv6 addresses ([GHSA-58jf-c377-6r8w](GHSA-58jf-c377-6r8w); no CVE assigned yet) ([#​884](foxcpp/maddy#884)). A bare IPv6 address in the `proxy_protocol` trust list was treated as a /32 network, trusting unrelated IPv6 peers in the same range. A directly connected attacker could forge PROXY headers to choose the client IP seen by SMTP/IMAP, bypassing rate limits and DNSBL checks and falsifying audit logs. Affects configurations using `proxy_protocol` on a public-facing endpoints (not recommended in general). - limits: Fix a panic when source rate limits are exhausted without IP limits ([GHSA-wcj3-m6rw-7gv9](GHSA-wcj3-m6rw-7gv9); no CVE assigned yet). With a `source` limit but no `ip` limit, exhausting the source bucket set made the cleanup path dereference a nil IP limiter. A remote sender could trigger a nil-pointer panic, disrupting message acceptance on the affected SMTP endpoint. ## Bug fixes - endpoint/smtp: Replace an invalid `Date` header with a valid value instead of rejecting the message during submission preparation ([#​518](foxcpp/maddy#518)). - endpoint/smtp: Recognize wrapped SMTP errors so oversized messages are reported as "message too large" instead of "internal server error" ([#​772](foxcpp/maddy#772)). - endpoint/smtp: Only clean up session state after a successful commit and abort failed deliveries, preventing stuck deliveries and spurious "database is locked" errors ([#​786](foxcpp/maddy#786)). - endpoint/smtp: Fix a shutdown race that could deadlock the server when a client connected while the endpoint was stopping. - endpoint/smtp: Export the `maddy_smtp_failed_logins` metric and count failed AUTH attempts for every SASL mechanism ([#​868](foxcpp/maddy#868)). - smtpconn: Treat wrapped dial errors as temporary network errors, so an unavailable LMTP server produces a retryable `450` response instead of a permanent `554` ([#​872](foxcpp/maddy#872)) (PR [#​874](foxcpp/maddy#874), thanks [@​amlaban65](https://github.com/amlaban65)). - storage/imapsql: Fix `APPENDLIMIT` reporting: `STATUS` now returns the effective per-mailbox limit, the capability is advertised without a value, and disabling the limit is rejected instead of making clients see a zero limit incorrectly ([#​788](foxcpp/maddy#788)). - storage/imapsql: Avoid holding a DB write transaction for the whole delivery and clean up staged messages on failure, reducing “database is locked” errors with concurrent deliveries and `reroute` ([#​786](foxcpp/maddy#786)). - storage/imapsql: Treat interrupted deliveries and serialization failures as temporary errors so the sender retries instead of the message being lost. - storage/imapsql: Fix `SEARCH UNSEEN` returning flags from other mailboxes and missing unseen messages, and fix delivery ignoring the `\Seen` flag set by IMAP filters ([#​591](foxcpp/maddy#591)). - storage/imapsql: Fix compound SEARCH queries with multiple excluded flags, which caused fetchmail to re-download already seen messages ([#​703](foxcpp/maddy#703)). - storage/imapsql: Report messages without `Content-Transfer-Encoding` as 7BIT in BODYSTRUCTURE instead of an invalid NIL value, fixing display in some IMAP clients ([#​756](foxcpp/maddy#756)). - storage/imapsql: Accept and store messages with malformed MIME structure instead of failing delivery ([#​466](foxcpp/maddy#466)). - storage/imapsql: Reject attempts to move a mailbox into itself. - storage/imapsql: Fix a missing transaction commit that left message flags, such as read/unread state, stale ([#​712](foxcpp/maddy#712)). - target/queue: Fix truncated exponential retry delays so queued mail follows the documented `5min × 1.25^(n−1)` schedule ([#​678](foxcpp/maddy#678)). - target/queue: Reduce default `initial_retry_time` to 5m from 15m, add missing documentation for delay configuration ([#​678](foxcpp/maddy#678)). - target/remote: Fix a panic when checking MTA-STS policies for internationalized (IDNA) domains. - modify/replace_addr: Apply relative aliases even when the exact address lookup returns the address unchanged ([#​734](foxcpp/maddy#734)) (PR [#​871](foxcpp/maddy#871), thanks [@​mvanhorn](https://github.com/mvanhorn)). - log: Make `maddy version` and the server startup log report the same version, including custom builds ([#​869](foxcpp/maddy#869)) (PR [#​870](foxcpp/maddy#870), thanks [@​MFAshby](https://github.com/MFAshby)). - auth/dovecot_sasl, endpoint/dovecot_sasld: Fix user ID parsing, formatting and escaping in the Dovecot authentication protocol; the auth server now passes the authenticated user ID back to Dovecot. - libdns/hetzner: Update to the new Hetzner DNS API; the old API no longer works ([#​807](foxcpp/maddy#807)). ## Improvements - dns: Reload `/etc/resolv.conf` when it changes (checked at most every five seconds), so DNS changes from network reconfiguration take effect without restarting maddy ([#​475](foxcpp/maddy#475)). - target/remote: Log MX/TLS policy decisions at normal log level, including policy names, effective security levels and rejection reasons, making outbound delivery issues easier to diagnose ([#​717](foxcpp/maddy#717)). - libdns: Update DNS provider integrations to libdns 1.1 and their latest releases; leaseweb and gandi use forks upgraded to libdns 1.1, outdates deprecation warnings were removed. - Dockerfile: Add `bash` to the image so the `command` system filter can be used in container deployments (PR [#​851](foxcpp/maddy#851), thanks [@​terminar](https://github.com/terminar)). ## Documentation - tls: Clarify the actual default TLS versions and cipher suites, their dependence on the Go version, and how to re-enable legacy ciphers for older servers ([#​702](foxcpp/maddy#702), [#​789](foxcpp/maddy#789)). - maddy.conf: Point new users to an example aliases file for the `(aliases)` file table syntax ([#​684](foxcpp/maddy#684)) (PR [#​729](foxcpp/maddy#729), thanks [@​stellarpower](https://github.com/stellarpower)). ## Misc - table: Fix data races in file table reload tests. - tests: Add a fetchmail interoperability integration test. - lint: Clean up linter findings in `auth/pam`, `endpoint/dovecot_sasld`, `endpoint/imap` and queue tests. </details> --- ### Configuration 📅 **Schedule**: (in timezone Europe/Berlin) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xOTguMyIsInVwZGF0ZWRJblZlciI6IjQ0LjE5OC4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.xcd.dev/gabrielcosi/home-ops/pulls/1593
eleboucher
pushed a commit
to eleboucher/homelab
that referenced
this pull request
Nov 6, 2026
…552) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [ghcr.io/foxcpp/maddy](https://maddy.email) ([source](https://github.com/foxcpp/maddy)) | patch | `0.9.6` → `0.9.7` | --- ### Release Notes <details> <summary>foxcpp/maddy (ghcr.io/foxcpp/maddy)</summary> ### [`v0.9.7`](https://github.com/foxcpp/maddy/releases/tag/v0.9.7): [SECURITY] maddy 0.9.7 [Compare Source](foxcpp/maddy@v0.9.6...v0.9.7) ## Summary This release includes fixes for several reported security vulnerabilities with CVSS severity ranging Low to High, including two DMARC verification bypasses. Upgrade is highly recommended. This release fixes several long-standing issues in go-imap-sql implementation. Upgrading is highly recommended for anyone using IMAP implementation. Fixes are fully compatible with 0.9.6 - messages written by 0.9.7 are readable by 0.9.6 as-is and vice versa. Now storage.imapsql can store malformed MIME messages. Such messages are stored as a single-part application/octet-stream message. This can cause display issues with most IMAP clients but no data is lost. ## Security - dmarc: Fix DMARC bypass when the From domain uses mixed case ([GHSA-qh5c-2mrx-4ppj](GHSA-qh5c-2mrx-4ppj), no CVE assigned yet). Messages whose From domain contained uppercase characters could be checked against the wrong organizational domain, so the domain’s published DMARC policy was not applied. An attacker could spoof a domain that publishes `p=reject` or `p=quarantine` and get the message delivered. Affects configurations using inbound SMTP with `dmarc yes` (default). - dmarc: Reject messages without a single valid author domain when DMARC is enabled ([GHSA-fhw2-mvqf-h69c](GHSA-fhw2-mvqf-h69c), not CVE assigned yet) ([#​879](foxcpp/maddy#879)). Messages with a malformed or multiple-address `From` header were treated as having no DMARC policy and accepted, allowing an attacker to bypass DMARC by deliberately breaking the `From` header. The new `dmarc_reject_invalid_from` option controls this behavior; it is enabled in the new default configuration, while existing deployments must enable it explicitly. Affects configurations using inbound SMTP with `dmarc yes` (default). - auth/ldap: Hide whether an LDAP username exists ([GHSA-88mq-x5xv-cmrh](GHSA-88mq-x5xv-cmrh); no CVE assigned yet) ([#​880](foxcpp/maddy#880)). Unknown usernames previously caused fewer LDAP operations than existing usernames, allowing unauthenticated clients to enumerate valid accounts through timing differences. This can aid targeted phishing and credential-stuffing attacks. Affects all configurations using `auth.ldap`. - proxy_protocol: Trust only the configured host for bare IPv6 addresses ([GHSA-58jf-c377-6r8w](GHSA-58jf-c377-6r8w); no CVE assigned yet) ([#​884](foxcpp/maddy#884)). A bare IPv6 address in the `proxy_protocol` trust list was treated as a /32 network, trusting unrelated IPv6 peers in the same range. A directly connected attacker could forge PROXY headers to choose the client IP seen by SMTP/IMAP, bypassing rate limits and DNSBL checks and falsifying audit logs. Affects configurations using `proxy_protocol` on a public-facing endpoints (not recommended in general). - limits: Fix a panic when source rate limits are exhausted without IP limits ([GHSA-wcj3-m6rw-7gv9](GHSA-wcj3-m6rw-7gv9); no CVE assigned yet). With a `source` limit but no `ip` limit, exhausting the source bucket set made the cleanup path dereference a nil IP limiter. A remote sender could trigger a nil-pointer panic, disrupting message acceptance on the affected SMTP endpoint. ## Bug fixes - endpoint/smtp: Replace an invalid `Date` header with a valid value instead of rejecting the message during submission preparation ([#​518](foxcpp/maddy#518)). - endpoint/smtp: Recognize wrapped SMTP errors so oversized messages are reported as "message too large" instead of "internal server error" ([#​772](foxcpp/maddy#772)). - endpoint/smtp: Only clean up session state after a successful commit and abort failed deliveries, preventing stuck deliveries and spurious "database is locked" errors ([#​786](foxcpp/maddy#786)). - endpoint/smtp: Fix a shutdown race that could deadlock the server when a client connected while the endpoint was stopping. - endpoint/smtp: Export the `maddy_smtp_failed_logins` metric and count failed AUTH attempts for every SASL mechanism ([#​868](foxcpp/maddy#868)). - smtpconn: Treat wrapped dial errors as temporary network errors, so an unavailable LMTP server produces a retryable `450` response instead of a permanent `554` ([#​872](foxcpp/maddy#872)) (PR [#​874](foxcpp/maddy#874), thanks [@​amlaban65](https://github.com/amlaban65)). - storage/imapsql: Fix `APPENDLIMIT` reporting: `STATUS` now returns the effective per-mailbox limit, the capability is advertised without a value, and disabling the limit is rejected instead of making clients see a zero limit incorrectly ([#​788](foxcpp/maddy#788)). - storage/imapsql: Avoid holding a DB write transaction for the whole delivery and clean up staged messages on failure, reducing “database is locked” errors with concurrent deliveries and `reroute` ([#​786](foxcpp/maddy#786)). - storage/imapsql: Treat interrupted deliveries and serialization failures as temporary errors so the sender retries instead of the message being lost. - storage/imapsql: Fix `SEARCH UNSEEN` returning flags from other mailboxes and missing unseen messages, and fix delivery ignoring the `\Seen` flag set by IMAP filters ([#​591](foxcpp/maddy#591)). - storage/imapsql: Fix compound SEARCH queries with multiple excluded flags, which caused fetchmail to re-download already seen messages ([#​703](foxcpp/maddy#703)). - storage/imapsql: Report messages without `Content-Transfer-Encoding` as 7BIT in BODYSTRUCTURE instead of an invalid NIL value, fixing display in some IMAP clients ([#​756](foxcpp/maddy#756)). - storage/imapsql: Accept and store messages with malformed MIME structure instead of failing delivery ([#​466](foxcpp/maddy#466)). - storage/imapsql: Reject attempts to move a mailbox into itself. - storage/imapsql: Fix a missing transaction commit that left message flags, such as read/unread state, stale ([#​712](foxcpp/maddy#712)). - target/queue: Fix truncated exponential retry delays so queued mail follows the documented `5min × 1.25^(n−1)` schedule ([#​678](foxcpp/maddy#678)). - target/queue: Reduce default `initial_retry_time` to 5m from 15m, add missing documentation for delay configuration ([#​678](foxcpp/maddy#678)). - target/remote: Fix a panic when checking MTA-STS policies for internationalized (IDNA) domains. - modify/replace_addr: Apply relative aliases even when the exact address lookup returns the address unchanged ([#​734](foxcpp/maddy#734)) (PR [#​871](foxcpp/maddy#871), thanks [@​mvanhorn](https://github.com/mvanhorn)). - log: Make `maddy version` and the server startup log report the same version, including custom builds ([#​869](foxcpp/maddy#869)) (PR [#​870](foxcpp/maddy#870), thanks [@​MFAshby](https://github.com/MFAshby)). - auth/dovecot_sasl, endpoint/dovecot_sasld: Fix user ID parsing, formatting and escaping in the Dovecot authentication protocol; the auth server now passes the authenticated user ID back to Dovecot. - libdns/hetzner: Update to the new Hetzner DNS API; the old API no longer works ([#​807](foxcpp/maddy#807)). ## Improvements - dns: Reload `/etc/resolv.conf` when it changes (checked at most every five seconds), so DNS changes from network reconfiguration take effect without restarting maddy ([#​475](foxcpp/maddy#475)). - target/remote: Log MX/TLS policy decisions at normal log level, including policy names, effective security levels and rejection reasons, making outbound delivery issues easier to diagnose ([#​717](foxcpp/maddy#717)). - libdns: Update DNS provider integrations to libdns 1.1 and their latest releases; leaseweb and gandi use forks upgraded to libdns 1.1, outdates deprecation warnings were removed. - Dockerfile: Add `bash` to the image so the `command` system filter can be used in container deployments (PR [#​851](foxcpp/maddy#851), thanks [@​terminar](https://github.com/terminar)). ## Documentation - tls: Clarify the actual default TLS versions and cipher suites, their dependence on the Go version, and how to re-enable legacy ciphers for older servers ([#​702](foxcpp/maddy#702), [#​789](foxcpp/maddy#789)). - maddy.conf: Point new users to an example aliases file for the `(aliases)` file table syntax ([#​684](foxcpp/maddy#684)) (PR [#​729](foxcpp/maddy#729), thanks [@​stellarpower](https://github.com/stellarpower)). ## Misc - table: Fix data races in file table reload tests. - tests: Add a fetchmail interoperability integration test. - lint: Clean up linter findings in `auth/pam`, `endpoint/dovecot_sasld`, `endpoint/imap` and queue tests. </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xOTkuMiIsInVwZGF0ZWRJblZlciI6IjQ0LjE5OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/2552
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.
Fixes #872
Problem
Since fd6d880,
attemptConnectwraps dial errors asfmt.Errorf("dialer: %w", err).wrapClientErrrecognizes network errors with a type switch on*net.OpError, so a wrapped dial error now falls through to thedefaultcase. It is no longer turned into450 4.4.2 Network I/O errorand ends up as a permanent554 5.0.0 Internal server error. With an LMTP target, maddy rejected RCPT permanently while the LMTP server was restarting, instead of asking the sender to retry.Change
defaultcase ofwrapClientErr, look for a*net.OpErrorwitherrors.As.*net.OpErrorhandling into a smallwrapNetErrhelper, used for both the direct and the wrapped case. The returnedSMTPErrorkeeps the full error (including thedialer:context) inErr. The codes and messages are unchanged.Testing
TestConnectRefusedininternal/smtpconn. It dials a closed local port with bothConnectandConnectLMTPand checks for a temporary450 4.4.2SMTPError. It fails ondevwithout the fix (the error comes back asexterrors.fieldsWrap: dialer: dial tcp ...: connection refused) and passes with it.go test ./internal/smtpconn/... ./internal/target/smtp/ ./internal/target/remote/passes.gofmtandgo vet ./internal/smtpconn/are clean.tests/. Locally I used Go 1.25.1 with a temporary modfile (go.mod asks for 1.26), so CI is the check on the real toolchain.