Skip to content

Preserve private file permissions before writing staging content #1906

Closed

Description

@phernandez

Problem

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.

Activity

  1. added
    security
    on Oct 28, 2026
  2. claude commented on Oct 28, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 13s —— View job


    Triage

    • Type: bug (hardening, security-labelled)
    • 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.

    I found no duplicate issues.

  3. added
    bug
    on Oct 28, 2026
  4. added a commit that references this issue on Oct 29, 2026
    9b77c18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsecurity

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions