fix(tui): write the command history owner-only#55
Open
clawedassistant26 wants to merge 1 commit into
Open
Conversation
The pit persists every line typed at the mosh prompt to ~/.moshcode_history, and the documented flows put secrets on those lines: `/mcp install <url> -H "Authorization: Bearer …"`, `/secrets`, `/coinpay`, and the `!` shell escape. saveHistory() passed no mode, so the file was created 0644 under a normal umask and every other account on the machine could read it. Write it 0600 and chmod it on every save, since `mode` is ignored when the file already exists — that is what fixes the history files existing installs have already written. Matches what auth.mjs already does for credentials.json.
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.
The bug
The pit saves every line typed at the mosh prompt to
~/.moshcode_history, andsaveHistory()passed nomode, so the file is created 0644 under a normal umask. Any other account on the machine can read it.That matters because the documented TUI flows put secrets on the command line:
/mcp install <url> -H "Authorization: Bearer <token>"/secrets …(logicsrc credentials),/coinpay …,/ugig …!shell escape, e.g.!export STRIPE_KEY=sk_live_…src/auth.mjsalready writescredentials.jsonwithmode: 0o600, so the standard for secret-bearing files in this repo is owner-only. The history file just missed it.Repro (executed on unmodified main, real TTY)
The fix
src/tui.mjsonly:saveHistory()writes with{ mode: 0o600 }.chmodSync(…, 0o600). This is the part that matters for existing users: Node appliesmodeonly when the file is created, so every history file already on disk would otherwise keep its 0644 bits forever. Tightening on each save fixes those in place.try/catch— history is a convenience and must never be fatal. On Windowschmodis a no-op for these bits and does not throw.Tests
Two added to
test/tui.test.mjs, both driving the real CLI in a child process withHOMEpointed at a temp dir:Both skip on win32 (POSIX permission bits).
Stash-verified with
git stash push -- src/: both FAIL unpatched (9 pass / 2 fail), 11/11 with the fix.Full suite
node --test: 166 tests / 163 pass / 0 fail / 3 skipped (main baseline measured this run: 164 / 161 / 0 fail / 3 skipped).