Behaviour SwRS-MDOKFSTUDIO-TRUST-012
Every page carries a deny-by-default content security policy
When the extension builds the policy of a page, it SHALL set its default source to none and open only the named kinds of source of the policy table (scripts and styles from the webview source or with the page nonce, images from the webview source and data URIs, fonts and media from the webview source), set connect, frame, object and worker sources, the base address and form action to none, put no bare wildcard source, unsafe-inline or unsafe-eval in it, and place it as the first meta of the head in place of any policy of the document.
Step 3 of path 1 in StRS-MDOKFSTUDIO-TRUST-006: from “The raw HTML is inert” to “The page shows the document with no foreign code and no network load”.
Scenarios 5
The situations the tests check; open one to read it.
nominalRendered page starts from none
nominalDirective table
| Directive | Value | Effect |
|---|---|---|
| script-src | the webview source and 'nonce-' followed by the page nonce, nothing else | A script from the webview source runs without a nonce (an alternative, not both required); a script element with no nonce and a source outside the webview source is not allowed |
| style-src | the webview source and 'nonce-' followed by the page nonce, nothing else | A style element with the nonce loads; an element with a style attribute is not allowed, because there is no unsafe-inline |
| img-src | the webview source followed by data: | A local image loads; an image whose address is on the network is not allowed. The data: source exists for the inline icons that styles load as masks and images |
| font-src | the webview source only | Bundled fonts for maths load; a font on the network is not allowed |
| media-src | the webview source only | A local video loads |
| connect-src, frame-src, object-src, worker-src | 'none' | A fetch call to a network address is blocked |
| base-uri, form-action | 'none' | A base element does not rebase relative addresses and a form cannot submit |
boundaryNo wildcard, unsafe-inline or unsafe-eval
| Input | Outcome |
|---|---|
| The webview source vscode-webview://unit and a nonce | The policy holds no bare asterisk source, no unsafe-inline and no unsafe-eval |
| The webview source that VS Code supplies, 'self' https://*.vscode-cdn.net | No source is a bare asterisk; the asterisk of the subdomain wildcard stays inside the host name |
refusalThe policy of the document is replaced
| Input | Outcome |
|---|---|
| A page whose head holds a meta policy default-src * | One policy remains, the extension's, as the first child of the head, and the weaker text is gone |
| A page with a Content-Security-Policy meta element in its body | The element in the body is not removed; only the policy of the head is replaced |
nominalStatus page
Implemented in 3
Tested by 6
Known limits (1)
- the webview source VS Code supplies is 'self' https://*.vscode-cdn.net, a subdomain wildcard of the webview origin, so the policy text of a real page does contain an asterisk (deduced from the VS Code 1.143.1 extension host, not run).