Redact recipient rules, improve protected tunnel startup output, and reject --allowed-mail for named tunnels.
Use state-specific cookies so concurrent login flows remain independent, with callbacks selecting and clearing only the matching state cookie.
This prevents users from abusing `--allowed-mail` policies by limiting the nr. of rules to 100 and defining a max per rule of 320 bytes. Validation errors now identify only the rule position and category, preventing recipient values from appearing in logs. Parsing also stops once limits are exceeded while preserving normalisation and deduplication.
To properly secure authorized requests, we need to strip any process-local session and authentication-state cookies before forwarding them. On protected responses, we also enforce `Cache-Control: private, no-store` and `Referrer-Policy: no-referrer` directives, to prevent sensitive data from being cached locally or by intermediaries and to block referrer URLs from leaking across requests.
Response headers and cookies for Public Quick Tunnel are preserved.
This adds a shared authorization boundary for protected Quick Tunnels before ingress selection. Unauthenticated requests are redirected or rejected, while requests with a valid local session continue to the origin after the internal authentication cookie is removed.
Before these changes, we could already login and validate sessions, but the request handler could not allow authenticated requests to continue to the origin. This change adds that authorization decision.
Public Quick Tunnels remain unchanged.
Validates callback-bound broker assertions, enforces recipient rules, and issues local sessions before redirecting with HTTP 303. Callback replay is bounded by the short-lived signed artifacts.
## Summary
- generate a cryptographically random process-local HMAC-SHA256 session signing key
- issue host-only, Secure, HttpOnly, SameSite=Lax Quick Tunnel session cookies
- cap sessions at the earlier of 4 hours or the Access identity expiry
- validate canonical cookie encoding, signatures, nonces, and expiry
- invalidate sessions across cloudflared restarts through process-local signing keys
- use `github.com/cloudflare/backoff` for tunnel retry jitter while preserving retry limits, retry-forever caps, and grace-period resets
## Security
- session payloads contain only a random nonce and expiry; no visitor identity or recipient rules
- malformed, tampered, expired, and previous-process sessions fail closed
- HMAC signatures are compared in constant time
## Validation
- `make test lint`
- `go test -race ./retry ./quicktunnelauth`
This reverts merge request !1952
Reverting this change. This was an unbuffered channel before, which does not mean "unbounded". The channel was effectively blocking until a receiver read the value.
For the refresh JWKS operation, a worker fiber was reading from a notification channel that had no buffering.
This has two issues. The first issue has to do with memory growth, but the second is more subtle. When we don't supply any bounds, the code needs to be capable to handle concurrent requests and the worker must be able to dedup notifications. While this is what happens now, a future iteration might introduce a bugthat removes the dedup logic.
## Summary
Validates callback-bound Quick Tunnel broker assertions using the verification keys cached in !1937. The validator accepts only ES256 JWTs from the fixed broker issuer and audience, verifies signatures before claims, enforces the two-minute handoff lifetime and Access identity expiry, binds the callback hostname and browser state, validates and normalizes the verified email, and returns a trusted identity for recipient authorization.
The temporary hostname validator mirrors TUN-10800 and is documented for consolidation after that stack merges.
## Stack
- Depends on: !1937
- Part 2/2: this MR
## Validation
- `make test lint`
- focused `go test -race ./connection` coverage for JWT headers, signatures, claims, and identity binding
## Summary
Adds the process-local broker JWKS cache used by protected Quick Tunnel assertion validation. Fetches keys only from the fixed broker endpoint with a five-second timeout, refuses redirects, bounds and validates responses, accepts only public P-256 ES256 signing keys, reuses cached keys, and refreshes once for an unknown key ID. Concurrent cache misses and refreshes are deduplicated.
## Stack
- Part 1/2: this MR
- Followed by: `afrigerio/TUN-10801-assertion-validation`
## Validation
- `make test lint`
- focused `go test -race ./connection` coverage for JWKS caching and refresh
Wires protected Quick Tunnel authentication into the request path so unauthenticated requests are intercepted before ingress selection. Broker callbacks are handled locally and fail closed
This adds callback handling for the browser-bound Quick Tunnel authentication state, consuming the POST to /.cloudflared/qt-auth/callback that the broker sends after login. The handler accepts a bounded application/x-www-form-urlencoded body containing exactly one state and one assertion, verifies the HMAC-signed state cookie, and binds it to the submitted state.
It fails closed and clears the state cookie once consumption succeeds. On success, the handler returns the broker assertion and the validated return path for later use.
This adds QuickTunnelAuthStateManager, which issues browser-bound authentication states for protected Quick Tunnels. Each login generates a random state and a signed, host-only cookie that binds the browser to that state. The cookie is Secure, scoped to the callback path, valid for 10 minutes, and uses SameSite=None because the broker's callback is a cross-site POST from login.trycloudflare.com back to .trycloudflare.com.
The design is stateless: the cookie is signed with a process-local HMAC key rather than tracked server-side, so there's nothing to store or clean up, and state values are verified rather than looked up. Return-path validation rejects unsafe schemes, hosts, and paths to prevent open redirects.