fix(security): write job sidecar files with 0600 mode (#3753)#3809
Merged
Conversation
Async job sidecar files (jobs/result-<jobId>.json) were written with the default umask. Defense-in-depth (#3753): the payload may carry job-result data, so restrict to the owner in case NEXUS_DATA_DIR is ever shared across users. Not exploitable today (per-user stdio MCP, randomUUID jobIds) — pure hardening. - Extract persistJobRecord(path, record) (DRY over the 4 writers: pending/complete/ failed/cancelled) — writeFileSync with mode 0o600 + chmodSync after, so the mode holds even when a terminal status overwrites a pre-existing default-umask pending file (the writeFileSync mode option only applies on create). - 4 new tests assert 0600 on each terminal write, on pending-create, and the pending->complete overwrite path. 11 + 81 jobs tests pass; typecheck + lint clean. Closes #3753. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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 #3753.
What
Async job sidecar files (
<NEXUS_DATA_DIR>/jobs/result-<jobId>.json) were written with the default umask. Defense-in-depth (post-session security audit finding): the payload may carry job-result data, so restrict to the owner ifNEXUS_DATA_DIRis ever shared across users. Not exploitable today (per-user stdio MCP, randomUUID jobIds, sha256 idempotency filenames) — pure hardening.How
persistJobRecord(path, record)— DRY over the four writers (writeJobPending/Complete/Failed/Cancelled, previously four identicalwriteFileSynccalls). It writes with{ mode: 0o600 }andchmodSync(path, 0o600)after — thechmodguarantees the mode even when a terminal status overwrites a pre-existing pending file (thewriteFileSyncmode option only applies on file create, not overwrite).Tests (TDD red→green)
4 new tests: 0600 on each terminal write (complete/failed/cancelled), on
writeJobPendingcreate, and on the pending→complete overwrite path (the case thechmodcovers). 11 store tests + 81 jobs-suite tests pass; typecheck + lint clean.🤖 Generated with Claude Code