Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-TRUST-025

A resource reference resolves only to an existing file inside a root

When the extension resolves a resource reference of a page, it SHALL give the page the webview address of the file only if the reference is a relative path that decodes safely, names an existing regular file whose real path lies inside the folder of the document or the resource root of the preview, and otherwise refuse it with the code of the failed check and remove the attribute that held it.

Step 1 of path 1 in StRS-MDOKFSTUDIO-TRUST-004: from “The document refers to a local image” to “The page holds the address of a file inside the allowed roots”.

Scenarios 7

The situations the tests check; open one to read it.

nominalAccepted references
InputOutcome
image.png, a file in a resource rootthe real path of the file is returned
%61.png, with a file a.png in the rootthe file is found (percent escapes are decoded)
sub/../image.png, with a file image.png in the rootthe file is found (parent steps that stay inside the root)
a symbolic link in the root that points to a file in the rootthe real path of the target is returned
image.png?v=1#previewthe file is found and the webview address ends with ?v=1#preview
a document in book/chapters, an image in book/external-img and the workspace folder as resource rootthe image address is rewritten to a webview address (parent-relative figure image)
a file of a second, existing root, next to a root that is not on diskthe file is found
refusalReference that is not a safe relative path
InputOutcome
data:text/plain,secretrefused with the code blocked-resource-scheme
javascript:alert(1)refused with the code blocked-resource-scheme
vscode://file/secretrefused with the code blocked-resource-scheme
file:///tmp/secretrefused with the code blocked-resource-scheme
/etc/hostsrefused with the code blocked-resource-scheme
//host/sharerefused with the code blocked-resource-scheme
%E0%A4%A (malformed escape)refused with the code invalid-resource-path
a path with a backslashrefused with the code invalid-resource-path
%00 (NUL character)refused with the code invalid-resource-path
an escape nested so deep that one remains after four decodingsrefused with the code invalid-resource-path (percent escapes are decoded at most four times)
refusalReference that leaves the roots or names no regular file
InputOutcome
../outside/secret.txt, with secret.txt next to the rootrefused with the code resource-outside-root
%2e%2e%2foutside%2fsecret.txtrefused with the code resource-outside-root (the decoded path leaves the root)
../../../etc/hostname from a document in book/chaptersthe src attribute is removed with the diagnostic blocked-resource
ghost.png, a file the root does not holdrefused with the code missing-resource, with the candidate path
sub, a folder of the rootrefused with the code missing-resource (not a regular file)
a symbolic link in the root that points to a file outside itrefused with the code symlink-escape
boundaryQuery and fragment of a reference
InputOutcome
image.png?v=1#previewthe lookup ignores ?v=1#preview and the webview address of the file ends with ?v=1#preview, unchanged
image.png#a?bthe suffix is #a?b, the whole part from the first hash
boundaryRoots of a page
Givena policy with a root that is not on disk and a second, existing root
a page of a preview with restricted reads
Whenthe policy is created
a parent-relative figure image is resolved
Thenit drops the missing root, records the diagnostic missing-root with the root path (message The {label} resource root is unavailable) and resolves nothing through it, while a file of the second root is found
it is refused, because both roots are the folder of the document
nominalThe src, poster and data attributes of a page
Givenan image, a video with a poster and a source, all inside the roots
an image whose reference leaves the roots
Whenthe page is sanitized
the page is sanitized
Theneach src, poster or data value becomes the webview address of its file
the src attribute is removed and the diagnostic blocked-resource is recorded
boundaryThe srcset attribute of a page
InputOutcome
a srcset with a local image at 1x and a data: image at 2xthe srcset keeps the local image with 1x only, as a webview address
a srcset whose candidates are all refusedthe attribute is removed and the diagnostic blocked-srcset is recorded

Implemented in 2

Tested by 7