How-To Guide

How to Enable TLS 1.3 Early Data

Use TLS 1.3 0-RTT early data to cut a round trip on resumed connections, and restrict it to safe requests to avoid replay.

On this page

  1. Introduction
  2. What 0-RTT Early Data Is
  3. The Replay Problem
  4. Server-Side Anti-Replay
  5. Configuring It on the Server
  6. Application-Level Enforcement
  7. Client Side and Fallback
  8. Common Pitfalls and Conclusion

Introduction

TLS 1.3 saves a round trip on a fresh connection by combining messages, but a resumed connection can save one more: with 0-RTT early data, the client sends application data in the first flight, before the handshake completes, using a key from the previous session. The server can accept and process it immediately, cutting the start latency for a resumed connection. The catch is replay: early data can be replayed by an attacker who captures it, so it must be restricted to requests that are safe to replay.

What 0-RTT Early Data Is

On a resumed TLS 1.3 connection, the client already shares a pre-shared key from the previous session and can encrypt application data in the first flight, before the server has confirmed the handshake. This is the “0-RTT” data: it arrives with the ClientHello rather than after a full round trip.

The benefit is latency: the server can start processing the request a round trip earlier, which matters on high-latency paths and for short requests where the round trip is a large fraction of the total. The cost is the replay property described next.

# full handshake (TLS 1.2)
client -> ClientHello
server -> ServerHello, cert, ...     | 1 RTT before app data
client -> app data                   |

# TLS 1.3 0-RTT on a resumed connection
client -> ClientHello + early app data   (no round trip before data)
server -> accepts and processes
# saves a round trip at the cost of replay risk for the early data

The Replay Problem

Early data has no protection against replay because it is sent before the handshake binds the connection to a fresh key. An attacker who captures the early data can resend it to the server, and the server cannot tell the copy from the original by the TLS layer alone. This is inherent to 0-RTT, not a bug.

Therefore early data must be restricted to requests where replay is harmless: safe, idempotent methods such as GET. A request that has side effects, a POST that charges a card, must not be processed from early data, because a replay would charge twice.

# 0-RTT replay risk
captured early data can be resent; the TLS layer cannot distinguish it
=> only SAFE, idempotent requests may use early data (GET, HEAD)
=> a POST with side effects must NOT be accepted as early data
# this is why servers reject early data for non-idempotent methods

Server-Side Anti-Replay

Beyond restricting to safe methods, a server can add anti-replay: a single-use ticket or a replay cache of early-data identifiers. TLS 1.3 provides a mechanism where the server rejects 0-RTT for a ticket it has already seen, or the server stores a nonce from the early data and rejects a repeat.

Anti-replay reduces the window but does not eliminate it, because a distributed server or a replay within the cache window can still slip through. Treat anti-replay as defence in depth, and the safe-method restriction as the primary control.

# layered 0-RTT defence
1. restrict early data to safe methods (GET/HEAD)          -- primary
2. single-use session tickets (reject a reused ticket)
3. a replay cache of early-data nonces (bounded window)
# anti-replay narrows the window; safe methods are the real control

Configuring It on the Server

Most servers and proxies expose 0-RTT as a setting. Enable it, understand that it applies to resumed connections only, and configure the safety policy: the server should reject early data for methods it deems unsafe. In NGINX, ssl_early_data on accepts early data and $ssl_early_data tells you whether the current request used it, so you can reject unsafe ones in the application.

The application can read the early-data flag and decide: allow the request if it is safe, or require a full handshake (return 425 Too Early) for a request with side effects. Returning 425 tells the client to retry without early data, which it does.

# nginx: accept 0-RTT and expose whether the request used it
server {
  listen 443 ssl;                            # TLS 1.3 required for early data
  ssl_protocols TLSv1.3;                     # (can keep 1.2 for compat, no 0-RTT)
  ssl_early_data on;
  location / {
    proxy_set_header Early-Data $ssl_early_data;   # pass the flag to the app
    proxy_pass http://app;
  }
}

Application-Level Enforcement

The application receives the early-data flag and enforces the policy. For a safe request, process it. For a request with side effects, reject with 425 Too Early so the client retries over a full handshake; do not silently process it. This is the point where the replay risk is actually contained.

Centralise the check in middleware so no handler can forget it. A request carrying the early-data flag and an unsafe method is rejected before it reaches business logic, which is the fail-safe shape: a new endpoint is safe by default because the middleware checks the method.

const SAFE = new Set(['GET', 'HEAD', 'OPTIONS']);

export function rejectUnsafeEarlyData(req: Request): Response | undefined {
  const usedEarlyData = req.headers.get('early-data') === '1';
  if (usedEarlyData && !SAFE.has(req.method)) {
    // 425 Too Early tells the client to retry without early data
    return new Response('retry without early data', { status: 425 });
  }
  return undefined;
}

Client Side and Fallback

A client must handle a 425 response by retrying the request over a full handshake, without early data. A client that does not understand 425 may treat it as an error, so the fallback must be built in. Many HTTP clients support 0-RTT opt-in and handle the retry automatically.

Clients should only attempt early data for requests they know are safe, mirroring the server’s policy. A client that sends a POST as early data will get a 425 and retry anyway, so it gains nothing and adds an attempt; the client should opt in per request based on safety.

# client policy
[ ] opt in to 0-RTT only for safe/idempotent requests
[ ] on 425 Too Early: retry the request without early data
[ ] do not send a POST as early data (it will be rejected anyway)
# server rejects unsafe early data; client retries over a full handshake

Common Pitfalls and Conclusion

Do not enable 0-RTT and process unsafe requests from early data; that is a replayable side effect. Do not rely only on anti-replay caches, which narrow but do not close the window. Do not forget the client’s 425 handling, or early data looks like an error. And do not expect 0-RTT on a fresh connection; it applies only to resumed ones.

TLS 1.3 0-RTT early data saves a round trip on a resumed connection by sending application data in the first flight, at the cost of replay risk for that data. Enable it, restrict it to safe methods as the primary control, add anti-replay as defence in depth, return 425 for unsafe early-data requests, and handle the retry on the client. Then the latency win is real and the replay risk is contained.

Sources: RFC 8446: TLS 1.3 (0-RTT), RFC 8470: Using Early Data in HTTP, NGINX: ssl_early_data.

FAQ

Why is 0-RTT data replayable?
Because it is sent before the handshake binds the connection to a fresh key, so the TLS layer cannot tell a resent copy from the original. This is inherent to 0-RTT, which is why it must be restricted to safe, idempotent requests.
What should a server do with an unsafe early-data request?
Reject it with 425 Too Early, so the client retries over a full handshake without early data. Do not process it, because a captured copy could be replayed to repeat the side effect. Centralise the check in middleware so no handler forgets it.

Related Examples