Remove vscode-webview-resource path normalization logic

We should now handle normalization before `loadLocalResource` is invoked and should never see a `vscode-webview-resource` uri being passed in
This commit is contained in:
Matt Bierner 2021-04-08 17:10:25 -07:00
parent 9c9e188aa0
commit de9887d9e0
No known key found for this signature in database
GPG key ID: 099C331567E11888
3 changed files with 3 additions and 34 deletions

View file

@ -73,11 +73,6 @@ export namespace Schemas {
*/
export const vscodeWebview = 'vscode-webview';
/**
* Scheme used for loading resources inside of webviews.
*/
export const vscodeWebviewResource = 'vscode-webview-resource';
/**
* Scheme used for extension pages
*/

View file

@ -176,41 +176,15 @@ function getResourceToLoad(
requestUri: URI,
roots: ReadonlyArray<URI>
): URI | undefined {
const normalizedPath = normalizeRequestPath(requestUri);
for (const root of roots) {
if (containsResource(root, normalizedPath)) {
return normalizedPath;
if (containsResource(root, requestUri)) {
return requestUri;
}
}
return undefined;
}
function normalizeRequestPath(requestUri: URI) {
if (requestUri.scheme === Schemas.vscodeWebviewResource) {
// The `vscode-webview-resource` scheme has the following format:
//
// vscode-webview-resource://id/scheme//authority?/path
//
// Encode requestUri.path so that URI.parse can properly parse special characters like '#', '?', etc.
const resourceUri = URI.parse(encodeURIComponent(requestUri.path).replace(/%2F/gi, '/').replace(/^\/([a-z0-9\-]+)(\/{1,2})/i, (_: string, scheme: string, sep: string) => {
if (sep.length === 1) {
return `${scheme}:///`; // Add empty authority.
} else {
return `${scheme}://`; // Url has own authority.
}
}));
return resourceUri.with({
query: requestUri.query,
fragment: requestUri.fragment
});
} else {
return requestUri;
}
}
function containsResource(root: URI, resource: URI): boolean {
let rootPath = root.fsPath + (root.fsPath.endsWith(sep) ? '' : sep);
let resourceFsPath = resource.fsPath;

View file

@ -425,7 +425,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
});
// Block all SVG requests from unsupported origins
const supportedSvgSchemes = new Set([Schemas.file, Schemas.vscodeFileResource, Schemas.vscodeRemoteResource, Schemas.vscodeWebviewResource, 'devtools']);
const supportedSvgSchemes = new Set([Schemas.file, Schemas.vscodeFileResource, Schemas.vscodeRemoteResource, 'devtools']); // TODO: handle webview origin
this._win.webContents.session.webRequest.onBeforeRequest((details, callback) => {
const uri = URI.parse(details.url);
if (uri.path.endsWith('.svg')) {