Security

Your machines, your keys, nobody in the middle

Bridge connects your machines through NAT with no open port, no public IP, and no middle party you have to trust. The relays carry ciphertext, the keys stay on your devices, and every client checks the key it is handed before it says anything secret.

· · 10 min read

Problem: Reaching your own machines from anywhere sucks. Usually you either:

  1. Forward a port and put a login page on the internet, or
  2. Hand your traffic, and often your keys, to somebody else's cloud.

Bridge does neither. Your machines stay behind NAT with nothing listening on a public port, and they still find each other. The middle parties involved are trusted with nothing: they move ciphertext and never hold a key, so none of them can read your traffic or pretend to be you.

This post is how that works.

The short version

The Bridge server's control plane and its sidecar sit behind NAT on your network. The sidecar dials out a WebSocket tunnel to an untrusted relay. A laptop or phone opens its own tunnel to the relay, which splices the two; the control traffic inside is Noise-encrypted end to end between the device and your Headscale. The device then reaches your machines directly over WireGuard. YOUR NETWORK · BEHIND NAT UNTRUSTED RELAY ANYWHERE OUTBOUND WSS 1 NOISE · TS2021 2 LOCAL DIRECT WIREGUARD 3 CTRL Headscale your control plane SIDECAR Bridge sidecar dials out, never listens AGENT Your machines WireGuard keys stay here RELAY bridgeproxy.net sees ciphertext DEVICE Laptop or phone pinned server key Trusted with nothing. LEGEND Bridge sidecar Runs on your hardware Untrusted relay Outbound tunnel Client tunnel, Noise E2E Direct WireGuard
The relay forwards bytes it cannot read. Once your devices are on the network, it is not in the path at all.
  1. The Bridge server runs its own Tailscale control plane, Headscale, on your hardware. A small sidecar next to it dials out to a relay and keeps that connection open. No port forwarding, no public IP, nothing to firewall.
  2. Your laptop or phone reaches the control plane through the relay at <fingerprint>.bridgeproxy.net. What crosses the relay is Tailscale's control protocol, Noise-encrypted end to end between your device and your Headscale.
  3. Your machines then talk to each other over WireGuard, directly whenever the network allows it. The relay is not in that path.

If this looks familiar, it is headfwd, a pattern I built for reaching self-hosted apps at home. Anyone can build the same pattern into their own apps, and because the relays cost next to nothing to run, they can use them for free. Bridge runs the same relay code, unmodified.

Why the control plane is the hard part

Tailscale solved NAT traversal for the machines themselves, and How NAT traversal works is still the best explanation of it anywhere. We did not rewrite any of it. Bridge's tailscaled does the hole punching.

What Tailscale assumes is that the control server is reachable. Tailscale runs theirs on the internet, which means trusting them with who is on your network. Self-host Headscale instead and you are back to port forwarding, a public IP, DNS and a certificate, on the one server that holds your network's root of trust.

So the control plane dials out. The sidecar holds one persistent WebSocket open to the relay and multiplexes everything over it. Outbound is the whole point: Headscale needs no inbound port, no port forwarding and no public IP.

The relay finds your control plane by its fingerprint: the first 128 bits of the SHA-256 of Headscale's public identity key. It is public, not secret. It is the subdomain, and it is in every invite.

The relay is assumed hostile

Every decision here starts from one rule: the relay is untrusted. Not "probably fine". We run it, and the design still assumes whoever runs it is reading along and would like to get in.

That matters because of where TLS ends. The relay terminates TLS for *.bridgeproxy.net. It can present a perfectly valid certificate and change anything in the response. HTTPS protects you from the coffee shop Wi-Fi, not from the relay.

What it cannot touch is the session inside. Tailscale's control protocol runs Noise between your device and Headscale, and only the holder of Headscale's private key can complete that handshake. That key lives on your host and never goes anywhere else.

Why a relay can't get in

A device needs the control plane's public key before it can start the Noise handshake, and it fetches that key through the relay. So that one exchange is built to be unforgeable, and everything after it is sealed.

On your device, an invite key carries a public fingerprint and a secret preauth key. The control shim fetches the control plane's key through the untrusted relay, checks that it hashes to the fingerprint, and only then sends the preauth key, sealed inside Noise, through the relay to Headscale on your network. If the check fails the shim exits and the key is never sent. YOUR DEVICE UNTRUSTED RELAY YOUR NETWORK GET /KEY 1 SERVED KEY 2 PREAUTH, SEALED 3 SPLICED INVITE Invite key fingerprint · public preauth · secret SHIM Control shim hash == fingerprint? then pin the key RELAY bridgeproxy.net terminates TLS CTRL Headscale Noise private key No match: the shim exits, and the key never leaves.
A substituted key fails the check at step 2, before the secret leaves the device. After that, the device never asks the relay for the key again.

Peer traffic never touches the relay

Once a device is on the network, the relay is done. Your laptop reaches your build machine over WireGuard, peer to peer, and the WireGuard keys never leave the devices that use them.

When two machines cannot reach each other directly (two strict NATs, a hostile corporate network), WireGuard falls back to Tailscale's public DERP relays. They forward packets that are encrypted end to end, with keys they never see. They are still third-party infrastructure, and they still see which machines talk and how much. The app says so, rather than calling every connection direct.

A few more details, because people ask:

Notifications: the relay we could not avoid

Push notifications are where self-hosted apps usually give up and send plaintext through somebody's cloud.

Apple only accepts pushes to an app from the team that signed it, so a Bridge server you run cannot talk to Apple by itself. The alternative is shipping our Apple key to every server operator, and that one key can push to every Bridge app on earth and never expires. So the key stays in one place, a small Worker at push.bridgeproxy.net, and your server posts through it.

That makes the push relay a middle party holding a powerful key. Which is exactly why it is not allowed to read anything.

Your Bridge server seals each notification to the phone's public key and sends the sealed blob to the push relay, which forwards it through Apple's push service to the phone. The phone decrypts it with a private key that never leaves its Keychain. The phone registered only its public key with your server. YOUR SERVER MIDDLE PARTIES YOUR PHONE SEALED BLOB SAME BLOB PUBLIC KEY ONLY SERVER Bridge server seals to the phone fresh key every push PUSH RELAY Push relay push.bridgeproxy.net holds Apple's key APPLE APNs token + blob nothing readable PHONE Bridge on iOS key in the Keychain decrypts, then shows A forged push can buzz a phone. It cannot put words on it.
Two middle parties carry the push. Neither can read it, and a forged one decrypts to nothing.

Why P-256 and not something more fashionable: both ends have it built in. An iOS notification extension has a hard memory limit and is killed, not warned, when it goes over, so shipping a crypto library into it is a bad trade. And the key is readable after first unlock rather than only while unlocked, because otherwise notifications would decrypt on a phone in your hand and silently fail on one sitting on the table.

The honest consequence: someone who learns a device token can make that phone buzz. They cannot put words on its lock screen.

Who is in the middle, and what they get

Middle partyRun bySeesWorst it can do
Control relay, bridgeproxy.netusyour fingerprint, when and from where you connect, Noise ciphertextstop your devices reaching the control plane
DERP relaysTailscalewhich machines talk and how much, WireGuard ciphertextstop the connections that could not go direct
Push relay, push.bridgeproxy.netusdevice token, topic, push type, sealed blobbuzz a phone whose token it knows
Apple push serviceAppledevice token, topic, sealed blobthe same

None of them holds a key that decrypts anything, and none of them can add a device to your network.

What this does not protect you from