Skip to content

fix(security): contain private session artifacts - #1249

Open
sethkarten wants to merge 4 commits into
mainfrom
sethkarten/security-private-files
Open

fix(security): contain private session artifacts#1249
sethkarten wants to merge 4 commits into
mainfrom
sethkarten/security-private-files

Conversation

@sethkarten

@sethkarten sethkarten commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • validate session identifiers and keep all session-derived paths inside the configured session directory
  • write session, auth, snapshot, debug, refinement, export, editor, and harness artifacts with private modes and atomic/no-follow protections
  • reject symlink and non-regular-file sinks where sensitive data could otherwise escape or be exposed

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 from trailers for original commits b0ce5adf20ec8c891dd44e8b39bdb0ab453a5eba and 4ede067b97f803957af36aefe16487e15851c363 from #1159. No MCP/provider changes are included.

Validation

  • npm run check
  • npx 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 passed
  • PYTHONPATH=prime-agent-runtime/src python3 -m unittest prime-agent-runtime/test/test_harness.py — 36 passed
  • focused Biome check on all changed TypeScript files
  • git diff --check origin/main...HEAD

Review 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

High Risk
Touches auth credential storage and session/artifact persistence with fail-closed symlink and permission checks. Existing permissive or symlinked paths will hard-error, and Windows loses persistent /refine harness storage.

Overview
Hardens private persistence so session, auth, harness, snapshot, export, editor, and debug sinks reject traversal IDs, symlinks, and non-regular files, and write with atomic O_NOFOLLOW opens plus 0o600/0o700 modes.

Adds a shared private-files helper and routes sensitive writers through it. Session IDs are validated and artifact paths are confined to their root; unsafe existing sinks fail closed rather than being followed or repaired into attacker-controlled targets.

Windows fails closed for persistent harness storage and /refine (in-memory sessions remain). Kernel snapshot save/restore and the Python harness get matching no-follow/atomic private writes.

Reviewed by Cursor Bugbot for commit 6006f3d. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Harden session and artifact storage against symlink attacks and unsafe file permissions

  • Introduces a new private-files utility module with helpers for atomic, permission-hardened (0600/0700) file and directory operations that reject symlinks and non-regular files via O_NOFOLLOW.
  • Applies these helpers across session storage, auth storage, refinement/harness state, log files, HTML exports, and external editor temp files in both the Node and Python runtimes.
  • Adds session ID validation (1–128 alphanumeric/dot/underscore/hyphen characters) across creation, header parsing, and path construction to prevent path traversal via malformed IDs.
  • Disables persistent harness storage on Windows in both the TypeScript agent and the Python runtime (prime-agent-runtime), returning in-memory state with explicit errors on mutation attempts.
  • Risk: Existing files or directories with permissive modes or symlinked paths that were previously accepted will now cause errors; symlinked session files, artifact directories, and harness state paths are rejected outright rather than silently followed.

Macroscope summarized 6006f3d.

Comment thread packages/coding-agent/src/utils/private-files.ts
Comment thread packages/coding-agent/src/core/session-manager.ts
Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
Comment thread packages/coding-agent/src/modes/interactive/components/extension-editor.ts Outdated
Comment thread prime-agent-runtime/src/rlm/harness.py
Comment thread prime-agent-runtime/src/rlm/harness.py
Comment thread packages/coding-agent/src/utils/private-files.ts
Comment thread packages/coding-agent/src/utils/private-files.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch 2 times, most recently from a43daa3 to d948433 Compare August 11, 2026 18:58
Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
Comment thread packages/coding-agent/src/utils/private-files.ts
Comment thread packages/coding-agent/src/utils/private-files.ts Outdated
Comment thread packages/coding-agent/src/core/refinement/refinement.ts
Comment thread packages/coding-agent/src/utils/private-files.ts Outdated
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from d948433 to 344d4e3 Compare August 11, 2026 19:11
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from 344d4e3 to 62618aa Compare August 11, 2026 19:16
Comment thread packages/coding-agent/src/core/refinement/refinement.ts
Comment thread packages/coding-agent/src/utils/private-files.ts
Comment thread prime-agent-runtime/src/rlm/harness.py
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from 39b3b0e to 3f63142 Compare August 11, 2026 19:21
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/core/kernel/state-snapshot.ts Outdated
Comment thread packages/coding-agent/src/core/refinement/refinement.ts
Comment thread packages/coding-agent/src/utils/private-files.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from 3f63142 to 6c0e62c Compare August 11, 2026 19:27
Comment thread packages/coding-agent/src/utils/private-files.ts Outdated
Comment thread packages/coding-agent/src/core/refinement/refinement.ts
Comment thread packages/coding-agent/src/core/kernel/state-snapshot.ts
Comment thread packages/coding-agent/src/utils/private-files.ts Outdated
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch 3 times, most recently from 5d6f2b8 to 351dd9a Compare August 11, 2026 19:38
Comment thread packages/coding-agent/src/core/kernel/state-snapshot.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from 351dd9a to ac475fd Compare August 11, 2026 19:39
Comment thread packages/coding-agent/src/core/agent-session.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from ac475fd to 697a920 Compare August 11, 2026 19:41
Comment thread packages/coding-agent/src/core/refinement/refinement.ts Outdated
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from 697a920 to fc0988a Compare August 11, 2026 19:43
Comment thread packages/coding-agent/src/core/session-manager.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from fc0988a to 0327faf Compare August 11, 2026 19:45
Comment thread packages/coding-agent/src/core/session-manager.ts
Comment thread packages/coding-agent/src/utils/private-files.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from 0327faf to 762f947 Compare August 11, 2026 19:49
Comment thread packages/coding-agent/src/core/auth-storage.ts
Comment thread packages/coding-agent/src/utils/private-files.ts Outdated
Comment thread packages/coding-agent/src/config.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch 2 times, most recently from ce6aea4 to 7f86590 Compare August 11, 2026 19:55
Comment thread packages/coding-agent/src/core/session-manager.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7f86590. Configure here.

Comment thread packages/coding-agent/src/core/refinement/refinement.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch 2 times, most recently from b813e92 to ec933cf Compare August 11, 2026 20:08
Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch 2 times, most recently from 4040af1 to 7b0751d Compare August 11, 2026 20:15
Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
Comment thread packages/coding-agent/src/core/session-manager.ts
Comment thread packages/coding-agent/src/utils/private-files.ts
Comment thread packages/coding-agent/src/core/kernel/state-snapshot.ts
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from 7b0751d to da27926 Compare August 11, 2026 20:21
@sethkarten
sethkarten force-pushed the sethkarten/security-private-files branch from da27926 to 6006f3d Compare August 11, 2026 20:22
@sethkarten
sethkarten requested a review from Apocrathia August 11, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant