Highlights

Contents

Part VIII
08

QUIC, TLS and web sessions

A reachable endpoint still needs to prove its identity and keep browser state within defined boundaries. Without authentication and browser policy, reliable bytes can deliver a request to an impostor or expose another user’s session. We will inspect QUIC, TLS, cookies, cross-origin access, and persistent web messaging.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Network models andphysical signals2Data link and Ethernetswitching3VLANs and IP addressing4IP forwarding and routing5Transport and TCP6Flow and congestioncontrol7DNS and HTTP8QUIC, TLS and websessions9Proxies, tunnels andfirewalls10Socket programming andI/O11CDN, P2P and cloudnetworking12The complete browserrequest

#Section 37QUIC streams, migration and establishment

QUIC supplies encrypted reliable streams and congestion control over UDP. Using a datagram carrier does not make the application’s delivery policy unreliable.

A QUIC packet can contain frames from several streams. Packet acknowledgements identify received packets, while stream offsets identify which bytes belong where. If a packet is lost, the sender can send needed stream data in a newly numbered packet. An independent stream can deliver complete bytes even while another stream waits for a gap. Delivery within the affected stream remains ordered.

ONE LOST PACKET DOES NOT REQUIRE EVERY STREAM TO WAITUDP packetQUIC framesstream Agap waitsstream Bcomplete bytesShared congestion capacity; independent stream delivery.
Figure 2.42A UDP datagram carries QUIC frames, and each stream tracks its own byte order. Orange marks the complete bytes of stream B progressing while stream A waits for a gap.

QUIC integrates TLS establishment, avoiding a separate TCP handshake before beginning the cryptographic exchange. A fresh connection still needs authenticated setup, and resumed early data has replay constraints. A connection identifier can let a connection survive a change of network tuple, such as a laptop moving between interfaces. The peer validates the new path rather than treating any packet carrying an identifier as trusted migration.

Finch’s gateway previously stored a tuple translation involving public port 40001. A path change can create a different NAT mapping even when the logical QUIC connection continues. TCP ordinarily binds its connection to its address and port pairings; QUIC adds a connection identity above the tuple. Migration is therefore protocol state, not a promise that every network permits it.

A firewall blocking UDP can prevent a QUIC path while allowing traditional HTTPS over TCP. Independent streams also share a congestion controller and connection-level flow allowance, so one flow cannot invent new link capacity. QUIC’s transport specification defines these boundaries. In an interview, say what moves above UDP before listing lower handshake cost as a possible consequence.

#Section 38HTTPS, TLS and certificate verification

TLS authenticates the expected peer and protects the exchange. Routing to an address alone does not prove it belongs to the requested hostname; HTTPS uses that protected transport.

A certificate binds a public key to names and other identity information under an issuer’s signature. A certificate authority issues such signed statements. The browser checks the requested hostname, validity conditions and a chain to a configured trust anchor. Possession of an arbitrary certificate is insufficient. The peer must also demonstrate control of the corresponding private key during the handshake.

TLS PROTECTS THE EXCHANGE AFTER VERIFYING THE EXPECTED ENDPOINTTLS PROTECTS THE EXCHANGE AFTER VERIFYING THE EXPECTED ENDPOINTclientexpected servercertificateidentity checkprotected session bytesencryption needs endpoint authentication and an agreed session
Figure 2.43The client checks the expected endpoint identity before trusting the protected session. The certificate and session protection have separate jobs in the exchange.

TLS uses asymmetric cryptographic operations for authentication and key agreement, then symmetric authenticated encryption for bulk data. A public key may be shared; the corresponding private key must remain secret. A digital signature proves control of a signing key and detects modifications. A cryptographic hash produces a compact digest, but a bare hash without authentication does not prove who sent it.

The TLS 1.3 exchange uses ephemeral key agreement rather than the old explanation that every client simply encrypts a session key with the certificate’s RSA key. The server’s certificate and handshake signature authenticate the exchange, while the negotiated secrets generate traffic keys. The TLS specification documents this division.

In the illustrative 40 ms RTT model, one TCP RTT, one TLS RTT and one HTTP request-response RTT sum to 120 ms. The model excludes DNS, application processing and connection reuse; resumption changes dependencies and early data adds replay risk. Encryption also leaves some metadata visible, including endpoints and traffic timing. A trusted proxy terminating TLS becomes part of the plaintext trust boundary.

#Section 39Cookies, sessions, authentication and authorization

A cookie is browser-held state returned under its scope and policy. A session connects later requests with application identity or state; HTTP does not remember a login automatically.

Server-side session

The browser holds an opaque identifier and the server uses it to look up session state. Deleting the server record can revoke subsequent use. Every participating backend must access the intended store or route consistently, so sticky sessions can hide an otherwise missing shared-state design.

JWT-style token

A signed token carries claims and a signature the server verifies. Encoding the claims does not encrypt them. The verifier must validate the expected algorithm, issuer, audience and expiration. Removing a login record does not automatically revoke a still-valid token; short validity periods, revocation state or other explicit policy may be needed.

A SESSION COOKIE IS A CLAIM TICKET; A SIGNED TOKEN IS A STAMPED PASSA SESSION COOKIE IS A CLAIM TICKET; A SIGNED TOKEN IS A STAMPED PASSserver-side sessionsid=7f3ameans nothing alonesessions7f3a → user 42, role admindelete the row: logged outsigned tokensub: 42aud: apiexp: 15:30sigverifyno lookup needed; validuntil expiry unless denylisted
Figure 2.44A server-side session follows an opaque identifier to stored state, while a signed token carries claims. Orange marks the lookup model used by Finch’s illustrative login.

Authentication establishes who a request acts for; authorization checks whether that identity may perform the requested action. Secure cookies restrict transmission to secure contexts, HttpOnly prevents ordinary script access, and SameSite controls some cross-site sending. Domain and path determine attachment scope, not a trustworthy application permission boundary.

Cross-site request forgery, or CSRF, exploits credentials the browser automatically attaches to a request initiated from another site. Script injection, or XSS, executes attacker-controlled code in the application’s context and can act with the user’s rights even if HttpOnly prevents reading the cookie. Session rotation after privilege changes and origin-aware defenses address different attack steps. 443 names Finch’s transport service, while none of these permissions come from that port number. A correct answer must identify where identity state lives and how it can expire or be revoked.

#Section 40CORS and the same-origin policy

An origin is scheme, host, and port. The same-origin policy restricts browser access; CORS allows specified cross-origin response reads. An answered request can still be hidden from script.

For a request requiring preflight, the browser sends OPTIONS with the intended method and relevant headers. The server answers with allowed origins, methods and headers, after which the browser decides whether to send the actual request. Some requests need no preflight, but exposing their responses still depends on appropriate permission. Credentials require additional agreement; a wildcard origin does not mean arbitrary credentialed browser reads are allowed.

BEFORE A CROSS-ORIGIN PUT, THE BROWSER ASKS PERMISSION WITH OPTIONSBEFORE A CROSS-ORIGIN PUT, THE BROWSER ASKS PERMISSION WITH OPTIONSapp.example.combrowser enforces the ruleapi.example.comOPTIONS Origin: app.example.comAccess-Control-Request-Method: PUTAccess-Control-Allow-Origin: app.example.comAllow-Methods: PUTPUT /profileonly if the answer allowed itCORS limits what pages may read; the API must still authenticate
Figure 2.45The browser sends OPTIONS before the actual preflighted request. Orange marks the permission inquiry; the server still authenticates and authorizes the eventual operation.

Access-Control-Allow-Origin names the permitted requesting origin. Allow-Methods and Allow-Headers describe permitted preflighted request properties, while the credential setting governs credentialed exposure. If a server varies its answer by Origin, cache behavior must preserve that distinction. An indiscriminately reflected origin can expose data that the server meant to keep private.

Finch’s API may listen on 443 and remain callable by a command-line client even when browser script cannot read it. curl does not implement the browser’s same-origin policy. CORS therefore cannot replace authentication, authorization, CSRF defenses or a firewall. Blocking a read is also different from preventing every request from being sent.

The Fetch standard defines the browser protocol. The useful diagnostic sequence is to identify the requesting origin, inspect preflight if present, inspect permission headers, then inspect application credentials. Changing server permissions without understanding the caller’s origin can conceal the error while broadening access.

#Section 41WebSockets, SSE and polling

A WebSocket provides bidirectional framed messages after establishment. The familiar HTTP/1.1 path upgrades the connection, replacing ordinary request-response bodies with WebSocket frames.

Frames distinguish data and control messages, and ping/pong helps test liveness. A large message may span frames, so a frame is not necessarily a complete application message. Reconnect creates a new connection; the application needs sequence identifiers or a resynchronization request if it must recover updates sent while disconnected.

ONE HTTP UPGRADE, THEN A LONG-LIVED PIPE WHERE EITHER SIDE CAN SPEAK FIRSTONE HTTP UPGRADE, THEN A LONG-LIVED PIPE WHERE EITHER SIDE CAN SPEAK FIRSTbrowserserverUpgrade:websocketHTTP/1.1 → 101msgmsgmsgmsgmsgframed messages both ways; ping and pong keep it aliveconnection drops: client reconnects andasks what it missed
Figure 2.46The HTTP upgrade opens a persistent framed exchange. Orange marks the opening upgrade request that negotiates the later bidirectional frame exchange.

Ordinary polling repeatedly asks for the latest state. Long polling lets the server hold a request until an update or deadline, then the client issues another. Server-Sent Events, or SSE, streams text events from server to browser through a long-lived HTTP response. WebSockets support messages in both directions, while SSE’s application direction is server to client and ordinary requests can carry client actions.

Property Polling SSE WebSocket
Server push Next request Event stream Message stream
Client messages New requests Separate requests Same connection
Reconnect state Query current value Event identifier policy Application protocol
Intermediary needs Ordinary HTTP Streaming HTTP Upgrade or supported mapping

Finch’s 40 ms RTT remains a lower path cost for an interactive round trip; keeping a connection open avoids repeated establishment but cannot erase propagation. A slow consumer can accumulate outgoing messages until memory grows without bound, so choose a buffer limit and resynchronization policy. Proxies and load balancers also need suitable idle timeouts and support for the chosen transport. The WebSocket specification supplies framing; application delivery guarantees still require application state.