Skip to content

Commit a3f7317

Browse files
ntottenclaude
andauthored
Security: Skip config resolution in untrusted workspaces (#3972)
* Fix untrusted workspace config resolution executing JS config files Prettier's resolveConfigFile/resolveConfig can require()/import() JavaScript config files (.prettierrc.js, prettier.config.js, etc.), allowing arbitrary code execution even when workspace trust restricted module resolution to the bundled Prettier. Add a workspace.isTrusted guard in resolveConfig() to skip config resolution entirely in untrusted workspaces, returning null (Prettier defaults). Reported by Hector Ruiz Ruiz. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Honor requireConfig in untrusted workspaces When requireConfig is true and the workspace is untrusted, return "disabled" instead of null so formatting is correctly skipped rather than proceeding with VS Code defaults. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3c13b34 commit a3f7317

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to the "prettier-vscode" extension will be documented in thi
66

77
## [Unreleased]
88

9+
- **Security**: Fixed config resolution in untrusted workspaces to prevent JavaScript config files (`.prettierrc.js`, `prettier.config.js`, etc.) from being executed. Previously, even when workspace trust was enforced for module resolution, Prettier's config resolution could still `require()`/`import()` JS config files, allowing arbitrary code execution. Reported by Hector Ruiz Ruiz.
10+
911
## [12.3.0]
1012

1113
- Watch `.prettierignore` for changes to invalidate cache (#3942)

src/ModuleResolverNode.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
INVALID_PRETTIER_CONFIG,
1616
INVALID_PRETTIER_PATH_MESSAGE,
1717
OUTDATED_PRETTIER_VERSION_MESSAGE,
18+
UNTRUSTED_WORKSPACE_SKIPPING_CONFIG,
1819
UNTRUSTED_WORKSPACE_USING_BUNDLED_PRETTIER,
1920
USING_BUNDLED_PRETTIER,
2021
} from "./message.js";
@@ -402,6 +403,18 @@ export class ModuleResolver implements ModuleResolverInterface {
402403
fileName: string,
403404
vscodeConfig: PrettierVSCodeConfig,
404405
): Promise<"error" | "disabled" | PrettierOptions | null> {
406+
// In untrusted workspaces, skip config resolution entirely.
407+
// Prettier's resolveConfigFile/resolveConfig can execute JS config files
408+
// (.prettierrc.js, prettier.config.js, etc.) which would allow arbitrary
409+
// code execution.
410+
if (!workspace.isTrusted) {
411+
this.loggingService.logDebug(UNTRUSTED_WORKSPACE_SKIPPING_CONFIG);
412+
if (vscodeConfig.requireConfig) {
413+
return "disabled";
414+
}
415+
return null;
416+
}
417+
405418
let configPath: string | undefined;
406419
try {
407420
configPath =

src/message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export const EXTENSION_DISABLED =
1313
"Extension is disabled. No formatters will be registered. To enable, change the `prettier.enable` to `true` and restart VS Code.";
1414
export const UNTRUSTED_WORKSPACE_USING_BUNDLED_PRETTIER =
1515
"This workspace is not trusted. Using the bundled version of prettier.";
16+
export const UNTRUSTED_WORKSPACE_SKIPPING_CONFIG =
17+
"Skipping Prettier config resolution in untrusted workspace. Config files are not loaded for security.";

0 commit comments

Comments
 (0)