Skip to content

fix(viewer): contain /api/restore path joins (closes #21) - #28

Merged
abogartz merged 1 commit into
mainfrom
fix/viewer-restore-containment
Oct 21, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix/viewer-restore-containment

Conversation

@abogartz

Copy link
Copy Markdown
Owner

Closes #21. Review finding F2. On main the exact probe returns 200: POST /api/restore with {"name":"../../outside/planted.logfmt"} copies a file from outside the store into <memoryRoot>/planted.logfmt, loadAll() globs it up, and its rows become injectable memory — an arbitrary-file-read + persistent-poisoning primitive (completes into a browser chain with the #11 XSS). The new containment tests fail on main (expect(res.status).toBe(400) gets 200) and pass here.

Two layers:

  1. restoreRoute — basename() the incoming name and pin it to the real snapshot grammar <epoch-ms>-<YYYY-MM-DD>.logfmt before any filesystem call. Legitimate viewer restores (names come from its own snapshot list) are unaffected — the existing restore describe still passes unchanged.
  2. restoreSnapshot (undo.ts) — defense in depth for every caller, including the memory_undo tool: resolve the target and throw if it would land outside the memory root.

memory_undo's tool path already basenamed; it keeps its behavior and gains the escape check.

Full gate on this branch: 196 tests / 0 fail, tsc --noEmit clean. Stacks cleanly with the guard-order PR (both touch server.ts, disjoint regions).

restoreRoute built both path joins from raw body.name: a name of
'../../outside/planted.logfmt' returned 200 and promoted an arbitrary
user-readable file into the active store, where loadAll() picks it up
and every future session injects it (issue #21, probe on main 286d2ba).

Route layer: basename() the name and require the real snapshot grammar
'<epoch-ms>-<YYYY-MM-DD>.logfmt' before any filesystem call. Store layer
(defense in depth for every restoreSnapshot caller, including the
memory_undo tool): resolve the target and refuse if it escapes the
memory root.
@abogartz
abogartz merged commit b0b73ee into main Oct 21, 2026
2 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz
abogartz deleted the fix/viewer-restore-containment branch October 22, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

viewer /api/restore joins raw body.name — files outside the store can be promoted into memory

1 participant