Skip to content

Chrome DevTools for coding agents

fix: validate install_pwa and launch_pwa URLs against navigation policy (#3464)

yulunz057a6aaa93aa
diff --git a/docs/configuration.md b/docs/configuration.md
index 56ef78f7..84966714 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -220,7 +220,7 @@ The Chrome DevTools MCP server supports the following configuration option:
- **Default:** `true`
- **`--fileNavigations`/ `--file-navigations`**
- Set to false to disallow navigating to file: URLs. When disabled, new_page, navigate_page and the slim navigate tool reject file: URLs, including view-source: URLs that target them. This restricts navigations the server performs. It is not a filesystem sandbox: it does not affect pages the browser already had open when the server connected, and the browser can reach the filesystem by other means. Use OS sandboxing for full filesystem confinement.
+ Set to false to disallow navigating to file: URLs. When disabled, new_page, navigate_page, the slim navigate tool, install_pwa and launch_pwa reject file: URLs, including view-source: URLs that target them. This restricts navigations the server performs. It is not a filesystem sandbox: it does not affect pages the browser already had open when the server connected, and the browser can reach the filesystem by other means. Use OS sandboxing for full filesystem confinement.
- **Type:** boolean
- **Default:** `true`
diff --git a/src/config/mcp-options.ts b/src/config/mcp-options.ts
index b116aebd..7dc214f1 100644
--- a/src/config/mcp-options.ts
+++ b/src/config/mcp-options.ts
@@ -208,7 +208,7 @@ export const mcpOptions: McpOptions = {
type: 'boolean',
default: true,
describe:
- 'Set to false to disallow navigating to file: URLs. When disabled, new_page, navigate_page and the slim navigate tool reject file: URLs, including view-source: URLs that target them. This restricts navigations the server performs. It is not a filesystem sandbox: it does not affect pages the browser already had open when the server connected, and the browser can reach the filesystem by other means. Use OS sandboxing for full filesystem confinement.',
+ 'Set to false to disallow navigating to file: URLs. When disabled, new_page, navigate_page, the slim navigate tool, install_pwa and launch_pwa reject file: URLs, including view-source: URLs that target them. This restricts navigations the server performs. It is not a filesystem sandbox: it does not affect pages the browser already had open when the server connected, and the browser can reach the filesystem by other means. Use OS sandboxing for full filesystem confinement.',
reloadable: true,
},
sourceMaps: {
diff --git a/src/tools/pwa.ts b/src/tools/pwa.ts
index 0418001e..0d6da040 100644
--- a/src/tools/pwa.ts
+++ b/src/tools/pwa.ts
@@ -4,11 +4,21 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import type {ParsedArguments} from '../config/mcp-options.js';
import {zod} from '../third_party/index.js';
+import {validateUrl} from '../utils/url.js';
import {ToolCategory} from './categories.js';
import {defineTool, type ToolFactory} from './ToolDefinition.js';
+function validatePwaUrl(url: string, args: ParsedArguments): void {
+ validateUrl(url, {
+ javascriptEvaluation: args.javascriptEvaluation,
+ categoryExtensions: args.categoryExtensions,
+ fileNavigations: args.fileNavigations,
+ });
+}
+
const manifestIdSchema = zod
.string()
.describe(
@@ -28,7 +38,7 @@ const displayModeSchema = zod
'app-window experience.',
);
-export const installPwa: ToolFactory = defineTool(() => ({
+export const installPwa: ToolFactory = defineTool((args: ParsedArguments) => ({
name: 'install_pwa',
description:
'Installs a Progressive Web App (PWA) identified by its manifest ID. ' +
@@ -64,6 +74,12 @@ export const installPwa: ToolFactory = defineTool(() => ({
},
handler: async (request, response, context) => {
const {manifestId, installUrlOrBundleUrl, displayMode} = request.params;
+ // Without an install URL, the browser installs from the manifest ID.
+ validatePwaUrl(manifestId, args);
+ // A plain file path is not a URL and was already confined to the roots.
+ if (installUrlOrBundleUrl && URL.canParse(installUrlOrBundleUrl)) {
+ validatePwaUrl(installUrlOrBundleUrl, args);
+ }
await context.installPWA({
manifestId,
installUrlOrBundleUrl,
@@ -103,7 +119,7 @@ export const uninstallPwa: ToolFactory = defineTool(() => ({
},
}));
-export const launchPwa: ToolFactory = defineTool(() => ({
+export const launchPwa: ToolFactory = defineTool((args: ParsedArguments) => ({
name: 'launch_pwa',
description:
'Launches an installed Progressive Web App using its saved display mode. ' +
@@ -127,6 +143,9 @@ export const launchPwa: ToolFactory = defineTool(() => ({
verifyFilesSchema: {},
handler: async (request, response, context) => {
const {manifestId, url} = request.params;
+ if (url !== undefined) {
+ validatePwaUrl(url, args);
+ }
const page = await context.launchPWA({manifestId, url});
response.appendResponseLine(
`Launched PWA with manifest ID: ${manifestId} (${page.url()})`,
diff --git a/tests/tools/pwa.test.ts b/tests/tools/pwa.test.ts
index 61605b08..6c18200c 100644
--- a/tests/tools/pwa.test.ts
+++ b/tests/tools/pwa.test.ts
@@ -178,6 +178,105 @@ describe('pwa', () => {
sinon.assert.alwaysCalledWithExactly(response.setIncludePages, true);
});
+ it('install_pwa rejects a file: bundle URL when fileNavigations is disabled', async () => {
+ const {context, response, args} = createHandlerMocks({
+ fileNavigations: false,
+ });
+
+ await assert.rejects(
+ installPwa(args).handler(
+ {
+ params: {
+ manifestId: 'isolated-app://app/',
+ installUrlOrBundleUrl: 'file:///tmp/app.swbn',
+ },
+ },
+ response,
+ context,
+ ),
+ /Navigating to file: URLs is not allowed/,
+ );
+ sinon.assert.notCalled(context.installPWA);
+ });
+
+ it('install_pwa rejects a restricted manifest ID or install URL', async () => {
+ const {context, response, args} = createHandlerMocks({
+ javascriptEvaluation: false,
+ });
+
+ await assert.rejects(
+ installPwa(args).handler(
+ {params: {manifestId: 'chrome://settings/', installUrlOrBundleUrl: ''}},
+ response,
+ context,
+ ),
+ /Navigating to chrome: URLs is not allowed/,
+ );
+ await assert.rejects(
+ installPwa(args).handler(
+ {
+ params: {
+ manifestId: 'https://example.com/',
+ installUrlOrBundleUrl: 'javascript:alert(1)',
+ },
+ },
+ response,
+ context,
+ ),
+ /Navigating to javascript: URLs is not allowed/,
+ );
+ sinon.assert.notCalled(context.installPWA);
+ });
+
+ it('install_pwa passes a file path through without URL validation', async () => {
+ const {context, response, args} = createHandlerMocks({
+ fileNavigations: false,
+ });
+ context.installPWA.resolves('isolated-app://app/');
+
+ await installPwa(args).handler(
+ {
+ params: {
+ manifestId: 'isolated-app://app/',
+ installUrlOrBundleUrl: '/tmp/app.swbn',
+ },
+ },
+ response,
+ context,
+ );
+
+ sinon.assert.calledOnceWithExactly(context.installPWA, {
+ manifestId: 'isolated-app://app/',
+ installUrlOrBundleUrl: '/tmp/app.swbn',
+ displayMode: undefined,
+ });
+ });
+
+ it('launch_pwa rejects file: and restricted URLs', async () => {
+ const {context, response, args} = createHandlerMocks({
+ fileNavigations: false,
+ });
+ const manifestId = 'https://example.com/pwa/';
+
+ await assert.rejects(
+ launchPwa(args).handler(
+ {params: {manifestId, url: 'file:///etc/passwd'}},
+ response,
+ context,
+ ),
+ /Navigating to file: URLs is not allowed/,
+ );
+ await assert.rejects(
+ launchPwa(args).handler(
+ {params: {manifestId, url: 'devtools://devtools/bundled/x.html'}},
+ response,
+ context,
+ ),
+ /Navigating to devtools: URLs is not allowed/,
+ );
+ sinon.assert.notCalled(context.launchPWA);
+ });
+
it('launches an installed PWA in a standalone window', async () => {
const {manifestId, startUrl} = setupPwaRoutes();
await withMcpContext(