Repository navigation
fix(smtp): require public SMTP hosts for project and messaging SMTP - #14811
Conversation
Project SMTP and messaging SMTP providers are dialled from the API and the workers on a host the project chooses, which was only checked for its format. Check every server in the host against the same public address rules webhooks and migrations use, dial the address checked (the certificate is still verified against the host), and stop repeating the server's own reply in the project SMTP error. Operator _APP_SMTP_* configuration is unchanged. Adds address pinning to the messaging SMTP adapter and a lenient PublicHostname::addresses() for hosts stored before they resolve.
|
Review complete. 🟠 1 high · 🟡 2 medium 💬 Inline comments (2)
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Host errors bypass the // src/Appwrite/Platform/Workers/Mails.php
251 addresses: new Host($publicHostname)->addresses($smtp['host']),
252 );
253
254 $send = static function (EmailAdapter $adapter) use ($emailMessage, $telemetry): array {
255 $adapter->setTelemetry($telemetry);
256
257 return $adapter->send($emailMessage);
258 };
259
260 $result = $adapter instanceof EmailAdapter ? $send($adapter) : $register->get('smtp')->use($send);
261 } catch (InvalidArgumentException $error) {
262 // The address or name can never be delivered, so a retry cannot help.The adapter construction at They land in the generic Impact: observability and end-state classification for project-SMTP host failures diverge from the design the pre-check at line 169 documents. This PR blocks private, reserved, and internal address targets for project SMTP and messaging SMTP providers by introducing a new
Main risks center on eager host resolution aborting messaging sends (a transient DNS failure dead-letters the whole message), host errors bypassing the intended catch path in the mails worker, and split-worker compose services missing the Reviewed commit: cf0088d |
🟢 Tier S · Ready to merge
Project-configured and messaging SMTP hosts are parsed and checked against public-address policy, with connections pinned to checked addresses while preserving hostname-based TLS verification. Project and messaging APIs reject private hosts, SMTP workers recheck stored hosts during delivery, and the PR adds configuration, validation tests, and API coverage for these behaviors. Latest changes: The newest commit adds an E2E case that stores an unresolved SMTP host, sends a message through it, and verifies the message reaches a failed state with a recipient delivery error.
📂 Walkthrough · 19
✅ Fixed since the last review · 1
Reviewed the commits since |
There was a problem hiding this comment.
Adds SSRF protection for user-supplied SMTP hosts by resolving and validating them at provider create/update and again at send time in the mails and messaging workers.
Key findings
- 🟠 Eager host resolution aborts messaging sends — Provider.php:112
- 🟡 Host errors bypass the
InvalidArgumentExceptioncatch — Mails.php:251 - 🟡 Separate workers miss
_APP_DNSfallback resolver — docker-compose.yml:1346
A refused or unresolved SMTP host threw out of the provider loop and failed the whole message, including recipients on other providers. Record it against that provider's recipients instead. Also pass _APP_DNS to the separate mails and messaging workers, which the public hostname check falls back to.
|
On the tenki finding outside the diff (Mails.php host errors bypassing the |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Cover a project SMTP host at a private address being skipped before any connection.
The private-host test changes the host after an earlier test stored a password, so the write-only password rule (appwrite#14795) rejected it before the public-host check (appwrite#14811) ran.
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
…MTP (backport #14811) Project SMTP and messaging SMTP provider hosts are checked against public addresses on save, on the SMTP test endpoint, and again by the mails and messaging workers before each send. Project SMTP verification dials the checked address of a single server and no longer echoes the server reply. Adds _APP_ALLOWED_INTERNAL_ADDRESSES (introduced in 1.9.10) so an internal relay can still be allowed. Pinning worker connections to the checked address needs the messaging library's SMTP addresses option, which 1.9.x's vendored utopia-php/messaging does not have. (cherry picked from commit 1c3636d)
fix(smtp): require public SMTP hosts for project and messaging SMTP (cherry picked from commit 1c3636d)
Summary
Project SMTP and messaging SMTP providers are dialled on a host the project chooses, which was only checked for its format. This applies the same public-address rules (
publicHostname,_APP_ALLOWED_INTERNAL_ADDRESSES) that webhooks and migration sources already use. Operator_APP_SMTP_*configuration is not affected.Appwrite\SMTP\Validator\Hostreads a host the way the SMTP adapter does (;-separated servers,ssl:///tls://prefixes,:port, bracketed IPv6) and checks every server.addressesoption for that.appwrite-worker-mailsnow receives_APP_DNS_EXTERNALand_APP_ALLOWED_INTERNAL_ADDRESSESlike the other workers.Messaging
deliveryErrorskeep the per-recipient SMTP replies (for example550 5.1.1 User unknown): with the host checks in place they only ever come from a public server the project configured, and they are what makes a failed send actionable.Self-hosted installs that point project SMTP at a private relay need to list it in
_APP_ALLOWED_INTERNAL_ADDRESSES, as for webhooks.Test plan
tests/unit/SMTP/Validator/HostTest.php,tests/unit/Network/Validators/PublicHostnameTest.phpbin/monorepo check messaging/bin/monorepo test messaging(newSMTPAddressesTest)testCreateSMTPProviderPrivateHost,testUpdateSMTPProviderPrivateHost(Messaging);testUpdateSMTPPrivateHost,testUpdateSMTPRefusedCredentialsDoNotEchoServer,testCreateSMTPTestPrivateHost(Project); existing maildev-based SMTP tests keep passingRelated: appwrite-labs/cloud#6674