Repository navigation
Fix typo in marked.js sanitizer - #111258
Conversation
There was / is a typo in `markdownRenderer.js` that allowed any *trusted* document to pass arbitrary HTML through the marked.js sanitizer provided it is wrapped in `<span></span>` tags, or similar. What could you have done with this? Not much that was not already possible in trusted mode, which, as far as I can tell is used just for Jypiter Notebooks that pretty much definitionally can execute Python anyway. Insane strips everything worthwhile except `<a data-href=''/>` which you can use to send `command:` URIs on click (`javascript:` URIs are disabled at a higher level of abstraction), but are already whitelisted (L141) for trusted documents.
| // marked for sanitization. | ||
| markedOptions.sanitizer = (html: string): string => { | ||
| const match = markdown.isTrusted ? html.match(/^(<span[^<]+>)|(<\/\s*span>)$/) : undefined; | ||
| const match = markdown.isTrusted ? html.match(/^(<span[^>]+>)|(<\/\s*span>)$/) : undefined; |
There was a problem hiding this comment.
I'm not sure that [^>] is correct. We still want to prevent html tags from beginning. [^<>] would probably be the best.
There was a problem hiding this comment.
An HTML tag can’t begin inside the attributes of another HTML tag.
I wrote this kind of hurriedly. I think you're right in that this regex is not a perfect way to do what's being attempted here, which is to allow <span class="codicon codicon-something" style="color:#ffff"> defined later in the file:
It's a bigger fix than just a typo, but we might want to be safe by going so far as to allowlist this specific set of inputs, since the regexes are already there in part:
/^(?:<span (?:(?:class="codicon codicon-[a-z\-]+(?:codicon-animation-[a-z\-]+)?")?|(?:style="(?:color\:#[0-9a-fA-F]+;|background-color\:#[0-9a-fA-F]+;)"))>|^<\/\s*span>)$/grefiddle: http://refiddle.com/refiddles/5fbe763e75622d16b3130000
rail diagram: 
There was a problem hiding this comment.
Instead of blocking a specific character, can we only allow specific characters? Something like:
<span( [a-z\-'"#0-9]*)?>
There was a problem hiding this comment.
It might be possible to confuse that regex into showing something it's not meant to by ending each pass with a trailing quote:
<span "> "this text may not be interpreted as HTML, but is parsed as HTML now"There was a problem hiding this comment.
It should be safe if you require it to match the entire string
|
An HTML tag can’t begin inside the attributes of another HTML tag.
…On Wed, 25 Nov 2020 at 9:39 am, Alex Ross ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In src/vs/base/browser/markdownRenderer.ts
<#111258 (comment)>:
> @@ -218,7 +218,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: MarkdownRende
// We always pass the output through insane after this so that we don't rely on
// marked for sanitization.
markedOptions.sanitizer = (html: string): string => {
- const match = markdown.isTrusted ? html.match(/^(<span[^<]+>)|(<\/\s*span>)$/) : undefined;
+ const match = markdown.isTrusted ? html.match(/^(<span[^>]+>)|(<\/\s*span>)$/) : undefined;
I'm not sure that [^>] is correct. We still want to prevent html tags
from beginning. [^<>] would probably be the best.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#111258 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDJGLVPXQBRUCHBMT5S4H3SRTGEVANCNFSM4UBNVXZA>
.
|
|
Thanks! Will be in the VS Code insiders build |
There was / is a typo in `markdownRenderer.js` that allowed any *trusted* document to pass arbitrary HTML through the marked.js sanitizer provided it is wrapped in `<span></span>` tags, or similar. What could you have done with this? Not much that was not already possible in trusted mode, which, as far as I can tell is used just for Jypiter Notebooks that pretty much definitionally can execute Python anyway. Insane strips everything worthwhile except `<a data-href=''/>` which you can use to send `command:` URIs on click (`javascript:` URIs are disabled at a higher level of abstraction), but are already whitelisted (L141) for trusted documents.
There was / is a typo in
markdownRenderer.jsthat allowed any trusted document to pass arbitrary HTML through the marked.js sanitizer provided it is wrapped in<span></span>tags, or similar.What could you have done with this? Not much that was not already possible in trusted mode, which, as far as I can tell is used just for Jypiter Notebooks that pretty much definitionally can execute Python anyway.
Insane strips everything worthwhile except
<a data-href=''/>which you can use to sendcommand:URIs on click (javascript:URIs are disabled at a higher level of abstraction), but the ability to do this is already allowlisted (L141) for trusted documents.This PR fixes #111257