Commit 482fa84a09

482fa84a09fe674d8c9e08de4371ad0cbf95edef

parent: c9d7cb7b65

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-24 02:16 UTC

Refuse SMTP credentials on an unencrypted connection

The "Plain" security mode built NWParameters.tcp and then sent AUTH LOGIN
over it, so the username and password went out base64-encoded in the
clear. The editor requires a password, so every email integration had
credentials to leak.

SMTPClient now throws before connecting when a username is set without
direct TLS, the editor says so at save time rather than when an alert
fires, and the mode reads "None (no TLS)". STARTTLS is not offered
because NWConnection cannot upgrade an established connection, so port
587 submission still needs that work.

Also guards the port conversion: UInt16(_:) traps above 65535, which the
editor's numeric port field accepts.

Layout: unified · split

DomainDig/IntegrationService.swift +14 −1
@@ -586,6 +586,7 @@ private enum IntegrationError: LocalizedError {
586586 case missingSecret
587587 case invalidResponse(Int)
588588 case invalidSMTPPort
589 case insecureCredentials
589590 case smtp(String)
590591 case streamClosed
591592
@@ -601,6 +602,8 @@ private enum IntegrationError: LocalizedError {
601602 return "The remote endpoint returned \(statusCode)."
602603 case .invalidSMTPPort:
603604 return "The SMTP port is invalid."
605 case .insecureCredentials:
606 return "SMTP credentials cannot be sent over an unencrypted connection. Use Direct TLS, usually on port 465."
604607 case .smtp(let message):
605608 return message
606609 case .streamClosed:
@@ -669,10 +672,20 @@ private enum SMTPClient {
669672 configuration: EmailIntegrationConfiguration,
670673 password: String
671674 ) async throws {
672 guard let port = NWEndpoint.Port(rawValue: UInt16(configuration.port)) else {
675 // `UInt16(_:)` traps above 65535, which the editor's port field allows.
676 guard let portNumber = UInt16(exactly: configuration.port),
677 let port = NWEndpoint.Port(rawValue: portNumber) else {
673678 throw IntegrationError.invalidSMTPPort
674679 }
675680
681 // AUTH LOGIN sends the username and password base64-encoded, which is
682 // not encryption. Without TLS from the first byte they would go out in
683 // the clear, so refuse before the connection opens. STARTTLS is not an
684 // option here: NWConnection cannot upgrade an established connection.
685 guard configuration.username.isEmpty || configuration.securityMode == .directTLS else {
686 throw IntegrationError.insecureCredentials
687 }
688
676689 let parameters: NWParameters = {
677690 switch configuration.securityMode {
678691 case .plain:
DomainDig/IntegrationsView.swift +4
@@ -468,6 +468,10 @@ private struct IntegrationEditorView: View {
468468 validationMessage = "SMTP password is required."
469469 return
470470 }
471 if smtpSecurity != .directTLS, !emailUsername.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
472 validationMessage = "A username needs Direct TLS, usually on port 465. Without it the password would be sent in cleartext."
473 return
474 }
471475
472476 let target = IntegrationTarget(
473477 id: targetID,
DomainDig/Models.swift +1 −1
@@ -1808,7 +1808,7 @@ enum SMTPSecurityMode: String, Codable, CaseIterable, Identifiable, Sendable {
18081808 var title: String {
18091809 switch self {
18101810 case .plain:
1811 return "Plain"
1811 return "None (no TLS)"
18121812 case .directTLS:
18131813 return "Direct TLS"
18141814 }