Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(proxy): throw when socks proxy is used with auth #5358

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ export function normalizeProxySettings(proxy: types.ProxySettings): types.ProxyS
} catch (e) {
url = new URL('http://' + server);
}
if (url.protocol === 'socks4:' && (proxy.username || proxy.password))
throw new Error(`Socks4 proxy protocol does not support authentication`);
if (url.protocol === 'socks5:' && (proxy.username || proxy.password))
throw new Error(`Browser does not support socks5 proxy authentication`);
server = url.protocol + '//' + url.host;
if (bypass)
bypass = bypass.split(',').map(t => t.trim()).join(',');
Expand Down
16 changes: 16 additions & 0 deletions test/browsercontext-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ it('should work with IP:PORT notion', async ({contextFactory, contextOptions, se
await browser.close();
});

it('should throw for socks5 authentication', async ({contextFactory, contextOptions}) => {
const error = await contextFactory({
...contextOptions,
proxy: { server: `socks5://localhost:1234`, username: 'user', password: 'secret' }
}).catch(e => e);
expect(error.message).toContain('Browser does not support socks5 proxy authentication');
});

it('should throw for socks4 authentication', async ({contextFactory, contextOptions}) => {
const error = await contextFactory({
...contextOptions,
proxy: { server: `socks4://localhost:1234`, username: 'user', password: 'secret' }
}).catch(e => e);
expect(error.message).toContain('Socks4 proxy protocol does not support authentication');
});

it('should authenticate', async ({contextFactory, contextOptions, server}) => {
server.setRoute('/target.html', async (req, res) => {
const auth = req.headers['proxy-authorization'];
Expand Down