Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do STUN requests fail when sent from certain websites?

(async function()
{
    var iceServers = [{ urls: ["stun:stun.l.google.com:19302"] }];
    
    var peer = new RTCPeerConnection({ iceServers });
    peer.channel = peer.createDataChannel("channel");
    
    peer.onicecandidate = function(e)
    {
        if(e.candidate)
            console.log(JSON.stringify(e.candidate, null, '\t'));
        else
            console.log("DONE");
    };
    
    peer.onicecandidateerror = (e) => console.error(e);
    
    var offer = await peer.createOffer();
    await peer.setLocalDescription(offer);
})();

I use this sample code to test connecting to a STUN server and listing the generated ICE candidates. If I paste it into the console, depending on what website I'm currently visiting, the icecandidateerror event is triggered. The IPV6 address is full of x's and looks invalid. It happens in Chrome but not Firefox. This is the error I receive:

RTCPeerConnectionIceErrorEvent
address: "[0:0:0:x:x:x:x:x]"
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: RTCPeerConnection {…}
defaultPrevented: false
errorCode: 701
errorText: "STUN host lookup received error."
eventPhase: 0
hostCandidate: "[0:0:0:x:x:x:x:x]:33860"
isTrusted: true
path: []
port: 33860
returnValue: true
srcElement: RTCPeerConnection {…}
target: RTCPeerConnection {…}
timeStamp: 2621.4149999996152
type: "icecandidateerror"
url: "stun:stun.l.google.com:19302"

Here's a list of websites I've tried this code on:

  • https://webrtc.github.io/samples/ - good
  • https://webrtc.github.io/definitelya404page/ - good
  • https://luisfonsivevo.github.io/samples/ - error (this is a fork of the above repo, using the same GitHub pages HTTP server)
  • https://google.com/ - error
  • https://codepen.io/ - good
  • https://stackoverflow.com/ - error

What is it about certain domain names that would cause this error? Could it be a Chrome bug?

like image 922
Luis Fonsi VEVO Avatar asked Oct 26 '25 17:10

Luis Fonsi VEVO


1 Answers

You probably have acquired permissions for camera access for the origin of the sites that are marked 'good'. That changes the behaviour.

Mandatory disclaimer: webrtc was not build to gather ip addresses.

like image 93
Philipp Hancke Avatar answered Oct 28 '25 06:10

Philipp Hancke