Skip to content

Chrome DevTools for coding agents

chore: remove CWD from config discovery (#3102)

Nikolay Vitkov1be732d6ee43
diff --git a/docs/configuration.md b/docs/configuration.md
index b0d33d6c..3a1a9119 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -281,10 +281,9 @@ The server uses the first config file it finds in the following locations,
from highest to lowest priority. Config files are not merged.
1. The path passed via `--config`.
-2. `cd4a.config.json` in the current working directory.
-3. `cd4a.config.json` in the `$PLUGIN_DATA` directory, when running as an
+2. `cd4a.config.json` in the `$PLUGIN_DATA` directory, when running as an
[agent plugin](https://agent-plugins.org/specification).
-4. The global config file:
+3. The global config file:
- macOS and Linux: `$XDG_CONFIG_HOME/cd4a/config.json`, falling back to
`~/.config/cd4a/config.json`.
- Windows: `%LOCALAPPDATA%/Google/cd4a/config.json`, falling back to
@@ -297,6 +296,18 @@ Set the `CHROME_DEVTOOLS_MCP_NO_CONFIG_DISCOVERY` env variable to turn off the
search for config files, for example in tests. A config file passed via
`--config` is still used.
+### Locking down the configuration file from agent access
+
+> [!WARNING]
+> Ensure that the configuration file and its parent directory are not writable
+> by the agent.
+
+The configuration file can set security-sensitive options such as
+`executablePath`, `chromeArg`, `allowedUrlPattern`, `blockedUrlPattern`, etc.
+If an agent can create or modify the configuration file in any of the
+discovered locations (or at the path passed via `--config`), it can alter
+these settings to bypass restrictions.
+
## Connecting via WebSocket with custom headers
You can connect directly to a Chrome WebSocket endpoint and include custom headers (e.g., for authentication):
diff --git a/src/config/ConfigLocator.ts b/src/config/ConfigLocator.ts
index e6b8ff5a..fd78b14f 100644
--- a/src/config/ConfigLocator.ts
+++ b/src/config/ConfigLocator.ts
@@ -30,9 +30,8 @@ function isFile(filePath: string): boolean {
* wins, config files are not merged.
*
* Locations, from highest to lowest priority:
- * 1. `${CWD}/cd4a.config.json`
- * 2. `${PLUGIN_DATA}/cd4a.config.json`
- * 3. The global config: `$XDG_CONFIG_HOME/cd4a/config.json` on macOS and
+ * 1. `${PLUGIN_DATA}/cd4a.config.json`
+ * 2. The global config: `$XDG_CONFIG_HOME/cd4a/config.json` on macOS and
* Linux, `%LOCALAPPDATA%/Google/cd4a/config.json` on Windows, with a
* fallback to `~/.config/cd4a/config.json`.
*
@@ -41,8 +40,8 @@ function isFile(filePath: string): boolean {
* `CHROME_DEVTOOLS_MCP_NO_CONFIG_DISCOVERY` env variable is set.
*/
export class ConfigLocator {
- getSearchPaths(cwd = process.cwd(), env = process.env): string[] {
- const searchPaths = [path.join(cwd, CONFIG_FILE_NAME)];
+ getSearchPaths(env = process.env): string[] {
+ const searchPaths: string[] = [];
const pluginData = env['PLUGIN_DATA'];
if (pluginData) {
searchPaths.push(path.join(pluginData, CONFIG_FILE_NAME));
@@ -75,8 +74,6 @@ export class ConfigLocator {
if (env[NO_CONFIG_DISCOVERY_ENV]) {
return undefined;
}
- return this.getSearchPaths(undefined, env).find(filePath =>
- checkIsFile(filePath),
- );
+ return this.getSearchPaths(env).find(filePath => checkIsFile(filePath));
}
}
diff --git a/tests/config/ConfigLocator.test.ts b/tests/config/ConfigLocator.test.ts
index 2fa3b90f..4ce171ec 100644
--- a/tests/config/ConfigLocator.test.ts
+++ b/tests/config/ConfigLocator.test.ts
@@ -11,11 +11,9 @@ import {describe, it} from 'node:test';
import {ConfigLocator} from '../../src/config/ConfigLocator.js';
const HOME = path.resolve('/home/user');
-const CWD = path.resolve('/work/project');
const PLUGIN_DATA = path.resolve('/plugins/data/chrome-devtools');
const XDG_CONFIG_HOME = path.resolve('/xdg/config');
-const CWD_CONFIG = path.join(CWD, 'cd4a.config.json');
const PLUGIN_CONFIG = path.join(PLUGIN_DATA, 'cd4a.config.json');
const XDG_CONFIG = path.join(XDG_CONFIG_HOME, 'cd4a', 'config.json');
const HOME_CONFIG = path.join(HOME, '.config', 'cd4a', 'config.json');
@@ -36,8 +34,8 @@ class TestConfigLocator extends ConfigLocator {
this.#platform = platform;
}
- override getSearchPaths(cwd = CWD, env = this.#env): string[] {
- return super.getSearchPaths(cwd, env);
+ override getSearchPaths(env = this.#env): string[] {
+ return super.getSearchPaths(env);
}
override getGlobalConfigPath(
@@ -113,7 +111,7 @@ describe('ConfigLocator', () => {
it('returns undefined when discovery is turned off', () => {
assert.strictEqual(
- new TestConfigLocator([CWD_CONFIG, PLUGIN_CONFIG, HOME_CONFIG], {
+ new TestConfigLocator([PLUGIN_CONFIG, HOME_CONFIG], {
PLUGIN_DATA,
CHROME_DEVTOOLS_MCP_NO_CONFIG_DISCOVERY: 'true',
}).locate(),
@@ -121,15 +119,6 @@ describe('ConfigLocator', () => {
);
});
- it('prefers the config file in the current working directory', () => {
- assert.strictEqual(
- new TestConfigLocator([CWD_CONFIG, PLUGIN_CONFIG, HOME_CONFIG], {
- PLUGIN_DATA,
- }).locate(),
- CWD_CONFIG,
- );
- });
-
it('prefers the plugin data config over the global config', () => {
assert.strictEqual(
new TestConfigLocator([PLUGIN_CONFIG, HOME_CONFIG], {