Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 36 ยท Security and Applications

WebRTC Privacy: Permissions, mDNS Candidates and IP Leaks

Understand what WebRTC reveals about users: local and public IP addresses, device labels and permissions. Learn mDNS candidates, relay-only mode, Permissions Policy and good consent UX.

Encryption keeps strangers from reading a call. Privacy is a different question: what does your page learn about the user, and what does the other peer learn? A WebRTC page can reach a camera, a microphone and the screen, and ICE candidates contain network addresses. Handled badly, these leak information the user never agreed to share; handled well, they stay inside clear boundaries.

This lesson covers the three areas that matter: device permissions, IP address exposure, and page-level controls. It also shows what the sandbox in this site's code editor does, since previews run in an isolated frame and cannot reach cameras.

Device permissions

getUserMedia and getDisplayMedia prompt the user. The page never sees the devices until the user allows it, and the browser shows an indicator while the camera or microphone is live.

Facts to design around:

  • Secure context only. navigator.mediaDevices exists only on HTTPS pages and localhost.
  • User gesture and prompt. Call getUserMedia from a click, and explain why before the browser prompt appears. A prompt out of the blue gets denied.
  • Labels are hidden until permission is granted. Before consent, enumerateDevices() returns device kinds and ids, but empty label strings (to stop device fingerprinting).
  • Permissions are per origin and can be remembered or reset by the user.
  • Third-party iframes need delegation: the embedding page must allow them with allow="camera; microphone".
JS What this preview can and cannot access

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In a normal page the last call shows the permission prompt. In this preview it fails because the sandboxed frame has no right to ask. You will see names such as SecurityError or NotAllowedError, which is also what your code sees when a user clicks "Block".

Where the IP address leaks

An ICE candidate is literally a network address, and the page receives and forwards them through signalling. Two problems follow:

  1. Local IP exposure. A host candidate used to contain the machine's private LAN IP (like 192.168.1.20). Any website could read it without any permission prompt, and combined with other data this helps fingerprinting.
  2. Public IP exposure. An srflx candidate reveals the public IP address even behind a VPN, because the browser asks a STUN server through the physical interface. This is the classic "WebRTC leak" found in VPN leak tests.

mDNS host candidates

To fix the first problem, browsers now hide local addresses behind mDNS names: instead of 192.168.1.20 the candidate carries a random name like 3f2a...-....local. Peers on the same LAN can resolve it with multicast DNS, but a website only sees a meaningless name.

Text
candidate:842163049 1 udp 2113937151 7f2c9a1e-3b5d-4c6a-9e0b-1d2f3a4b5c6d.local 54321 typ host

Chrome-family browsers use mDNS by default whenever the page has no camera or microphone permission. Once the user grants capture permission, they may expose real addresses, because the user has shown they intend a call.

JS Do host candidates hide the LAN address?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Controlling the public address

You cannot hide the public IP of a normal connection, because the peer needs some path to you. Your options:

  • iceTransportPolicy: 'relay': use only TURN. The peer sees the TURN server's address, not the user's. The cost is that all traffic goes through your server (TURN Servers).
  • Offer a privacy mode in your app: a "hide my IP" toggle that switches to relay-only.
  • Don't open a peer connection at all just to look up an IP; if you do not need WebRTC on a page, do not create connections there.
JS Relay-only means no direct addresses leave the page

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In a real app you would add a TURN server to iceServers; then the relay-only list contains relay candidates and nothing else.

Page-level controls

  • Permissions-Policy header. A site can say which features its pages and frames may use:

    Text
    Permissions-Policy: camera=(self), microphone=(self), display-capture=(self)
    

    Pages that never need capture should send camera=(), microphone=() to block them even if a script is injected.

  • iframe allow attribute. Embeds only get capture if you opt in: <iframe allow="camera; microphone" ...>.

  • Content Security Policy. Restrict connect-src to your signalling host and your TURN/STUN hosts.

  • No camera on page load. Ask only after a click.

Respecting the user

Good privacy design is mostly good communication:

  • Show why you need the camera before asking, and offer a preview with a clear way to switch devices.
  • Release devices as soon as they are not needed: call track.stop() on every track when a call ends. Stopping the track turns off the camera light.
  • Do not record or upload media without a visible indicator and explicit consent.
  • Remember that screen sharing can expose notifications and other windows; prefer sharing a single window or tab and warn users.
  • Collect the minimum stats; stats can contain IP addresses and should not go to analytics unredacted.
JS Always release devices: a stop-all helper

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Common mistakes

  • Prompting immediately on page load. Users deny and rarely reconsider.
  • Forgetting track.stop(). The camera light stays on after the call UI is gone.
  • Assuming a VPN hides everything. WebRTC can bypass it; test with a leak-check page and prefer relay-only for privacy features.
  • Logging full SDP and candidates. They contain addresses.
  • Allowing capture for every embedded frame. Use a restrictive Permissions-Policy.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does enumerateDevices() return empty labels before permission?

    Device labels are distinctive, so browsers reveal them only after the user grants access.
  2. 2. What does an mDNS host candidate hide?

    The host candidate carries a random .local name instead of the real private address.
  3. 3. How can you keep the user's public IP from the peer?

    With relay-only, the peer sees the TURN server's address instead of the user's.
  4. 4. What turns off the camera indicator light after a call?

    The device is released only when its tracks are stopped; hiding the video element is not enough.

Summary

  • Capture needs HTTPS, a prompt and a user who understands why; labels stay hidden until consent.
  • Host candidates use mDNS names; srflx candidates reveal the public IP even behind a VPN.
  • Use relay-only mode when IP privacy matters, and a Permissions-Policy to limit features.
  • Always stop tracks, keep stats and SDP out of analytics, and explain what you collect.

Next: WebRTC in Real Apps