Skip to content

Commit da1d8b9

Browse files
fix 235221: Passing the markdown content to the webview via meta tag and purifying it before use
1 parent 68410e1 commit da1d8b9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

extensions/markdown-language-features/preview-src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ document.addEventListener('click', event => {
353353
}
354354
}, true);
355355

356+
window.addEventListener('load', () => {
357+
const htmlParser = new DOMParser();
358+
const markDownHtml = htmlParser.parseFromString(getData('data-md-content'), 'text/html');
359+
document.body.appendChild(markDownHtml.body);
360+
});
361+
356362
window.addEventListener('scroll', throttle(() => {
357363
updateScrollProgress();
358364

extensions/markdown-language-features/src/preview/documentRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ export class MdDocumentRenderer {
9898
<meta id="vscode-markdown-preview-data"
9999
data-settings="${escapeAttribute(JSON.stringify(initialData))}"
100100
data-strings="${escapeAttribute(JSON.stringify(previewStrings))}"
101-
data-state="${escapeAttribute(JSON.stringify(state || {}))}">
101+
data-state="${escapeAttribute(JSON.stringify(state || {}))}"
102+
data-md-content="${escapeAttribute(JSON.stringify(body.html))}">
102103
<script src="${this._extensionResourcePath(resourceProvider, 'pre.js')}" nonce="${nonce}"></script>
103104
${this._getStyles(resourceProvider, sourceUri, config, imageInfo)}
104105
<base href="${resourceProvider.asWebviewUri(markdownDocument.uri)}">
105106
</head>
106107
<body class="vscode-body ${config.scrollBeyondLastLine ? 'scrollBeyondLastLine' : ''} ${config.wordWrap ? 'wordWrap' : ''} ${config.markEditorSelection ? 'showEditorSelection' : ''}">
107-
${body.html}
108108
${this._getScripts(resourceProvider, nonce)}
109109
</body>
110110
</html>`;

0 commit comments

Comments
 (0)