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(server): default run-server and launchServer to localhost (#40500)
Pavel Feldmana8ad57fcb456
diff --git a/docs/src/api/class-android.md b/docs/src/api/class-android.mdindex ffef68509d..4427622b6a 100644--- a/docs/src/api/class-android.md+++ b/docs/src/api/class-android.md@@ -206,7 +206,7 @@ throw if multiple devices are connected.* since: v1.45- `host` <[string]>-Host to use for the web socket. It is optional and if it is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider hardening it with picking a specific interface.+Host to use for the web socket. It is optional and defaults to `localhost`, accepting connections only from the loopback interface. Pass an explicit address (e.g. `0.0.0.0`) to accept connections from the network — be aware this exposes the device RPC to anything that can reach the listening port.### option: Android.launchServer.port* since: v1.28diff --git a/docs/src/api/class-browserserver.md b/docs/src/api/class-browserserver.mdindex 0de5c1228b..21f318a70a 100644--- a/docs/src/api/class-browserserver.md+++ b/docs/src/api/class-browserserver.md@@ -31,5 +31,3 @@ Browser websocket url.Browser websocket endpoint which can be used as an argument to [`method: BrowserType.connect`] to establish connectionto the browser.--Note that if the listen `host` option in `launchServer` options is not specified, localhost will be output anyway, even if the actual listening address is an unspecified address.diff --git a/docs/src/api/class-browsertype.md b/docs/src/api/class-browsertype.mdindex ce815d6e8a..e3f52a8503 100644--- a/docs/src/api/class-browsertype.md+++ b/docs/src/api/class-browsertype.md@@ -405,7 +405,7 @@ const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'.* since: v1.45- `host` <[string]>-Host to use for the web socket. It is optional and if it is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider hardening it with picking a specific interface.+Host to use for the web socket. It is optional and defaults to `localhost`, accepting connections only from the loopback interface. Pass an explicit address (e.g. `0.0.0.0`) to accept connections from the network — be aware this exposes the browser RPC to anything that can reach the listening port.### option: BrowserType.launchServer.port* since: v1.8diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.tsindex 527243cd56..69ce47e5b6 100644--- a/packages/playwright-client/types/types.d.ts+++ b/packages/playwright-client/types/types.d.ts@@ -16100,9 +16100,9 @@ export interface BrowserType<Unused = {}> {headless?: boolean;/**- * Host to use for the web socket. It is optional and if it is omitted, the server will accept connections on the- * unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider- * hardening it with picking a specific interface.+ * Host to use for the web socket. It is optional and defaults to `localhost`, accepting connections only from the+ * loopback interface. Pass an explicit address (e.g. `0.0.0.0`) to accept connections from the network — be aware+ * this exposes the browser RPC to anything that can reach the listening port.*/host?: string;@@ -17348,9 +17348,9 @@ export interface Android {deviceSerialNumber?: string;/**- * Host to use for the web socket. It is optional and if it is omitted, the server will accept connections on the- * unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider- * hardening it with picking a specific interface.+ * Host to use for the web socket. It is optional and defaults to `localhost`, accepting connections only from the+ * loopback interface. Pass an explicit address (e.g. `0.0.0.0`) to accept connections from the network — be aware+ * this exposes the device RPC to anything that can reach the listening port.*/host?: string;@@ -19526,9 +19526,6 @@ export interface BrowserServer {* Browser websocket endpoint which can be used as an argument to* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect)* to establish connection to the browser.- *- * Note that if the listen `host` option in `launchServer` options is not specified, localhost will be output anyway,- * even if the actual listening address is an unspecified address.*/wsEndpoint(): string;diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.tsindex 527243cd56..69ce47e5b6 100644--- a/packages/playwright-core/types/types.d.ts+++ b/packages/playwright-core/types/types.d.ts@@ -16100,9 +16100,9 @@ export interface BrowserType<Unused = {}> {headless?: boolean;/**- * Host to use for the web socket. It is optional and if it is omitted, the server will accept connections on the- * unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider- * hardening it with picking a specific interface.+ * Host to use for the web socket. It is optional and defaults to `localhost`, accepting connections only from the+ * loopback interface. Pass an explicit address (e.g. `0.0.0.0`) to accept connections from the network — be aware+ * this exposes the browser RPC to anything that can reach the listening port.*/host?: string;@@ -17348,9 +17348,9 @@ export interface Android {deviceSerialNumber?: string;/**- * Host to use for the web socket. It is optional and if it is omitted, the server will accept connections on the- * unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider- * hardening it with picking a specific interface.+ * Host to use for the web socket. It is optional and defaults to `localhost`, accepting connections only from the+ * loopback interface. Pass an explicit address (e.g. `0.0.0.0`) to accept connections from the network — be aware+ * this exposes the device RPC to anything that can reach the listening port.*/host?: string;@@ -19526,9 +19526,6 @@ export interface BrowserServer {* Browser websocket endpoint which can be used as an argument to* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect)* to establish connection to the browser.- *- * Note that if the listen `host` option in `launchServer` options is not specified, localhost will be output anyway,- * even if the actual listening address is an unspecified address.*/wsEndpoint(): string;diff --git a/packages/utils/wsServer.ts b/packages/utils/wsServer.tsindex ffc83a6a58..921a24dbd7 100644--- a/packages/utils/wsServer.ts+++ b/packages/utils/wsServer.ts@@ -60,6 +60,10 @@ export class WSServer {async listen(port: number = 0, hostname: string | undefined, path: string): Promise<string> {debugLogger.log('server', `Server started at ${new Date()}`);+ // Default to loopback so the WebSocket RPC is not exposed to the network unless+ // the caller explicitly opts in by passing a host (e.g. '0.0.0.0').+ hostname ??= 'localhost';+const server = createHttpServer(this._delegate.onRequest);server.on('error', error => debugLogger.log('server', String(error)));this.server = server;@@ -71,7 +75,7 @@ export class WSServer {reject(new Error('Could not bind server socket'));return;}- const wsEndpoint = typeof address === 'string' ? `${address}${path}` : `ws://${hostname || 'localhost'}:${address.port}${path}`;+ const wsEndpoint = typeof address === 'string' ? `${address}${path}` : `ws://${hostname}:${address.port}${path}`;resolve(wsEndpoint);}).on('error', reject);});