Privacy Tools Guide

WebRTC (Real-Time Communication) is a browser feature that enables direct peer-to-peer communication for services like Google Meet, Discord, and Zoom. However, it can inadvertently reveal your real IP address even when you’re connected to a VPN—a vulnerability known as a WebRTC leak. This guide walks you through testing methods to detect WebRTC leaks, understand the risks, and implement effective mitigation strategies.

What is a WebRTC Leak?

WebRTC leaks occur when browsers use the STUN (Session Traversal Utilities for NAT) protocol to discover your public IP address through UDP connections, bypassing your VPN tunnel. Both your real IP and your VPN-assigned IP can be exposed, compromising your anonymity. This happens because WebRTC queries STUN servers to establish peer-to-peer connections, and these queries occur outside the normal VPN routing.

The vulnerability affects all major browsers including Chrome, Firefox, Safari, and Edge. Even if you’ve configured your VPN correctly and see a VPN IP address in other tests, WebRTC can still expose your true location. Understanding this threat is essential for anyone serious about online privacy, particularly journalists, activists, and security professionals.

Testing for WebRTC Leaks

Method 1: Online WebRTC Leak Testing Tools

The quickest way to test for WebRTC leaks is using specialized online tools. These services perform the STUN requests directly in your browser and display any IP addresses that WebRTC reveals.

Start by disconnecting from your VPN and noting your real IP address. Then connect to your VPN and visit a WebRTC leak testing site. Look for any IP addresses that differ from your VPN-assigned IP. If your real IP appears, you have a WebRTC leak. Popular testing tools include BrowserLeaks, IP8, and DuckDuckGo’s privacy test page.

When using these tools, ensure your VPN is actually connected—some tools will warn you if they detect you’re not using a VPN. Also test on multiple browsers since Chrome might leak while Firefox doesn’t, depending on your configuration.

Method 2: Manual Browser Console Testing

For a more technical verification, you can test WebRTC leaks directly in your browser’s developer console. This method gives you granular control and doesn’t rely on third-party services.

Open your browser’s developer tools (F12 or right-click and select Inspect), then navigate to the Console tab. Paste the following JavaScript code to enumerate all active RTCPeerConnection instances:

async function testWebRTCLeak() {
  const peerConnections = [];
  const seenIPs = new Set();

  // Override RTCPeerConnection to capture instances
  const OriginalRTCPeerConnection = window.RTCPeerConnection;
  window.RTCPeerConnection = function(...args) {
    const pc = new OriginalRTCPeerConnection(...args);
    peerConnections.push(pc);

    pc.createDataChannel('');
    return pc;
  };

  // Create a test connection
  const pc = new RTCPeerConnection({
    iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
  });

  pc.createOffer().then(offer => pc.setLocalDescription(offer));

  // Wait for ICE candidates
  await new Promise(resolve => setTimeout(resolve, 2000));

  // Check for leaked IPs
  peerConnections.forEach(p => {
    p.getReceivers().forEach(r => {
      if (r.transport && r.transport.transport) {
        r.transport.transport._candidatePairStats.forEach(stat => {
          if (stat.candidateType !== 'host') {
            seenIPs.add(stat.ip);
          }
        });
      }
    });
  });

  console.log('Potential leaked IPs:', [...seenIPs]);

  // Cleanup
  peerConnections.forEach(p => p.close());
}

testWebRTCLeak();

This script creates a test WebRTC connection and monitors which IP addresses are exposed. The stun:stun.l.google.com:19302 server is Google’s public STUN server, commonly used in WebRTC implementations. Any IP addresses that appear in the output (other than your VPN IP) indicate a potential leak.

Method 3: Command-Line Testing with Python

For automated or repeatable testing, you can use Python with the aiodns and aioice libraries to simulate STUN requests programmatically. This approach is useful for integrating WebRTC leak testing into larger security assessment workflows.

First, install the required dependencies:

pip install aiodns aioice stun

Then create a Python script to test for WebRTC leaks:

import asyncio
import stun

async def test_webrtc_leak():
    # Get your apparent IP using STUN
    # Using Google's public STUN server
    nat_type, external_ip, external_port = stun.get_ip_info(
        stun.STUN_SERVERS[0]
    )

    print(f"Detected external IP: {external_ip}")
    print("If this IP differs from your VPN IP, you have a WebRTC leak")

    # Test with multiple STUN servers for completeness
    for server in stun.STUN_SERVERS[:3]:
        try:
            nat_type, external_ip, _ = stun.get_ip_info(server)
            print(f"STUN server {server}: {external_ip}")
        except Exception as e:
            print(f"Error with {server}: {e}")

