Repository navigation
fix(viewer): contain /api/restore path joins (closes #21) - #28
Merged
Merged
Conversation
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.
|
🎉 This PR is included in version 0.3.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #21. Review finding F2. On
mainthe exact probe returns 200: POST/api/restorewith{"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 onmain(expect(res.status).toBe(400)gets 200) and pass here.Two layers:
restoreRoute—basename()the incoming name and pin it to the real snapshot grammar<epoch-ms>-<YYYY-MM-DD>.logfmtbefore any filesystem call. Legitimate viewer restores (names come from its own snapshot list) are unaffected — the existingrestoredescribe still passes unchanged.restoreSnapshot(undo.ts) — defense in depth for every caller, including thememory_undotool: 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 --noEmitclean. Stacks cleanly with the guard-order PR (both touchserver.ts, disjoint regions).