fix(security): contain private session artifacts - #1249
Conversation
a43daa3 to
d948433
Compare
d948433 to
344d4e3
Compare
344d4e3 to
62618aa
Compare
39b3b0e to
3f63142
Compare
3f63142 to
6c0e62c
Compare
5d6f2b8 to
351dd9a
Compare
351dd9a to
ac475fd
Compare
ac475fd to
697a920
Compare
697a920 to
fc0988a
Compare
fc0988a to
0327faf
Compare
0327faf to
762f947
Compare
ce6aea4 to
7f86590
Compare
b813e92 to
ec933cf
Compare
4040af1 to
7b0751d
Compare
7b0751d to
da27926
Compare
da27926 to
6006f3d
Compare
|
@codex review |
Apocrathia
left a comment
There was a problem hiding this comment.
Do a pass to make sure we're actually using this new utility in the places that actually matter.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6006f3d407
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cf9e3ae. Configure here.
|
@Apocrathia Ready for re-review. The private-file utility now covers JSONL export and RLM artifact-directory boundaries, all five automated security findings are fixed with behavioral/race coverage, current main is merged, CI is green, and all review threads are resolved. |

Summary
This is the private-storage portion extracted from #1159 and proposed directly against current
main.Risk
Medium. The change intentionally rejects unsafe pre-existing paths and symlinks. Existing regular files remain supported and are repaired to private modes where appropriate. User-selected HTML export directories are not chmodded; the emitted file itself remains private.
Provenance
The two commits preserve
cherry picked fromtrailers for original commitsb0ce5adf20ec8c891dd44e8b39bdb0ab453a5ebaand4ede067b97f803957af36aefe16487e15851c363from #1159. No MCP/provider changes are included.Validation
npm run checknpx vitest --run test/suite/regressions/1105-session-storage-security.test.ts test/suite/regressions/1105-named-sinks-security.test.ts test/kernel-state-snapshot.test.ts test/interactive-mode-debug-command.test.ts— 31 passedPYTHONPATH=prime-agent-runtime/src python3 -m unittest prime-agent-runtime/test/test_harness.py— 36 passedgit diff --check origin/main...HEADReview focus
Please focus on path containment, symlink/non-regular-file rejection, POSIX mode repair, Windows fallbacks, and the intentionally different parent-directory policy for user-selected HTML exports.
Note
Medium Risk
Touches core persistence and intentionally rejects unsafe existing paths/symlinks; behavior changes on Windows and environments without O_NOFOLLOW, though regular files are repaired where possible.
Overview
This PR hardens session, auth, harness, refinement, snapshot, export, and temp-file paths so sensitive data cannot escape via traversal IDs, symlinks, or permissive modes.
It introduces
utils/private-files.tsand replaces scatteredfsusage with helpers that enforce 0o700/0o600, atomic writes, and O_NOFOLLOW (no insecure fallback).SessionManagernow validates session IDs, confines artifact dirs undersession-artifacts, rejects symlink/non-regular transcripts, and usesownsSessionDirso user-selected transcript parents are not chmodded. Auth, refinement/harness, IPython snapshots, HTML export, and editor/share temps go through the same layer; Windows gets in-memory harness state and/refinefails early. README documents POSIX requirements and residual race limits.Reviewed by Cursor Bugbot for commit c498fb9. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Harden session and artifact storage against symlink attacks, path traversal, and permissive file modes
utils/private-files.tswith O_NOFOLLOW-based helpers (ensurePrivateFile,readPrivateFile,writePrivateFileAtomic,appendPrivateFile,createPrivateTempFile, etc.) that enforce 0o700/0o600 permissions and reject symlinks at every step.fscalls throughout session, auth, harness, refinement, and interactive-mode code paths with these privacy-aware helpers, making all sensitive file reads and writes atomic and symlink-safe.SESSION_ID_PATTERN) to reject traversal IDs, and validates artifact directory paths against path-escape and symlink attacks inSessionManager./refineon Windows, returning in-memory state with a clear error instead of attempting filesystem access.state-snapshot.tsto requireO_NOFOLLOW, use atomic temp-file writes with 0o600, and reject symlinked or non-regular destinations.O_NOFOLLOW(and Windows for harness persistence) now fail closed rather than falling back to unsafe operations.Changes since #1249 opened
Macroscope summarized cf9e3ae.