Skip to content

Commit 013b6f4

Browse files
ntottenclaude
andcommitted
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>
1 parent 1b0dad6 commit 013b6f4

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-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: 10 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,15 @@ 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+
return null;
413+
}
414+
405415
let configPath: string | undefined;
406416
try {
407417
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)