feat: disable chmod in untrusted workspaces via workspace trust API#48
Open
feat: disable chmod in untrusted workspaces via workspace trust API#48
Conversation
A malicious workspace could contain shebang files that silently become executable on save. Switching from `"supported": true` to `"limited"` lets the extension load in restricted mode but gates all chmod operations behind `vscode.workspace.isTrusted`. - Declare `"supported": "limited"` with `restrictedConfigurations` to prevent workspace-level `permissionStrategy` override (e.g. "all") - Add `!isTrusted` early return in `shouldSkipDocument()`, covering both the on-save handler and the manual command - Grey out the manual command via `isWorkspaceTrusted` enablement - No `onDidGrantWorkspaceTrust` listener needed — `isTrusted` is checked on every save, so granting trust mid-session just works Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR implements workspace trust support to prevent malicious files from becoming executable in untrusted workspaces. The extension now respects VS Code's workspace trust boundaries by blocking all chmod operations when vscode.workspace.isTrusted is false, addressing a security concern where opening an untrusted workspace containing shebang files could silently make them executable.
Changes:
- Added runtime workspace trust guard in
shouldSkipDocument()to block chmod operations in untrusted workspaces - Updated package.json manifest with
untrustedWorkspaces.supported: "limited", restrictedpermissionStrategyconfiguration, and command enablement clause - Added comprehensive test suite (4 tests) covering untrusted/trusted scenarios and mid-session trust grants
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/document-handler.ts | Added !vscode.workspace.isTrusted check in shouldSkipDocument() to block all chmod operations in untrusted workspaces |
| package.json | Changed untrusted workspace support to "limited", added restrictedConfigurations for permissionStrategy, and updated command enablement with isWorkspaceTrusted context |
| src/test/extension.test.ts | Added workspace trust test suite with 4 tests covering untrusted blocking, trusted operation, manual command blocking, and mid-session trust grants |
| AGENTS.md | Documented workspace trust implementation pattern for future reference |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
untrustedWorkspaces.supported: true, meaning chmod ran unconditionally — a malicious workspace could contain shebang files that silently become executable on save"supported": "limited"so the extension still loads in Restricted Mode but all permission changes are gated behindvscode.workspace.isTrustedpermissionStrategysetting viarestrictedConfigurationsto prevent a workspace-level.vscode/settings.jsonfrom escalating to the"all"strategyChanges
Runtime guard (
src/document-handler.ts): Added!vscode.workspace.isTrustedearly return inshouldSkipDocument(). This covers both the on-save handler and the manual command since both flow throughprocessDocument(). NoonDidGrantWorkspaceTrustevent listener is needed —isTrustedis checked on every save, so granting trust mid-session immediately unblocks subsequent saves.Manifest (
package.json): ChangeduntrustedWorkspacesto"limited"with a user-facing description. AddedrestrictedConfigurationsforpermissionStrategy. AddedisWorkspaceTrustedto the manual command'senablementclause to grey it out in the command palette when untrusted.Tests (
src/test/extension.test.ts): Newworkspace trustsuite with 4 tests — untrusted blocks on-save, trusted works normally, manual command blocked when untrusted, and mid-session trust grant enables subsequent saves.Test plan
🤖 Generated with Claude Code