cherry-pick(#22855): fix(server): explicit allowlist for launch options (#22857)

Some options, usually paths, do not make sense when running remotely.
This commit is contained in:
Dmitry Gozman 2023-05-05 15:01:17 -07:00 committed by GitHub
parent 8da3502df5
commit ea963a8e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -57,6 +57,7 @@ export class PlaywrightConnection {
this._ws = ws;
this._preLaunched = preLaunched;
this._options = options;
options.launchOptions = filterLaunchOptions(options.launchOptions);
if (clientType === 'reuse-browser' || clientType === 'pre-launched-browser-or-android')
assert(preLaunched.playwright);
if (clientType === 'pre-launched-browser-or-android')
@ -271,6 +272,21 @@ function launchOptionsHash(options: LaunchOptions) {
return JSON.stringify(copy);
}
function filterLaunchOptions(options: LaunchOptions) {
return {
channel: options.channel,
args: options.args,
ignoreAllDefaultArgs: options.ignoreAllDefaultArgs,
ignoreDefaultArgs: options.ignoreDefaultArgs,
timeout: options.timeout,
headless: options.headless,
proxy: options.proxy,
chromiumSandbox: options.chromiumSandbox,
firefoxUserPrefs: options.firefoxUserPrefs,
slowMo: options.slowMo,
};
}
const defaultLaunchOptions: LaunchOptions = {
ignoreAllDefaultArgs: false,
handleSIGINT: false,

View File

@ -576,6 +576,19 @@ for (const kind of ['launchServer', 'run-server'] as const) {
expect(entry.request.url).toBe(server.EMPTY_PAGE);
});
test('should filter launch options', async ({ connect, startRemoteServer, server, browserType }, testInfo) => {
const tracesDir = testInfo.outputPath('traces');
const oldTracesDir = (browserType as any)._defaultLaunchOptions.tracesDir;
(browserType as any)._defaultLaunchOptions.tracesDir = tracesDir;
const remoteServer = await startRemoteServer(kind);
const browser = await connect(remoteServer.wsEndpoint());
const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE);
await browser.close();
(browserType as any)._defaultLaunchOptions.tracesDir = oldTracesDir;
expect(fs.existsSync(tracesDir)).toBe(false);
});
test('should record trace with sources', async ({ connect, startRemoteServer, server, trace }, testInfo) => {
test.skip(trace === 'on');
const remoteServer = await startRemoteServer(kind);