Skip to content

Commit

Permalink
Fix #143985
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Kearl committed Feb 26, 2022
1 parent 0760151 commit d5b00ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function sanitize(documentContent: string, allowUnknownProtocols: boolean): stri
for (const attr of ['href', 'src']) {
if (node.hasAttribute(attr)) {
anchor.href = node.getAttribute(attr) as string;
if (!allowedProtocols.includes(anchor.protocol)) {
if (!allowedProtocols.includes(anchor.protocol.replace(/:$/, ''))) {
node.removeAttribute(attr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,16 @@ export class GettingStartedPage extends EditorPane {
}

private mdCache = new ResourceMap<Promise<string>>();
private async readAndCacheStepMarkdown(path: URI): Promise<string> {
private async readAndCacheStepMarkdown(path: URI, base: URI): Promise<string> {

const transformUris = (content: string): string => content.replace(/src="([^"]*)"/g, (_, src: string) => {
if (src.startsWith('https://')) { return `src="${src}"`; }

const path = joinPath(base, src);
const transformed = asWebviewUri(path).toString();
return `src="${transformed}"`;
});

if (!this.mdCache.has(path)) {
this.mdCache.set(path, (async () => {
try {
Expand All @@ -483,7 +492,7 @@ export class GettingStartedPage extends EditorPane {
return new Promise<string>(resolve => {
require([moduleId], content => {
const markdown = content.default();
resolve(renderMarkdownDocument(markdown, this.extensionService, this.languageService, true, true));
resolve(renderMarkdownDocument(transformUris(markdown), this.extensionService, this.languageService, true, true));
});
});
}
Expand Down Expand Up @@ -512,7 +521,7 @@ export class GettingStartedPage extends EditorPane {
: path);

const markdown = bytes.value.toString();
return renderMarkdownDocument(markdown, this.extensionService, this.languageService, true, true);
return renderMarkdownDocument(transformUris(markdown), this.extensionService, this.languageService, true, true);
} catch (e) {
this.notificationService.error('Error reading markdown document at `' + path + '`: ' + e);
return '';
Expand Down Expand Up @@ -772,18 +781,10 @@ export class GettingStartedPage extends EditorPane {
}

private async renderMarkdown(path: URI, base: URI): Promise<string> {
const content = await this.readAndCacheStepMarkdown(path);
const content = await this.readAndCacheStepMarkdown(path, base);
const nonce = generateUuid();
const colorMap = TokenizationRegistry.getColorMap();

const uriTranformedContent = content.replace(/src="([^"]*)"/g, (_, src: string) => {
if (src.startsWith('https://')) { return `src="${src}"`; }

const path = joinPath(base, src);
const transformed = asWebviewUri(path).toString();
return `src="${transformed}"`;
});

const css = colorMap ? generateTokensCSSForColorMap(colorMap) : '';

const inDev = document.location.protocol === 'http:';
Expand Down Expand Up @@ -854,7 +855,7 @@ export class GettingStartedPage extends EditorPane {
</head>
<body>
<vertically-centered>
${uriTranformedContent}
${content}
</vertically-centered>
</body>
<script nonce="${nonce}">
Expand Down

0 comments on commit d5b00ef

Please sign in to comment.