Skip to content

smtpconn: Treat wrapped dial errors as network errors - #874

Merged
foxcpp merged 1 commit into
foxcpp:masterfrom
amlaban65:smtpconn-dial-error-temporary
Nov 1, 2026
Merged

foxcpp merged 1 commit into
foxcpp:masterfrom
amlaban65:smtpconn-dial-error-temporary

Conversation

@amlaban65

Copy link
Copy Markdown
Contributor

Fixes #872

Problem

Since fd6d880, attemptConnect wraps dial errors as fmt.Errorf("dialer: %w", err). wrapClientErr recognizes network errors with a type switch on *net.OpError, so a wrapped dial error now falls through to the default case. It is no longer turned into 450 4.4.2 Network I/O error and ends up as a permanent 554 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

  • In the default case of wrapClientErr, look for a *net.OpError with errors.As.
  • Move the existing *net.OpError handling into a small wrapNetErr helper, used for both the direct and the wrapped case. The returned SMTPError keeps the full error (including the dialer: context) in Err. The codes and messages are unchanged.

Testing

  • Added TestConnectRefused in internal/smtpconn. It dials a closed local port with both Connect and ConnectLMTP and checks for a temporary 450 4.4.2 SMTPError. It fails on dev without the fix (the error comes back as exterrors.fieldsWrap: dialer: dial tcp ...: connection refused) and passes with it.
  • go test ./internal/smtpconn/... ./internal/target/smtp/ ./internal/target/remote/ passes. gofmt and go vet ./internal/smtpconn/ are clean.
  • I did not run the full test suite or the integration tests in 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.

@foxcpp
foxcpp changed the base branch from dev to master November 1, 2026 13:12
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
foxcpp force-pushed the smtpconn-dial-error-temporary branch from faa1390 to 1dd7b84 Compare November 1, 2026 13:19
@foxcpp

foxcpp commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Rebased onto master. Bugfix PRs should be created into master, not dev.

@foxcpp
foxcpp merged commit 707eac7 into foxcpp:master Nov 1, 2026
3 checks passed
@foxcpp

foxcpp commented Nov 1, 2026

Copy link
Copy Markdown
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) ([#&#8203;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) ([#&#8203;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) ([#&#8203;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 ([#&#8203;518](foxcpp/maddy#518)).
- endpoint/smtp: Recognize wrapped SMTP errors so oversized messages are
  reported as "message too large" instead of "internal server error" ([#&#8203;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 ([#&#8203;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 ([#&#8203;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` ([#&#8203;872](foxcpp/maddy#872)) (PR [#&#8203;874](foxcpp/maddy#874), thanks [@&#8203;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 ([#&#8203;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` ([#&#8203;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 ([#&#8203;591](foxcpp/maddy#591)).
- storage/imapsql: Fix compound SEARCH queries with multiple excluded flags,
  which caused fetchmail to re-download already seen messages ([#&#8203;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 ([#&#8203;756](foxcpp/maddy#756)).
- storage/imapsql: Accept and store messages with malformed MIME structure
  instead of failing delivery ([#&#8203;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 ([#&#8203;712](foxcpp/maddy#712)).
- target/queue: Fix truncated exponential retry delays so queued mail follows
  the documented `5min × 1.25^(n−1)` schedule ([#&#8203;678](foxcpp/maddy#678)).
- target/queue: Reduce default `initial_retry_time` to 5m from 15m, add missing
  documentation for delay configuration ([#&#8203;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 ([#&#8203;734](foxcpp/maddy#734)) (PR [#&#8203;871](foxcpp/maddy#871), thanks [@&#8203;mvanhorn](https://github.com/mvanhorn)).
- log: Make `maddy version` and the server startup log report the same version,
  including custom builds ([#&#8203;869](foxcpp/maddy#869)) (PR [#&#8203;870](foxcpp/maddy#870), thanks [@&#8203;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 ([#&#8203;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 ([#&#8203;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 ([#&#8203;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 [#&#8203;851](foxcpp/maddy#851), thanks [@&#8203;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 ([#&#8203;702](foxcpp/maddy#702), [#&#8203;789](foxcpp/maddy#789)).
- maddy.conf: Point new users to an example aliases file for the `(aliases)`
  file table syntax ([#&#8203;684](foxcpp/maddy#684)) (PR [#&#8203;729](foxcpp/maddy#729), thanks [@&#8203;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) ([#&#8203;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) ([#&#8203;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) ([#&#8203;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 ([#&#8203;518](foxcpp/maddy#518)).
- endpoint/smtp: Recognize wrapped SMTP errors so oversized messages are
  reported as "message too large" instead of "internal server error" ([#&#8203;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 ([#&#8203;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 ([#&#8203;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` ([#&#8203;872](foxcpp/maddy#872)) (PR [#&#8203;874](foxcpp/maddy#874), thanks [@&#8203;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 ([#&#8203;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` ([#&#8203;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 ([#&#8203;591](foxcpp/maddy#591)).
- storage/imapsql: Fix compound SEARCH queries with multiple excluded flags,
  which caused fetchmail to re-download already seen messages ([#&#8203;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 ([#&#8203;756](foxcpp/maddy#756)).
- storage/imapsql: Accept and store messages with malformed MIME structure
  instead of failing delivery ([#&#8203;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 ([#&#8203;712](foxcpp/maddy#712)).
- target/queue: Fix truncated exponential retry delays so queued mail follows
  the documented `5min × 1.25^(n−1)` schedule ([#&#8203;678](foxcpp/maddy#678)).
- target/queue: Reduce default `initial_retry_time` to 5m from 15m, add missing
  documentation for delay configuration ([#&#8203;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 ([#&#8203;734](foxcpp/maddy#734)) (PR [#&#8203;871](foxcpp/maddy#871), thanks [@&#8203;mvanhorn](https://github.com/mvanhorn)).
- log: Make `maddy version` and the server startup log report the same version,
  including custom builds ([#&#8203;869](foxcpp/maddy#869)) (PR [#&#8203;870](foxcpp/maddy#870), thanks [@&#8203;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 ([#&#8203;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 ([#&#8203;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 ([#&#8203;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 [#&#8203;851](foxcpp/maddy#851), thanks [@&#8203;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 ([#&#8203;702](foxcpp/maddy#702), [#&#8203;789](foxcpp/maddy#789)).
- maddy.conf: Point new users to an example aliases file for the `(aliases)`
  file table syntax ([#&#8203;684](foxcpp/maddy#684)) (PR [#&#8203;729](foxcpp/maddy#729), thanks [@&#8203;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
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.

LMTP connection failures return 554 instead of 450 (regression in 0.9.5)

2 participants