Skip to content

Commit 3e725b8

Browse files
fix(security): Add path allowlisting to /vscode-remote-resource endpoint
## Issue P401260599 ## Description of Changes Add path traversal protection to the /vscode-remote-resource handler. The endpoint previously served any file readable by the process with no path restriction, enabling arbitrary file read via ../ traversal, URL encoding, or direct absolute paths. Changes: - Import resolve from vs/base/common/path - Resolve requested file path to canonical form before serving - Validate resolved path against allowed directories (builtinExtensionsPath, extensionsPath, userDataPath) - Return 403 Forbidden for paths outside allowed roots ## Testing - Verified patch applies cleanly via quilt (prepare-src.sh) - All subsequent patches in sagemaker.series apply without conflict ## Screenshots/Videos ## Additional Notes Patch is placed after validate-http-request-referer.diff in the series, as it builds on the same handler code path. ## Backporting This PR targets the 1.1 branch. A matching PR has been created for 1.0.
1 parent 0ffc0f3 commit 3e725b8

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

patches/sagemaker.series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sagemaker/sagemaker-extensions-sync.diff
4646
sagemaker/fix-port-forwarding.diff
4747
sagemaker/display-both-versions-in-about.diff
4848
sagemaker/validate-http-request-referer.diff
49+
sagemaker/fix-path-traversal-vscode-remote-resource.diff
4950
sagemaker/sanitize-terminal-sendtext-paths.diff
5051
sagemaker/override-picomatch-post-startup-notifications.diff
5152
sagemaker/remove-delay-shutdown-endpoint.diff
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Index: code-editor-src/src/vs/server/node/remoteExtensionHostAgentServer.ts
2+
===================================================================
3+
--- code-editor-src.orig/src/vs/server/node/remoteExtensionHostAgentServer.ts
4+
+++ code-editor-src/src/vs/server/node/remoteExtensionHostAgentServer.ts
5+
@@ -17,7 +17,7 @@ import { isSigPipeError, onUnexpectedErr
6+
import { isEqualOrParent } from '../../base/common/extpath.js';
7+
import { Disposable, DisposableStore } from '../../base/common/lifecycle.js';
8+
import { connectionTokenQueryName, FileAccess, getServerProductSegment, Schemas } from '../../base/common/network.js';
9+
-import { dirname, join } from '../../base/common/path.js';
10+
+import { dirname, join, resolve } from '../../base/common/path.js';
11+
import * as perf from '../../base/common/performance.js';
12+
import * as platform from '../../base/common/platform.js';
13+
import { createRegExp, escapeRegExpCharacters } from '../../base/common/strings.js';
14+
@@ -191,6 +191,17 @@ class RemoteExtensionHostAgentServer ext
15+
return serveError(req, res, 400, `Bad request.`);
16+
}
17+
18+
+ // Security: restrict file access to allowed directories only
19+
+ const resolvedPath = resolve(filePath);
20+
+ const allowedRoots = [
21+
+ this._environmentService.builtinExtensionsPath,
22+
+ this._environmentService.extensionsPath,
23+
+ this._environmentService.userDataPath
24+
+ ];
25+
+ if (!allowedRoots.some(root => isEqualOrParent(resolvedPath, root, !platform.isLinux))) {
26+
+ return serveError(req, res, 403, `Forbidden.`);
27+
+ }
28+
+
29+
const responseHeaders: Record<string, string> = Object.create(null);
30+
if (this._environmentService.isBuilt) {
31+
if (isEqualOrParent(filePath, this._environmentService.builtinExtensionsPath, !platform.isLinux)

0 commit comments

Comments
 (0)