WebRTC Leaks: How Your Browser Can Reveal Your Real IP Behind a VPN
WebRTC is what lets a browser tab make a video call or send a file straight to another browser. To do that it has to find a network path between two devices, and along the way it collects your device's network addresses.
WebRTC is what lets a browser tab make a video call or send a file straight to another browser. To do that it has to find a network path between two devices, and along the way it collects your device's network addresses. Any web page can ask for that list with a few lines of JavaScript, without a permission prompt.
If you rely on a VPN or a proxy, that list is where your real IP address can slip out. This post explains how the leak happens, shows the code a page needs to see it, and lists the settings that stop it.
Disclosure: I work on GhostSMS, which runs the free WebRTC leak test mentioned at the end.
How WebRTC finds your addresses
Before two peers can talk, each side gathers ICE candidates, the possible addresses the other side might reach:
-
Host candidates: the addresses of your network interfaces, for example
192.168.1.23or an IPv6 address. - Server-reflexive candidates: your public address as seen by a STUN server on the internet.
- Relay candidates: addresses on a TURN relay, if one is configured.
A page never has to start a call to get these. Creating a peer connection and an offer is enough to begin gathering.
The few lines a page needs
const pc = new RTCPeerConnection({
iceServers: [{ urls: 'stun:stun.example.org:3478' }],
});
pc.createDataChannel('probe');
pc.onicecandidate = (event) => {
if (!event.candidate) return; // gathering finished
// e.g. "candidate:842163049 1 udp 1677729535 203.0.113.7 51200 typ srflx ..."
console.log(event.candidate.candidate);
};
pc.createOffer().then((offer) => pc.setLocalDescription(offer));
Each candidate string contains an address and a type (host, srflx or relay). A page can read them and send them to its own server.
When this becomes a leak
A full-device VPN that routes all traffic, UDP included, usually means the STUN server sees the VPN's address, so the srflx candidate shows the VPN IP rather than yours. Leaks happen in the gaps:
- Browser-extension "VPNs" and proxies. Many only proxy HTTP(S) requests. WebRTC's UDP traffic goes around them, so the STUN server sees your real public IP.
- Split tunnelling. If the browser or UDP traffic is excluded from the tunnel, the same thing happens.
- IPv6. A VPN that only tunnels IPv4 can leave your IPv6 address exposed in the candidates.
-
Local addresses. Older browsers exposed private LAN addresses as host candidates. Modern Chrome, Firefox and Safari replace them with random mDNS names ending in
.local, unless the page has camera or microphone permission.
How to stop it
- Use a VPN app that handles WebRTC, then test with the VPN on.
-
Firefox: in
about:config, setmedia.peerconnection.enabledtofalseif you never make browser calls.media.peerconnection.ice.default_address_onlylimits the candidates without turning WebRTC off. - Brave: Settings β Privacy and security β WebRTC IP handling policy β Disable non-proxied UDP.
- Chrome and other Chromium browsers: there is no built-in switch. uBlock Origin's "Prevent WebRTC from leaking local IP addresses" option, or Google's WebRTC Network Limiter extension, changes the IP handling policy.
- Test again after every change. Browser updates and VPN reconnects can reset the behaviour.
Test your own browser
We built a free WebRTC leak test that shows which addresses your browser exposes. It runs in your browser and on our own servers, with no third-party services. The same lab has a browser fingerprint test and an IP and proxy check.
If you also want to keep your phone number out of sign-up forms, that is what GhostSMS does: temporary numbers for one-time SMS codes, no KYC, paid with Monero or other crypto. ghostsms.org
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.