Skip to content

Commit 3c9741e

Browse files
authored
Merge pull request #96 from ClayPulse/hotfix
Set resolve to assume uri is absolute
2 parents 6f10d71 + 3e0c8b1 commit 3c9741e

File tree

1 file changed

+7
-7
lines changed
  • remote-workspace/src/servers/api-server/platform-api

1 file changed

+7
-7
lines changed

remote-workspace/src/servers/api-server/platform-api/handler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import path from "path";
55
// Define a safe root directory for projects. Can be overridden by env or configured as needed.
66
// All incoming URIs will be resolved and validated to ensure they don't escape this root.
77

8+
// Absolute paths
89
const appRoot = "/pulse-editor";
9-
1010
const workspaceRoot = "/workspace";
1111

1212
const settingsPath = path.join(appRoot, "settings.json");
@@ -16,16 +16,16 @@ function safeWorkspaceResolve(uri: string): string {
1616
throw new Error("Invalid path");
1717
}
1818

19-
// Canonicalize the workspaceRoot once for this function
20-
const rootPath = path.resolve(workspaceRoot);
21-
// Combine and normalize the user input relative to the safe root
22-
const candidate = path.resolve(uri);
19+
// uri should be an absolute path
20+
if (!path.isAbsolute(uri)) {
21+
throw new Error("Path must be absolute");
22+
}
2323

2424
// Check that candidate is strictly under rootPath (or equal to rootPath)
25-
const rel = path.relative(rootPath, candidate);
25+
const rel = path.relative(workspaceRoot, uri);
2626
// Allow if candidate is rootPath itself, or a subpath (not escaping via '..', not absolute)
2727
if (rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel))) {
28-
return candidate;
28+
return uri;
2929
}
3030

3131
throw new Error("Can only access paths within the project home directory.");

0 commit comments

Comments
 (0)