Skip to content

Commit 5ee4551

Browse files
authored
Add codeql comments and small fix (microsoft#185931)
1 parent 04a2bbc commit 5ee4551

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ window.addEventListener('message', async event => {
194194
const root = document.querySelector('.markdown-body')!;
195195

196196
const parser = new DOMParser();
197-
const newContent = parser.parseFromString(data.content, 'text/html');
197+
const newContent = parser.parseFromString(data.content, 'text/html'); // CodeQL [SM03712] This renderers content from the workspace into the Markdown preview. Webviews (and the markdown preview) have many other security measures in place to make this safe
198198

199199
// Strip out meta http-equiv tags
200200
for (const metaElement of Array.from(newContent.querySelectorAll('meta'))) {

extensions/markdown-language-features/src/languageFeatures/copyFiles/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function escapeHtmlAttribute(attr: string): string {
261261

262262
function escapeMarkdownLinkPath(mdPath: string): string {
263263
if (needsBracketLink(mdPath)) {
264-
return '<' + mdPath.replace('<', '\\<').replace('>', '\\>') + '>';
264+
return '<' + mdPath.replaceAll('<', '\\<').replaceAll('>', '\\>') + '>';
265265
}
266266

267267
return encodeURI(mdPath);

extensions/typescript-language-features/src/languageFeatures/jsDocCompletions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class JsDocCompletionProvider implements vscode.CompletionItemProvider {
103103
export function templateToSnippet(template: string): vscode.SnippetString {
104104
// TODO: use append placeholder
105105
let snippetIndex = 1;
106-
template = template.replace(/\$/g, '\\$');
106+
template = template.replace(/\$/g, '\\$'); // CodeQL [SM02383] This is only used for text which is put into the editor. It is not for rendered html
107107
template = template.replace(/^[ \t]*(?=(\/|[ ]\*))/gm, '');
108108
template = template.replace(/^(\/\*\*\s*\*[ ]*)$/m, (x) => x + `\$0`);
109109
template = template.replace(/\* @param([ ]\{\S+\})?\s+(\S+)[ \t]*$/gm, (_param, type, post) => {

extensions/typescript-language-features/src/languageFeatures/util/textRendering.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function convertLinkTags(
217217
}
218218

219219
function escapeMarkdownSyntaxTokensForCode(text: string): string {
220-
return text.replace(/`/g, '\\$&');
220+
return text.replace(/`/g, '\\$&'); // CodeQL [SM02383] This is only meant to escape backticks. The Markdown is fully sanitized after being rendered.
221221
}
222222

223223
export function tagsToMarkdown(

src/vs/base/common/htmlContent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function markdownStringEqual(a: IMarkdownString, b: IMarkdownString): boo
140140

141141
export function escapeMarkdownSyntaxTokens(text: string): string {
142142
// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
143-
return text.replace(/[\\`*_{}[\]()#+\-!~]/g, '\\$&');
143+
return text.replace(/[\\`*_{}[\]()#+\-!~]/g, '\\$&'); // CodeQL [SM02383] Backslash is escaped in the character class
144144
}
145145

146146
export function escapeDoubleQuotes(input: string) {

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ async function webviewPreloads(ctx: PreloadContext) {
882882
const onDidReceiveKernelMessage = createEmitter<unknown>();
883883

884884
const ttPolicy = window.trustedTypes?.createPolicy('notebookRenderer', {
885-
createHTML: value => value,
886-
createScript: value => value,
885+
createHTML: value => value, // CodeQL [SM03712] The rendered content is provided by renderer extensions, which are responsible for sanitizing their content themselves. The notebook webview is also sandboxed.
886+
createScript: value => value, // CodeQL [SM03712] The rendered content is provided by renderer extensions, which are responsible for sanitizing their content themselves. The notebook webview is also sandboxed.
887887
});
888888

889889
window.addEventListener('wheel', handleWheel);

0 commit comments

Comments
 (0)