Skip to content

Commit 9ec4ab4

Browse files
committed
[Proposal] Early Data Support in URLSession
1 parent bfc4580 commit 9ec4ab4

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Early Data Support in URLSession
2+
3+
* Proposal: [SF-NNNN](NNNN-urlsession-early-data.md)
4+
* Authors: [Guoye Zhang](https://github.com/guoye-zhang)
5+
* Review Manager: TBD
6+
* Status: **Awaiting review**
7+
* Implementation: [swiftlang/swift-corelibs-foundation#5216](https://github.com/swiftlang/swift-corelibs-foundation/pull/5216)
8+
* Review: ([pitch](https://forums.swift.org/t/pitch-early-data-support-in-urlsession-on-darwin/80071))
9+
10+
## Introduction
11+
12+
HTTP/3 early data enables request transmission on a new connection with no round trip delays (0-RTT), improving the startup time of apps. We are introducing a new flag `enablesEarlyData` on URLSessionConfiguration to allow developers to opt in to the feature.
13+
14+
The flag is not available on non-Darwin platforms at this moment.
15+
16+
## Example usage
17+
18+
Adopting HTTP early data and loading a URL.
19+
20+
```swift
21+
let configuration = URLSessionConfiguration.default
22+
configuration.usesClassicLoadingMode = false
23+
configuration.enablesEarlyData = true
24+
25+
let session = URLSession(configuration: configuration)
26+
let (data, response) = try await session.data(from: url)
27+
```
28+
29+
## Detailed design
30+
31+
By opting in to the flag, URLSession persists HTTP/3 connection state along with QUIC and TLS session state, allowing 0-RTT transmission of safe requests (GET or HEAD requests) when establishing a new connection to the same host.
32+
33+
```swift
34+
open class URLSessionConfiguration {
35+
36+
/* Enables HTTP/3 0-RTT early data transmission of safe requests (GET or HEAD
37+
requests).
38+
39+
WARNING: Inclusion in TLS early data changes the security guarantees offered
40+
by TLS.
41+
42+
Requests sent in early data are not covered by anti-replay security
43+
protections. Early data must be idempotent and the impact of adversarial
44+
replays must be carefully evaluated, as the data may be replayed. Early data
45+
also does not provide full forward secrecy; data transmitted is more
46+
susceptible to data breach and security compromise of the server, even if
47+
the breach happens after the data was transmitted.
48+
49+
See Section 8 of RFC8446 for more details.
50+
51+
https://datatracker.ietf.org/doc/html/rfc8446#section-8
52+
53+
See RFC8470 for additional discussion and security considerations.
54+
55+
https://datatracker.ietf.org/doc/html/rfc8470
56+
57+
If these risks are acceptable for your use case, set this property to true.
58+
If unsure, false is the safest option.
59+
60+
NOTE: Not supported in the classic loading mode.
61+
62+
Defaults to false.
63+
*/
64+
@available(*, unavailable, message: "Not available on non-Darwin platforms")
65+
open var enablesEarlyData: Bool
66+
}
67+
```
68+
69+
## Source compatibility
70+
71+
No impact.
72+
73+
## Implications on adoption
74+
75+
This feature can be freely adopted and un-adopted in source code with no deployment constraints and without affecting source compatibility.
76+
77+
## Future directions
78+
79+
Some apps use unsafe method such as POSTs to transfer idempotent data, and they might want to send those requests in the early data. This can be supported in the form of a flag `URLRequest.unsafeAllowsInEarlyData` on a per-request basis. However, it is not needed for the majority of the use cases.
80+
81+
## Alternatives considered
82+
83+
### Enabling early data by default
84+
85+
0-RTT early data can be replayed by an attacker, and we do not know if the server has sufficient mitigations of such an attack. Therefore we ask developers to enable this flag at their own risk.

0 commit comments

Comments
 (0)