Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitise SVG instead of banning it #38

Open
joaomoreno opened this issue Mar 25, 2021 · 6 comments
Open

Sanitise SVG instead of banning it #38

joaomoreno opened this issue Mar 25, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@joaomoreno
Copy link
Member

joaomoreno commented Mar 25, 2021

From @PeterWone in microsoft/vscode#119713


The publishing page https://code.visualstudio.com/api/working-with-extensions/publishing-extension says that I can't ship SVG resource and they must be loaded from trusted sources "for security reasons".

I looked into why, and discovered SVG supported embedded or linked scripts with a script tag similar to the HTML script tag.

  • No browser I could find would allow this script to run when the image is loaded from the internet
  • When the image is loaded from the local filesystem by a browser, the scripts are loaded and can run but the same-source policy prevents them from doing much.

If SVG is a threat for VS Code then presumably VS Code fails to enforce the same source policy. If so, that's not well thought through. There is absolutely nothing stopping an extension from pulling files from the general internet and putting them into the file system after the extension is installed. For that matter you can't stop me from embedding SVG files as strings and saving them to the filesystem on first run.

If the risk is in the WebView pages then why not sanitise the SVG by the simple expedient of stripping all script tags and their content? Their mere presence reveals malice afoot so an alert to the user would not be out of place. Or even just look for <script> and barf on finding it. MalwareException: 'nasty.svg' contains script.

Disallowing SVG in extension bundles is not an effective threat mitigation. Sanitising could be effective if it were applied universally.

@luanpotter
Copy link

This was also requested here: microsoft/vscode-vsce#183

@pokey
Copy link

pokey commented Jul 11, 2021

Maybe you'd consider supporting your own svg badges? I get an error for https://open.vscode.dev/badges/open-in-vscode.svg 😅

@ghost
Copy link

ghost commented Aug 30, 2021

The SVG sanitizer at DOMPurify is meant to be enterprise grade, would love if you could use that :)

@gjsjohnmurray
Copy link
Contributor

The SVG sanitizer at DOMPurify is meant to be enterprise grade, would love if you could use that :)

Looks like VS Code is switching to DOMPurify

microsoft/vscode#131950

@ghost
Copy link

ghost commented Aug 31, 2021

Noice

@ghost
Copy link

ghost commented Sep 4, 2021

As asked on vscode-vsce, is help wanted on this?

ryu1kn added a commit to ryu1kn/vscode-extension-update-reporter that referenced this issue Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants