Commit 171c7a9
authored
fix(security): sandbox vikingdb:// protocol to userData directory (#363)
The renderer-loadable `vikingdb://` protocol read any local file the
main-process had access to: the handler ran `path.resolve(filePath)` and
passed the result straight to `fs.readFileSync` with no allow-list. A
markdown image such as `` rendered
in any vault note, chat reply, or LLM response would have caused the main
process to read that file and stream the bytes back into the renderer.
This is amplified by two adjacent settings:
* `webPreferences.webSecurity` is `false`, so the renderer can `fetch()`
a custom-protocol URL and read the response body in JS.
* `renderer/index.html`'s CSP allows `connect-src *` and
`script-src 'unsafe-inline' 'unsafe-eval' *`, so any future renderer
XSS — including a stored one in vault content — has unrestricted
network egress.
Combined, the original handler turned even a minor renderer XSS into a
full local-file exfiltration primitive.
Fix: constrain the resolved path to the directory the backend writes its
data into. In production this is `app.getPath('userData')`, which mirrors
`CONTEXT_PATH` in `backend.ts` (the env var the backend uses for its own
storage root). In dev the backend is launched with `CONTEXT_PATH='.'`, so
we mirror that and allow the project working directory.
We also `fs.realpathSync` the resolved path before the under-root check,
so a symlink planted inside userData (e.g. by another local process) can't
be used to escape the sandbox.
The MIME-type table, error codes, and callback shape are unchanged, so
legitimate image loads under userData continue to work.1 parent e782408 commit 171c7a9
1 file changed
Lines changed: 40 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
204 | 207 | | |
205 | | - | |
206 | | - | |
207 | | - | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
208 | 230 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 231 | + | |
| 232 | + | |
215 | 233 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
223 | 245 | | |
224 | 246 | | |
225 | 247 | | |
| |||
0 commit comments