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
| Input | Outcome |
|---|---|
| image.png, a file in a resource root | the real path of the file is returned |
| %61.png, with a file a.png in the root | the file is found (percent escapes are decoded) |
| sub/../image.png, with a file image.png in the root | the file is found (parent steps that stay inside the root) |
| a symbolic link in the root that points to a file in the root | the real path of the target is returned |
| image.png?v=1#preview | the 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 root | the 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 disk | the file is found |
refusalReference that is not a safe relative path
| Input | Outcome |
|---|---|
| data:text/plain,secret | refused with the code blocked-resource-scheme |
| javascript:alert(1) | refused with the code blocked-resource-scheme |
| vscode://file/secret | refused with the code blocked-resource-scheme |
| file:///tmp/secret | refused with the code blocked-resource-scheme |
| /etc/hosts | refused with the code blocked-resource-scheme |
| //host/share | refused with the code blocked-resource-scheme |
| %E0%A4%A (malformed escape) | refused with the code invalid-resource-path |
| a path with a backslash | refused 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 decodings | refused with the code invalid-resource-path (percent escapes are decoded at most four times) |
refusalReference that leaves the roots or names no regular file
| Input | Outcome |
|---|---|
| ../outside/secret.txt, with secret.txt next to the root | refused with the code resource-outside-root |
| %2e%2e%2foutside%2fsecret.txt | refused with the code resource-outside-root (the decoded path leaves the root) |
| ../../../etc/hostname from a document in book/chapters | the src attribute is removed with the diagnostic blocked-resource |
| ghost.png, a file the root does not hold | refused with the code missing-resource, with the candidate path |
| sub, a folder of the root | refused with the code missing-resource (not a regular file) |
| a symbolic link in the root that points to a file outside it | refused with the code symlink-escape |
boundaryQuery and fragment of a reference
| Input | Outcome |
|---|---|
| image.png?v=1#preview | the lookup ignores ?v=1#preview and the webview address of the file ends with ?v=1#preview, unchanged |
| image.png#a?b | the 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
a page of a preview with restricted reads
Whenthe policy is created
a parent-relative figure image is resolved
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
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
an image whose reference leaves the roots
Whenthe page is sanitized
the 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
the src attribute is removed and the diagnostic blocked-resource is recorded
boundaryThe srcset attribute of a page
| Input | Outcome |
|---|---|
| a srcset with a local image at 1x and a data: image at 2x | the srcset keeps the local image with 1x only, as a webview address |
| a srcset whose candidates are all refused | the attribute is removed and the diagnostic blocked-srcset is recorded |
Implemented in 2
Tested by 7
- test/integration/untrusted-suite.tsintegration
- test/security/html-policy.test.tsunit
- test/security/resource-policy.memory.test.tsunit
- test/security/resource-policy.test.tsunit
- test/security/trustReq.pageBuild.requirements.test.tsunit
- test/security/trustReq.requirements.test.tsunit
- test/session/webview.priming.test.tsunit