fix: match against secure path (#13442)

This commit is contained in:
Yury Semikhatsky 2022-04-08 14:57:43 -07:00 committed by GitHub
parent 212c665152
commit 9712b9ee08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View File

@ -658,7 +658,7 @@ async function launchGridServer(factoryPathOrPackageName: string, port: number,
factory.name = factory.name || factoryPathOrPackageName;
const gridServer = new GridServer(factory as GridFactory, authToken, address);
await gridServer.start(port);
console.log('Grid server is running at ' + gridServer.urlPrefix());
console.log('Grid server is running at ' + gridServer.gridURL());
}
function buildBasePlaywrightCLICommand(cliTargetLang: string | undefined): string {

View File

@ -253,7 +253,8 @@ export class GridServer {
return true;
}
if (request.url!.startsWith('/registerAgent') || request.url!.startsWith('/registerWorker')) {
if (request.url!.startsWith(this._securePath('/registerAgent'))
|| request.url!.startsWith(this._securePath('/registerWorker'))) {
const params = new URL('http://localhost/' + request.url).searchParams;
const agentId = params.get('agentId');
return !!agentId && this._agents.has(agentId);
@ -285,7 +286,7 @@ export class GridServer {
return;
}
if (request.url?.startsWith('/registerAgent')) {
if (request.url?.startsWith(this._securePath('/registerAgent'))) {
const params = new URL('http://localhost/' + request.url).searchParams;
if (params.get('pwVersion') !== this._pwVersion) {
ws.close(WSErrors.AGENT_PLAYWRIGHT_VERSION_MISMATCH.code, WSErrors.AGENT_PLAYWRIGHT_VERSION_MISMATCH.reason);
@ -302,7 +303,7 @@ export class GridServer {
return;
}
if (request.url?.startsWith('/registerWorker')) {
if (request.url?.startsWith(this._securePath('/registerWorker'))) {
const params = new URL('http://localhost/' + request.url).searchParams;
const agentId = params.get('agentId')!;
const workerId = params.get('workerId')!;
@ -332,7 +333,7 @@ export class GridServer {
const initPromise = Promise.resolve()
.then(() => this._factory.launch({
agentId: agent.agentId,
gridURL: this.urlPrefix(),
gridURL: this.gridURL(),
playwrightVersion: getPlaywrightVersion(),
})).then(() => {
this._log('created');
@ -386,8 +387,8 @@ export class GridServer {
await this._server.start(port);
}
urlPrefix(): string {
return this._server.urlPrefix() + this._securePath('/');
gridURL(): string {
return this._server.urlPrefix() + this._securePath('');
}
async stop() {

View File

@ -242,7 +242,7 @@ async function launchDockerContainer(): Promise<() => Promise<void>> {
const { error } = await gridServer.createAgent();
if (error)
throw error;
process.env.PW_GRID = gridServer.urlPrefix().substring(0, gridServer.urlPrefix().length - 1);
process.env.PW_GRID = gridServer.gridURL();
return async () => await gridServer.stop();
}