Markdown OKF-Schema Studio

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
Givena rendered preview page, or a policy built for any webview source and nonce
Whenits policy is read
Thenit starts with default-src 'none' and every other directive narrows or opens a named kind of source
nominalDirective table
DirectiveValueEffect
script-srcthe webview source and 'nonce-' followed by the page nonce, nothing elseA 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-srcthe webview source and 'nonce-' followed by the page nonce, nothing elseA style element with the nonce loads; an element with a style attribute is not allowed, because there is no unsafe-inline
img-srcthe 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-srcthe webview source onlyBundled fonts for maths load; a font on the network is not allowed
media-srcthe webview source onlyA 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
InputOutcome
The webview source vscode-webview://unit and a nonceThe policy holds no bare asterisk source, no unsafe-inline and no unsafe-eval
The webview source that VS Code supplies, 'self' https://*.vscode-cdn.netNo source is a bare asterisk; the asterisk of the subdomain wildcard stays inside the host name
refusalThe policy of the document is replaced
InputOutcome
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 bodyThe element in the body is not removed; only the policy of the head is replaced
nominalStatus page
Givena preview waiting for its first render, or a preview whose render failed (the pending, error and missing-source pages)
Whenthe status page is built
Thenit holds the policy meta with a nonce of its own (a fresh nonce for the error page), a style element that carries the nonce, and no script element

Implemented in 3

Tested by 6

Known limits (1)