You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Preserve private file permissions before writing staging content #1906
Follow-up from the reviewed CodeRabbit deep scan (K30). This ticket tracks one distinct fix; duplicate scan rows are consolidated here.
Reviewed evidence and scope
K30 (scan ID 7575106d-c53a-4a39-872b-622fb795b749, review A, Low): Staging file mode is 0666 masked by umask before later mode restoration. Preserve restrictive target permissions before writing bytes.
Source at current baseline: src/basic_memory/file_utils.py:170.
Fix and validation
Preserve private file permissions before writing staging content.
Recheck current callers and supported behavior before choosing the smallest complete fix.
Add a bounded regression at the affected public or service boundary; demonstrate it fails without the fix.
Preserve legitimate inputs and tenant/project boundaries. Run focused tests plus repository static/type checks.
The scan/review establishes the code-level concern described above; it does not establish production exploitation. Conditional branches and local/tooling-only exposure must retain that scope.
Priority: Low. This is a code-level concern only, with no production exploitation established. The exposure is local, and the window is brief.
Component: Database/sync, file utilities (src/basic_memory/file_utils.py). It is not Cloud-specific.
Complexity: Simple
Findings from the code:_create_atomic_temp_path creates the staging file with os.open(..., 0o666), so the mode is 0666 masked by the umask. It then reads the target's mode. write_file_atomic_bytes writes the bytes first and only calls chmod(target_mode) afterwards. If the target is private, for example 0600, and the umask is permissive, the content sits in a more widely readable staging file until the chmod. The concern in the issue holds.
Likely fix direction (not implemented, triage only): stat the target before creating the staging file. Create the staging file with the target's mode, or 0o600 for new files, and chmod it again before the write so the umask can't widen it. Check whether the text writer above this function has the same pattern. The regression test should check the staging file's mode at write time, for example by patching the write step to capture it.
Activity
claude commentedon Oct 28, 2026
Claude finished @phernandez's task in 13s —— View job
Triage
src/basic_memory/file_utils.py). It is not Cloud-specific.Findings from the code:
_create_atomic_temp_pathcreates the staging file withos.open(..., 0o666), so the mode is 0666 masked by the umask. It then reads the target's mode.write_file_atomic_byteswrites the bytes first and only callschmod(target_mode)afterwards. If the target is private, for example 0600, and the umask is permissive, the content sits in a more widely readable staging file until the chmod. The concern in the issue holds.Likely fix direction (not implemented, triage only): stat the target before creating the staging file. Create the staging file with the target's mode, or 0o600 for new files, and chmod it again before the write so the umask can't widen it. Check whether the text writer above this function has the same pattern. The regression test should check the staging file's mode at write time, for example by patching the write step to capture it.
I found no duplicate issues.
fix(core): make atomic staging private before writing (basicmachines-…