Replies: 7 comments 21 replies
-
Here is a demo extension that works with csp headers, although the "unsafe-inline" is not too sophisticated. What is the csp meta tag have you set? What do you mean by rouge styles? Do they come from the library? If yes, which ones? (I'm guessing it's related to the Icon component.) If I understand the documentation correctly, the 'litNonce' only relevant to the older browsers. I created a demo to test a strict CSP: <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'nonce-abc123'; script-src-elem 'nonce-abc123'; font-src 'self' data: 'nonce-abc123'"
/>
<title>VSCode Elements</title>
<link
rel="stylesheet"
href="/node_modules/@vscode/codicons/dist/codicon.css"
id="vscode-codicon-stylesheet"
nonce="abc123"
/>
<script
type="module"
src="/node_modules/@vscode-elements/webview-playground/dist/index.js"
nonce="abc123"
></script>
<script nonce="abc123">
window.litNonce = 'abc123';
</script>
<script type="module" src="/dist/main.js" nonce="abc123"></script>
</head>
<body>
<h1>Using nonce property</h1>
<main>
<vscode-demo>
<vscode-icon name="account"></vscode-icon>
<vscode-icon name="loading" size="32" spin spin-duration="3"></vscode-icon>
<vscode-button>Hello World</vscode-button>
<vscode-button secondary>Hello World</vscode-button>
</vscode-demo>
</main>
</body>
</html> This is the rendered page: I got a bunch of errors:
This is all I currently know about CSP. I hope it will be thought-provoking. |
Beta Was this translation helpful? Give feedback.
-
My current https://github.com/microsoft/genaiscript/blob/main/packages/vscode/src/webview.ts#L42 |
Beta Was this translation helpful? Give feedback.
-
Oh, and ignore this part - it has no effect: <script nonce="abc123">
window.litNonce = 'abc123';
window.vscodeWebviewPlaygroundNonce = 'abc123';
</script> |
Beta Was this translation helpful? Give feedback.
-
I'm seeing: |
Beta Was this translation helpful? Give feedback.
-
Sorry, I made a mistake. The I'll get back to you with the solution. |
Beta Was this translation helpful? Give feedback.
-
a few more style updates. should the vscode-elements have the nonce attribute? |
Beta Was this translation helpful? Give feedback.
-
i am using the react wrappers btw |
Beta Was this translation helpful? Give feedback.
-
I was wondering if there was a sample/example of webviewpanel implementation with CSP (Content Security Policy) policies applied to the HTML. I am seeing some rogue styles being inject by lit-html. I have tried to set
window.litNonce
so that the style element gets the 'nonce' attribute but this did not seem to fix the issue.Beta Was this translation helpful? Give feedback.
All reactions