File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,18 @@ function webviewUriToFilePath(webviewUri: string): string {
5757 if ( webviewUri . includes ( "vscode-userdata" ) || webviewUri . includes ( "vscode-cdn.net" ) ) {
5858 // Try to decode the URI and extract the file path
5959 const decoded = decodeURIComponent ( webviewUri )
60- // Look for a file path pattern in the decoded URI
61- const pathMatch = decoded . match ( / (?: U s e r s | C : ) ( [ ^ ? # ] + \. (?: p n g | j p g | j p e g | g i f | w e b p ) ) / i)
60+
61+ // Use safer, non-polynomial regex patterns
62+ // Look for Unix-style paths first
63+ let pathMatch = decoded . match ( / \/ U s e r s \/ [ ^ ? # ] * \. (?: p n g | j p g | j p e g | g i f | w e b p ) / i)
64+ if ( pathMatch ) {
65+ return pathMatch [ 0 ]
66+ }
67+
68+ // Look for Windows-style paths with bounded length to prevent polynomial behavior
69+ pathMatch = decoded . match ( / C : \\ [ ^ ? # ] { 0 , 500 } \. (?: p n g | j p g | j p e g | g i f | w e b p ) / i)
6270 if ( pathMatch ) {
63- const extractedPath = pathMatch [ 0 ]
64- return extractedPath
71+ return pathMatch [ 0 ]
6572 }
6673 }
6774
You can’t perform that action at this time.
0 commit comments