Description
App Transport Security (ATS) in Apple’s URL Loading System does not cover NWConnection. With Network.framework, the app must configure transport encryption and authenticate the peer.
Network.NWParameters.tcp and Network.NWParameters.udp select plain TCP and UDP. Network.NWParameters(tls: nil, tcp: ...) and Network.NWParameters(dtls: nil, udp: ...) explicitly omit TLS and DTLS.
To assess exposure, check whether the connection succeeded, which protocol it used, how it authenticated the peer, and whether the application protocol protected the data.
Potential impact
If the application protocol also lacks authenticated encryption:
- Network observers or intermediaries may read credentials and personal information.
- An active attacker may modify transmitted data.
- An attacker may impersonate the server or peer.
- Captured messages may be replayed if separate replay controls are absent.
Remediation
- For TCP, use
Network.NWParameters.tlsor supply non-nilTLS options. For UDP, useNetwork.NWParameters.dtlsor supply non-nilDTLS options. Keep the system’s server-trust checks enabled and avoid callbacks that accept every certificate or peer. - For HTTP or other URL-based resources, use HTTPS with
URLSessionand limit ATS exceptions. - Send only the sensitive data you need. If you also need protection beyond the TLS endpoints, add application-layer authenticated encryption with independent key management, unique nonces, and replay protection. Keep authenticated transport in place.
- Inspect release-build traffic for cleartext and unexpected protocols.
Examples
Before
import Dispatch
import Foundation
import Network
func sendCredential(clientSecret: Data) {
let connection = Network.NWConnection(
host: "api.example.com",
port: 443,
using: Network.NWParameters.tcp
)
let queue = DispatchQueue(label: "cleartext-connection")
connection.start(queue: queue)
connection.send(content: clientSecret, completion: .contentProcessed { _ in })
}
After
import Dispatch
import Foundation
import Network
func sendCredential(clientSecret: Data) {
let connection = Network.NWConnection(
host: "api.example.com",
port: 443,
using: Network.NWParameters.tls
)
let queue = DispatchQueue(label: "tls-connection")
connection.start(queue: queue)
connection.send(content: clientSecret, completion: .contentProcessed { _ in })
}
Port 443 alone does not enable TLS. The revised NWConnection uses Network.NWParameters.tls to protect clientSecret in transit. Keep server-trust checks enabled and handle connection states and send errors.
References
- CWE-319: Cleartext Transmission of Sensitive Information
- Apple - Network
- Apple - NWParameters
- Apple TN3151 - Choosing the right networking API
- OWASP MASTG-TEST-0323: Uses of Low-Level Networking APIs for Cleartext Traffic
- OWASP MASTG-TEST-0344: Network.framework TLS Protocol Configuration
- OWASP MASTG-TEST-0236: Cleartext Traffic Observed on the Network
- CodeQL - Cleartext transmission of sensitive information