if __name__ == "__main__":
    asyncio.run(test_webrtc_leak())

This script queries multiple STUN servers and reports the detected IP addresses. Run this script both with and without your VPN connected to compare results. If the reported IP changes when you connect to your VPN, your WebRTC implementation is working correctly—but remember that browser-level WebRTC can still leak even if this test passes.

Mitigating WebRTC Leaks

Browser Extension Solutions

The simplest mitigation is using a browser extension that blocks WebRTC requests. Extensions like WebRTC Leak Shield, uBlock Origin (with WebRTC blocking enabled), or Privacy Badger can prevent STUN requests from executing. However, extensions vary in effectiveness—some only disable WebRTC entirely while others allow it but filter leaking IPs.

To enable WebRTC blocking in uBlock Origin, go to Settings and check “Prevent WebRTC from leaking local IP addresses”. This setting modifies browser configuration to block the leak vectors while allowing WebRTC functionality for sites that need it.

Browser Configuration

For more control, configure your browser directly. In Firefox, set media.peerconnection.enabled to false in about:config to disable WebRTC entirely. This breaks features like video calling but guarantees protection against leaks.

Chrome users can use the “WebRTC Network Limiter” extension from Google or modify Chrome’s flags. Navigate to chrome://flags/#webrtc-ip-handling-policy and select “Disable non-proxied UDP” or “Default” with non-default ICE candidate settings.

VPN-Side Protection

Some VPN providers implement WebRTC leak protection on their clients. This typically involves firewall rules that block UDP traffic except through the VPN tunnel, or by intercepting and filtering STUN requests at the application level. Check if your VPN provider offers this feature—it provides protection regardless of browser configuration.

Testing After Mitigation

After implementing mitigation strategies, verify they work by repeating the testing methods described above. Browser extensions can sometimes be bypassed by determined attackers, and configuration settings may reset after browser updates. Make testing a regular part of your security routine, especially when using sensitive services.

Test on all browsers you use, since each handles WebRTC differently. Chrome’s Chromium-based browsers share similar protections, while Firefox has its own independent implementation. Mobile browsers also need testing—iOS Safari and Android Chrome both support WebRTC and may leak.

Understanding the Risk

The severity of a WebRTC leak depends on your threat model. For average users, IP exposure might mean targeted ads or basic geographic tracking. For journalists, activists, or those bypassing censorship, a leaked IP can have serious consequences including identity exposure or physical danger.

WebRTC leaks are particularly dangerous because they’re invisible to most users—you won’t notice them in normal browsing. Regular testing, especially after browser updates or VPN configuration changes, is essential for maintaining privacy. Combine WebRTC protection with other privacy tools like HTTPS Everywhere, a quality VPN, and privacy-focused search engines for defense in depth.

Advanced Testing with tcpdump

For sophisticated verification, use packet capture to observe actual network traffic:

# Install tcpdump if needed
sudo apt-get install tcpdump  # Linux
brew install tcpdump  # macOS

# Capture WebRTC traffic (listen on all interfaces)
sudo tcpdump -i any -n 'tcp port 3478 or udp port 3478' -w webrtc_capture.pcap

# In another terminal, trigger WebRTC connection and then Ctrl+C the capture

# Analyze captured packets
tcpdump -r webrtc_capture.pcap -X | head -50

This approach reveals exactly which IP addresses your device contacts, providing definitive evidence of leaks that testing tools might miss.

Testing Across Different Network Conditions

WebRTC behavior varies depending on network conditions. Test in multiple scenarios:

Test 1: Connected VPN on Home WiFi

# Connect VPN first
vpn_status=$(systemctl status wireguard@wg0 | grep active)

# Run leak test
echo "VPN Status: $vpn_status"
python3 test_webrtc.py

# Expected: Only VPN IP should appear

Test 2: Mobile Hotspot (4G/5G) Network providers sometimes implement different blocking for cellular data. Test your VPN performance on mobile networks:

# Connect to phone hotspot, then test
# Mobile carriers may have different STUN blocking characteristics

Test 3: Untrusted Public WiFi Coffee shop WiFi represents a realistic threat scenario. Test there:

# Connect to public WiFi first, then VPN, then test
# Verify VPN connection quality and leak status

Test 4: Corporate Network If accessing from office networks with proxies, test WebRTC behavior:

