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 {
586 case missingSecret 586 case missingSecret
587 case invalidResponse(Int) 587 case invalidResponse(Int)
588 case invalidSMTPPort 588 case invalidSMTPPort
589 case insecureCredentials
589 case smtp(String) 590 case smtp(String)
590 case streamClosed 591 case streamClosed
591 592
@@ -601,6 +602,8 @@ private enum IntegrationError: LocalizedError {
601 return "The remote endpoint returned \(statusCode)." 602 return "The remote endpoint returned \(statusCode)."
602 case .invalidSMTPPort: 603 case .invalidSMTPPort:
603 return "The SMTP port is invalid." 604 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."
604 case .smtp(let message): 607 case .smtp(let message):
605 return message 608 return message
606 case .streamClosed: 609 case .streamClosed:
@@ -669,10 +672,20 @@ private enum SMTPClient {
669 configuration: EmailIntegrationConfiguration, 672 configuration: EmailIntegrationConfiguration,
670 password: String 673 password: String
671 ) async throws { 674 ) 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 {
673 throw IntegrationError.invalidSMTPPort 678 throw IntegrationError.invalidSMTPPort
674 } 679 }
675 680
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
676 let parameters: NWParameters = { 689 let parameters: NWParameters = {
677 switch configuration.securityMode { 690 switch configuration.securityMode {
678 case .plain: 691 case .plain:
DomainDig/IntegrationsView.swift +4
@@ -468,6 +468,10 @@ private struct IntegrationEditorView: View {
468 validationMessage = "SMTP password is required." 468 validationMessage = "SMTP password is required."
469 return 469 return
470 } 470 }
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 }
471 475
472 let target = IntegrationTarget( 476 let target = IntegrationTarget(
473 id: targetID, 477 id: targetID,
DomainDig/Models.swift +1 −1
@@ -1808,7 +1808,7 @@ enum SMTPSecurityMode: String, Codable, CaseIterable, Identifiable, Sendable {
1808 var title: String { 1808 var title: String {
1809 switch self { 1809 switch self {
1810 case .plain: 1810 case .plain:
1811 return "Plain" 1811 return "None (no TLS)"
1812 case .directTLS: 1812 case .directTLS:
1813 return "Direct TLS" 1813 return "Direct TLS"
1814 } 1814 }