mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
Some HTTP proxies (as seen in ChatGPT Work's sandbox) intercept TLS and refuse DERP's "Upgrade: DERP" request but allow WebSocket upgrades, like browsers use. derphttp could already speak DERP over WebSockets, but only on js/wasm or with the ts_debug_websockets build tag and an envknob, and that path dials with its own http.Client, skipping the DERP node selection, proxy CONNECT, and TLS logic of the normal path. Add derphttp.HookUpgradeWebsocket. When it's set and a client's HTTP upgrade to DERP fails after any TLS handshake succeeded, the client redials and calls the hook to do a WebSocket handshake over the new connection instead. Once that works, the client keeps using WebSockets for its reconnects until they fail, so it doesn't pay for a refused upgrade every time. The new feature/derpwebsocket package sets the hook. Neither tailscaled nor tsnet links it in; programs that want the fallback, like tailcat, import it. Updates #22412 Signed-off-by: Brad Fitzpatrick <[email protected]> Change-Id: I20e4b29f1bca6e7e5e3b33f960ce9d331ec7dac9
15 lines
593 B
Go
15 lines
593 B
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package derpwebsocket registers a fallback for DERP clients to speak DERP
|
|
// inside WebSockets, as browsers do, when their HTTP upgrade to DERP fails.
|
|
// This gets through HTTP proxies that intercept TLS and allow WebSocket
|
|
// upgrades but block others, as in some sandboxes for AI agents.
|
|
//
|
|
// Neither tailscaled nor tsnet links it in. Programs that want it must
|
|
// import it themselves.
|
|
//
|
|
// On js/wasm, where DERP clients always use WebSockets, importing it does
|
|
// nothing.
|
|
package derpwebsocket
|