@@ -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
89const appRoot = "/pulse-editor" ;
9-
1010const workspaceRoot = "/workspace" ;
1111
1212const 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