Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(wsServer): reject WebSocket upgrades with cross-origin Origin (#40545)
Pavel Feldman212c3a40914c
diff --git a/packages/utils/wsServer.ts b/packages/utils/wsServer.tsindex 1fbbaad456..5eb6502aa5 100644--- a/packages/utils/wsServer.ts+++ b/packages/utils/wsServer.ts@@ -102,6 +102,11 @@ export class WSServer {socket.destroy();return;}+ if (this._allowedHosts && !this._isAllowedOrigin(request.headers.origin)) {+ socket.write(`HTTP/${request.httpVersion} 403 Forbidden\r\n\r\n`);+ socket.destroy();+ return;+ }const upgradeResult = this._delegate.onUpgrade(request, socket);if (upgradeResult) {socket.write(upgradeResult.error);@@ -136,6 +141,18 @@ export class WSServer {this._delegate.onRequest(request, response);}+ private _isAllowedOrigin(origin: string | undefined): boolean {+ if (!origin)+ return true;+ try {+ const hostname = new URL(origin).hostname.toLowerCase();+ const bracketed = hostname.includes(':') ? `[${hostname}]` : hostname;+ return this._allowedHosts!.has(hostname) || this._allowedHosts!.has(bracketed);+ } catch {+ return false;+ }+ }+async close() {const server = this._wsServer;if (!server)