fix(core): restrict session artifact permissions on unix (light-tested) - #2614
Open
1688mengdie wants to merge 1 commit into
Open
fix(core): restrict session artifact permissions on unix (light-tested)#26141688mengdie wants to merge 1 commit into
1688mengdie wants to merge 1 commit into
Conversation
Session JSON artifacts (prompts, outputs, transcripts) are written to a temporary file that inherits the process umask, typically 0o644, and are then renamed into place, so the published file stays world-readable on multi-user hosts. Before publishing the temporary file, tighten its permissions to owner-only (previous mode masked with 0o700) on unix so the renamed artifact ends up 0o600-equivalent regardless of the process umask. Permission tightening is best-effort: failures to read or set the permissions are logged and the write still succeeds. Test: cargo check --locked -p bitfun-services-core --jobs 4 (0 errors, 0 warnings); cargo test --locked -p bitfun-services-core --features local-storage --test storage_owner_contracts --jobs 4 (12 passed). AI: AI-assisted, locally tested (cargo check + contract tests on Windows; unix behavior to be exercised by the CI ubuntu/macos matrix).
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.
Summary
On unix, session JSON artifacts written through
JsonFileStore(sessiontranscripts, metadata, token usage) were published with permissions
inherited from the process umask — typically 0o644 — making prompt and
output content world-readable on multi-user hosts.
This PR tightens the temporary artifact file to owner-only (previous
mode masked with 0o700) before it is renamed into place, so the
published artifact ends up 0o600-equivalent regardless of the process
umask. Permission tightening is best-effort: failures to read or set the
permissions are logged and the write still succeeds. Windows behavior is
unchanged (the tightening block is compiled out on non-unix targets).
Fixes #2605
Type and Areas
Type: security fix
Areas: Agent runtime / core
Verification
cargo check --locked -p bitfun-services-core --jobs 4— passed (0 errors, 0 warnings).cargo test --locked -p bitfun-services-core --features local-storage --test storage_owner_contracts --jobs 4— 11 passed, 0 failed (same count before and after the change: zero regression).#[cfg(unix)]-gated and compiles out on Windows).Reviewer Notes
std::os::unix::fs::PermissionsExt— no new dependencies.Checklist
This is an AI-assisted change.