Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to the "prettier-vscode" extension will be documented in thi

## [Unreleased]

- **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.

## [12.3.0]

- Watch `.prettierignore` for changes to invalidate cache (#3942)
Expand Down
13 changes: 13 additions & 0 deletions src/ModuleResolverNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
INVALID_PRETTIER_CONFIG,
INVALID_PRETTIER_PATH_MESSAGE,
OUTDATED_PRETTIER_VERSION_MESSAGE,
UNTRUSTED_WORKSPACE_SKIPPING_CONFIG,
UNTRUSTED_WORKSPACE_USING_BUNDLED_PRETTIER,
USING_BUNDLED_PRETTIER,
} from "./message.js";
Expand Down Expand Up @@ -402,6 +403,18 @@ export class ModuleResolver implements ModuleResolverInterface {
fileName: string,
vscodeConfig: PrettierVSCodeConfig,
): Promise<"error" | "disabled" | PrettierOptions | null> {
// In untrusted workspaces, skip config resolution entirely.
// Prettier's resolveConfigFile/resolveConfig can execute JS config files
// (.prettierrc.js, prettier.config.js, etc.) which would allow arbitrary
// code execution.
if (!workspace.isTrusted) {
this.loggingService.logDebug(UNTRUSTED_WORKSPACE_SKIPPING_CONFIG);
Comment thread
ntotten marked this conversation as resolved.
if (vscodeConfig.requireConfig) {
return "disabled";
}
return null;
}
Comment thread
ntotten marked this conversation as resolved.

let configPath: string | undefined;
try {
configPath =
Expand Down
2 changes: 2 additions & 0 deletions src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const EXTENSION_DISABLED =
"Extension is disabled. No formatters will be registered. To enable, change the `prettier.enable` to `true` and restart VS Code.";
export const UNTRUSTED_WORKSPACE_USING_BUNDLED_PRETTIER =
"This workspace is not trusted. Using the bundled version of prettier.";
export const UNTRUSTED_WORKSPACE_SKIPPING_CONFIG =
"Skipping Prettier config resolution in untrusted workspace. Config files are not loaded for security.";
Loading