Skip to content

Commit 6e21476

Browse files
feat: validate browser.createUserContext:proxy
1 parent 67b5db3 commit 6e21476

File tree

2 files changed

+217
-132
lines changed

2 files changed

+217
-132
lines changed

src/bidiMapper/modules/browser/BrowserProcessor.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ export class BrowserProcessor {
188188
}
189189
}
190190

191+
export function asserProxyHost(proxyHost: string): void {
192+
// A "host and optional port" string is defined as being a valid host, optionally
193+
// followed by a colon and a valid port.
194+
if (proxyHost.includes('://')) {
195+
throw new InvalidArgumentException('Proxy URL should not have a scheme');
196+
}
197+
if (proxyHost.includes('/')) {
198+
throw new InvalidArgumentException('Proxy URL should not have a path');
199+
}
200+
if (proxyHost.includes('?')) {
201+
throw new InvalidArgumentException(
202+
'Proxy URL should not have search parameters',
203+
);
204+
}
205+
if (proxyHost.includes('#')) {
206+
throw new InvalidArgumentException('Proxy URL should not have a hash');
207+
}
208+
209+
try {
210+
new URL(`http://${proxyHost}`);
211+
} catch (error) {
212+
throw error instanceof TypeError
213+
? new InvalidArgumentException(
214+
`Invalid proxy format: ${proxyHost}. ${error.message}`,
215+
)
216+
: error;
217+
}
218+
}
219+
191220
/**
192221
* Proxy config parse implementation:
193222
* https://source.chromium.org/chromium/chromium/src/+/main:net/proxy_resolution/proxy_config.h;drc=743a82d08e59d803c94ee1b8564b8b11dd7b462f;l=107
@@ -222,13 +251,13 @@ export function getProxyStr(
222251

223252
// HTTP Proxy
224253
if (proxyConfig.httpProxy !== undefined) {
225-
// servers.push(proxyConfig.httpProxy);
254+
asserProxyHost(proxyConfig.httpProxy);
226255
servers.push(`http=${proxyConfig.httpProxy}`);
227256
}
228257

229258
// SSL Proxy (uses 'https' scheme)
230259
if (proxyConfig.sslProxy !== undefined) {
231-
// servers.push(proxyConfig.sslProxy);
260+
asserProxyHost(proxyConfig.sslProxy);
232261
servers.push(`https=${proxyConfig.sslProxy}`);
233262
}
234263

@@ -255,6 +284,7 @@ export function getProxyStr(
255284
`'socksVersion' must be between 0 and 255`,
256285
);
257286
}
287+
asserProxyHost(proxyConfig.socksProxy);
258288
servers.push(
259289
`socks=socks${proxyConfig.socksVersion}://${proxyConfig.socksProxy}`,
260290
);

0 commit comments

Comments
 (0)