question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent IP leak. WebRTC

See original GitHub issue

I have installed TOR in my server, and using it as proxy server for puppeteer. It is running on port 9060

// Dependencies
const puppeteer = require('puppeteer');
const fs = require('fs');
const request = require('request');

const USER_AGENTS = [
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0'
];

const SS_PATH = '/var/www/storage/app/public/images/';

// Variables
let page = null;

let response = {success: true, screenshot: null, message: null};

async function register()
{
    
    try 
    {
        
        const extensionPath = 'extensions/webrtc';

        await puppeteer.launch({ userDataDir: './cache', slowMo: 10, headless: true, args:[ 
            `--disable-extensions-except=${extensionPath}`,
            `--load-extension=${extensionPath}`,
            '--lang=en-US,en',
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--disable-infobars',
            '--proxy-server=socks5://127.0.0.1:9060'],
            ignoreHTTPSErrors: true, dumpio: false 
        }).then(async browser => {
            
            await createTab(browser);
            
            await page.evaluateOnNewDocument(() => {
                chrome.privacy.network.webRTCIPHandlingPolicy.set({
                    value: "default_public_interface_only" 
                });
            });

            await page.goto('https://www.expressvpn.com/webrtc-leak-test');

            await page.waitFor(20000);

            let screenshotName5 = `ipleak${Date.now()}.jpg`;
            response.screenshot = screenshotName5;
            await takeScreenshot(screenshotName5, page);

            process.exit();
            await browser.close();

        });

    } catch(err) {

        console.log(err);

    }
  
}

register().then(function()
{

    console.log(JSON.stringify(response));
    process.exit();

});

// Creates new tab
async function createTab(browser)
{

	page = await browser.newPage();
	page.on('error', err=> {});
    page.on('pageerror', err=> {});
    
    await page.deleteCookie(...cookies);
    await page._client.send('Network.clearBrowserCookies');
    await page.setViewport({
        width: 1920,
        height: 1080
    });
    await page.setUserAgent(
        USER_AGENTS[Math.floor(Math.random()*USER_AGENTS.length)]
    );
    await page.setExtraHTTPHeaders({
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/png,*/*;q=0.8',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en;q=0.9',
        'Connection': 'keep-alive'
    });

}

// Takes screenshot
async function takeScreenshot(name, page)
{

    let options = {
        path: SS_PATH+'/'+name,
        fullPage: true
    }
    await page.screenshot(options);  

}

Tell us about your environment:

  • Puppeteer version: 1.13 (I guess, I installed newest version a month ago)
  • Platform / OS version: Ubuntu 18.04
  • URLs (if applicable):
  • Node.js version: v10.11.0

What is the expected result?

See that my public sever’s IP is not leaking.

What happens instead?

I see this:

Untitled

Even tough I am using TOR, i see that my real IP address is leaking through WebRTC.

Im sure that TOR proxy is working cause puppeteer works fine and if I go to whatismyip.com I see a different IP addres than mine’s.

As you can see I tried to use this: https://github.com/GoogleChrome/puppeteer/issues/2878

as a solution, but it didn’t help. (I assume extension works fine, cause I get no errors while running the code).

So my question is, how can I disable WebRTC so it won’t leak my public IP address?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

27reactions
ediweissmanncommented, Nov 6, 2019

Another way to do it:

await page.evaluateOnNewDocument(
        `navigator.mediaDevices.getUserMedia = navigator.webkitGetUserMedia = navigator.mozGetUserMedia = navigator.getUserMedia = webkitRTCPeerConnection = RTCPeerConnection = MediaStreamTrack = undefined;`
      );
1reaction
aslushnikovcommented, Mar 15, 2019

@dudeperfect95 you can pass a comma-separated list of paths for both --disable-extensions-except and --load-extension flags.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable WebRTC and prevent leaks - NordVPN
By far the simplest way is to block WebRTC leaks by using NordVPN. Whether you're using our regular VPN or our browser plugins...
Read more >
WebRTC leak: how to test & prevent IP leaks - Surfshark
As long as WebRTC is turned on in your browser and you're on a website that uses it, your real IP address will...
Read more >
How to stop WebRTC leaks on Chrome or any browser ...
How to stop WebRTC leaks in Safari · Open Safari and go to Safari > Preferences… · Go to the Advanced tab and...
Read more >
WebRTC Leak Prevent
Prevent WebRTC leaks in Chrome by controlling hidden WebRTC privacy settings. This will protect against WebRTC leaks. Test for leaks here ...
Read more >
What Is WebRTC Leak (How to Protect Yourself From It)
How to Fix and Prevent WebRTC Leak Issues · 1. Disable WebRTC in Your Browser · 2. Use Add-Ons and Extensions to Disable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found