wireproxy
wireproxy copied to clipboard
Fix HTTP proxy authentication to support both preemptive and challenge-response auth
The current HTTP proxy authentication implementation works with clients that use preemptive authentication (like curl) but fails with clients expecting a challenge-response flow (such as Puppeteer and web browsers).
Solution:
- Immediately returning a
407 Proxy Authentication Requiredstatus when no auth header is present. - Adding a
Proxy-Authenticateheader to 407 responses, prompting clients to provide credentials.
Testing with Puppeteer:
Should fail before the change and pass after the fix
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
args: [`--proxy-server=http://0.0.0.0:25345`],
});
const page = await browser.newPage();
await page.authenticate({
username: 'username',
password: 'password',
});
await page.goto('https://httpbin.org/ip');
const body = await page.waitForSelector('body');
const ip = await body.getProperty('textContent');
console.log(await ip.jsonValue());
await browser.close();
})();