# Behind corporate proxy, test whether WebRTC respects proxy settings
# Some proxies interfere with VPN/STUN interactions

Interpreting Test Results

Understanding what results mean matters as much as getting them:

Pass Result: Only your VPN-assigned IP appears in tests. This indicates your WebRTC implementation is correctly routing through the VPN.

Fail Result: Your real IP appears alongside your VPN IP. You have a WebRTC leak requiring mitigation.

Incomplete Result: Some tests show your VPN IP but not your real IP. This might indicate:

Browser-Specific Testing Matrix

Different browsers leak differently. Test comprehensively:

#!/bin/bash
# Test WebRTC leaks across all installed browsers

BROWSERS=("google-chrome" "firefox" "microsoft-edge" "brave-browser")

for browser in "${BROWSERS[@]}"; do
    if command -v $browser &> /dev/null; then
        echo "Testing $browser..."
        $browser http://localhost:8000/webrtc-test.html &
        sleep 5
        pkill $browser
        echo "---"
    fi
done

Record results for each browser. You may find that one browser needs different configuration than others.

WebRTC Leak Severity Assessment

Not all WebRTC leaks are equally severe:

Severe: Your real IP is exposed while you believe you’re using a VPN. This indicates the VPN itself may be misconfigured or ineffective.

Moderate: Your real IP is exposed alongside your VPN IP. This reveals you’re using a VPN (potentially suspicious to ISPs or networks) but your traffic is still encrypted through the VPN.

Minimal: Only your VPN IP appears, but additional analysis shows it’s slightly different from your VPN’s public announcement. This level of leak has minimal practical impact.

VPN Provider Comparison for WebRTC Handling

Some VPN providers handle WebRTC better than others:

Provider Default WebRTC Blocking Method Leak Risk
Mullvad VPN Leaks Network isolation Low
ProtonVPN Leaks Requires extension Medium
IVPN Leaks Network isolation Low
Perfect Privacy Filters VPN-level filtering Very Low
Windscribe Mixed Depends on protocol Medium

Test your specific VPN provider rather than relying on general reputation. Implementations vary.

Automating Regular WebRTC Leak Testing

Set up automated testing to catch regressions:

#!/usr/bin/env python3
import subprocess
import time
from datetime import datetime
import stun

def test_webrtc_leaks():
    """Run WebRTC leak test and log results"""

    results = {
        'timestamp': datetime.utcnow().isoformat(),
        'ips': set(),
        'leaked': False
    }

    # Get real IP (without VPN)
    try:
        real_ip = subprocess.check_output(
            ['curl', '-s', 'https://api.ipify.org'],
            timeout=5
        ).decode().strip()
    except:
        real_ip = "unknown"

    # Get VPN IP
    try:
        vpn_ip = subprocess.check_output(
            ['curl', '-s', '--socks5', 'localhost:9050', 'https://api.ipify.org'],
            timeout=5
        ).decode().strip()
    except:
        vpn_ip = "unknown"

    # Test WebRTC
    for server in stun.STUN_SERVERS[:3]:
        try:
            nat_type, external_ip, _ = stun.get_ip_info(server)
            results['ips'].add(external_ip)
        except:
            pass

    # Check for leak
    if real_ip in results['ips']:
        results['leaked'] = True

    return results

def alert_on_leak(results):
    """Send alert if leak detected"""
    if results['leaked']:
        # Send email or Slack notification
        print(f"ALERT: WebRTC leak detected at {results['timestamp']}")
        print(f"Leaked IPs: {results['ips']}")

# Run test
if __name__ == "__main__":
    results = test_webrtc_leaks()
    alert_on_leak(results)
    print(f"Test results: {results}")

Run this script daily via cron to catch new leaks automatically:

# Add to crontab -e
0 9 * * * /home/user/test-webrtc.py >> /home/user/webrtc-test.log 2>&1

Defense-in-Depth Strategy

WebRTC leak testing is one component of VPN protection:

  1. Network Level: Use VPN with firewall rules blocking WebRTC
  2. Browser Level: Install extension blocking WebRTC or configure browser settings
  3. Testing Level: Regular WebRTC leak testing to catch failures
  4. Monitoring Level: Automated testing with alerts for regressions
  5. Trust Level: Verify your VPN provider’s commitment to WebRTC protection

This layered approach ensures WebRTC leaks become extremely unlikely even if one component fails.

Built by theluckystrike — More at zovo.one