File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ function webviewUriToFilePath(webviewUri: string): string {
5757 // Use strict prefix matching to prevent arbitrary host injection
5858 if (
5959 webviewUri . startsWith ( "vscode-resource://vscode-webview/" ) &&
60- ( webviewUri . includes ( "vscode-userdata" ) || webviewUri . includes ( "vscode-cdn.net" ) )
60+ ( webviewUri . includes ( "vscode-userdata" ) || isValidVsCodeCdnHost ( webviewUri ) )
6161 ) {
6262 try {
6363 // Decode safely with length limits
@@ -92,6 +92,20 @@ function webviewUriToFilePath(webviewUri: string): string {
9292/**
9393 * Gets the MIME type from a file path
9494 */
95+ /**
96+ * Safely validates if a webview URI is from the trusted vscode-cdn.net host
97+ * Prevents host injection attacks by properly parsing the URL
98+ */
99+ function isValidVsCodeCdnHost ( webviewUri : string ) : boolean {
100+ try {
101+ const url = new URL ( webviewUri )
102+ return url . host === "vscode-cdn.net"
103+ } catch {
104+ // URL parsing failed - not a valid URL
105+ return false
106+ }
107+ }
108+
95109function getMimeTypeFromPath ( filePath : string ) : string {
96110 const ext = path . extname ( filePath ) . toLowerCase ( )
97111
You can’t perform that action at this time.
0 commit comments