11import type { TreeViewNode } from "reactive-vscode" ;
22import type { UCDTreeItem } from "../composables/useUCDExplorer" ;
3+ import { resolveSafePath } from "@ucdjs/path-utils" ;
34import { executeCommand , useCommand } from "reactive-vscode" ;
45import { Uri } from "vscode" ;
56import * as Meta from "../generated/meta" ;
@@ -19,35 +20,8 @@ export function useOpenOnUnicodeCommand() {
1920 return ;
2021 }
2122
22- // Sanitize path to prevent directory traversal attacks
23- const rawPath = treeViewOrUri . path ;
24-
25- // Normalize the path and check for traversal attempts
26- // Use a simple approach: split, filter out dangerous segments, rejoin
27- const segments = rawPath . split ( "/" ) . filter ( ( segment ) => {
28- // Block empty segments, current dir refs, and parent dir refs
29- return segment !== "" && segment !== "." && segment !== ".." ;
30- } ) ;
31-
32- // If no valid segments remain, block the request
33- if ( segments . length === 0 ) {
34- logger . error ( "Invalid path provided to openOnUnicode command: path is empty or invalid." ) ;
35- return ;
36- }
37-
38- // Check if any segment still contains traversal patterns (encoded or otherwise)
39- const hasTraversal = segments . some ( ( segment ) => {
40- const decoded = decodeURIComponent ( segment ) ;
41- return decoded === ".." || decoded === "." || decoded . includes ( "../" ) || decoded . includes ( "..\\" ) ;
42- } ) ;
43-
44- if ( hasTraversal ) {
45- logger . error ( "Invalid path provided to openOnUnicode command: path traversal detected." ) ;
46- return ;
47- }
48-
49- const sanitizedPath = segments . join ( "/" ) ;
50- executeCommand ( "vscode.open" , Uri . parse ( `https://unicode.org/Public/${ sanitizedPath } ` ) ) ;
23+ const resolvedPath = resolveSafePath ( "/Public/" , treeViewOrUri . path ) ;
24+ executeCommand ( "vscode.open" , Uri . parse ( `https://unicode.org/${ resolvedPath } ` ) ) ;
5125 return ;
5226 }
5327
0 commit comments