-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Help webview extensions add a Content Security Policy #79340
Comments
I'll pick this up. Will start with code settings sync extension. |
I worked on |
@mjbvz I believe |
We've just added a csp to the python extension, but we're still getting the warning? Does it have to be strict in order to not get the warning? Here's our current CSP:
|
What file or files is the CSP usually included in? So if you click on any of the repos with confirmed and open issues and take a look at the project files, what files should usually contain a CSP? All HTML files? |
Is the declared CSP actually enforced? We use a webview that relies upon inline CSS and base64-encoded images, and it loads correctly with a Sure, it removes the warning. But I'm a bit worried that we'll have to push a bugfix release in a rush when our users start reporting that the webview is broken after an update to Code. |
@jblievremont Can you share a link to an example extension |
Hi, I'm from the |
@abist Looks good. Thanks |
✔️James-Yu.latex-workshop James-Yu/LaTeX-Workshop/pull/1676 |
mike-lischke.vscode-antlr4 uses webviews too and while working on adding CSPs to them I stumbled across a problem: I get the missing CSP warning even though I have added a CSP. The generated code is:
Why's that not accepted? |
@mike-lischke I just tried that html in a webview with VSCode 1.41.0-insider (Commit: 0d728c3) but could not reproduce the issue. Can you please share an example extension? |
@mjbvz I assumed that Select the Railroad diagram, which will show a webview. This one does not bring up the warning. Then try |
@mike-lischke I can't repo this in VS Code insiders. Are you 100% sure your webview html always has a content security policy. For example, this line looks suspicious: https://github.com/mike-lischke/vscode-antlr4/blob/b6b065c09494e947259617661ab9f1bcb6c2a148/src/frontend/ATNGraphProvider.ts#L41 |
Many thanks for looking into that @mjbvz. Unfortunately this function is not the culprit here. It definitely needs a change to include a CSP, but it is not called when you have a grammar rule selected (which is the case in this example). I tried to debug further to see where the missing csp message is generated, but that went to nowhere (I found the place where it is printed, but not the location where vscode determines if this message is needed). My (vague) assumption is that something in the generated HTML code is keeping vscode to think the csp is still missing (even though it is there). |
@mjbvz |
@seongwon-kang Can you link the the code that does this? All html used in webviews (even html that properly escapes its content) should have a content security policy |
@mjbvz it seems vscode already attach CSP metatag when webview renders to workbench. is any other path to see webview? |
Closing this since we've done work on the VS Code side to make these errors more obvious to extension authors. |
Many webview extensions do not currently set a content security policy. All webviews (even very simple ones) should set a content security policy. This is not a immediate security problem but a content security policy helps to limit the potential impact of content injections and is generally a good measure for defense in depth.
I've put together this initial list of extensions that create webviews that seem not to have a content security policy (there may be false positives). If you are feeling like a security hero, consider helping these extensions out by submitting a PR that adds a restrictive content security policy to their webviews. Here's our documentation to help you get started.
Let me know if an extension has been fixed or was incorrectly flagged
Key
Extensions
The text was updated successfully, but these errors were encountered: