Skip to content

Treat directory prefixes as literal paths when selecting notes to move #1887

Closed

Description

@phernandez

Problem

Follow-up from the reviewed CodeRabbit deep scan (K3). This ticket tracks one distinct fix; duplicate scan rows are consolidated here.

Reviewed evidence and scope

  • K3 (scan ID ec9ff094-17d5-446b-ae55-a9039769f28c, review A, High): Literal directory prefix is interpolated into LIKE; local SQL probe confirms underscore matches a sibling. Directory move trusts these rows and slices by prefix length. Escape wildcards and test percent/underscore folder names.
    Source at current baseline: src/basic_memory/repository/entity_repository.py:763.

Fix and validation

  • Treat directory prefixes as literal paths when selecting notes to move.
  • 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 16s —— View job


    Triage

    • Type: Bug (code defect) — labeled bug; existing security label preserved.
    • Component: Database/repository layer (EntityRepository directory prefix lookup), affecting directory move via CLI/MCP. Not Cloud-specific.
    • Priority: Medium. The LIKE pattern at src/basic_memory/repository/entity_repository.py (~L763, f"{directory_prefix}/%") does not escape % or _, so a folder like my_dir can also match a sibling such as myXdir. Directory move then slices paths by prefix length, which could move or rewrite the wrong notes. The impact is on local file/DB correctness, and the scan does not establish production exploitation.
    • Complexity: Simple. Escape %, _ and the escape character in the prefix, add escape= to the like() call (or use startswith(..., autoescape=True)), then add regression tests with _ and % folder names on SQLite and Postgres. Check the other callers of this method and keep the project boundary intact.
    • Duplicates: A quick gh search issues found no obvious duplicate.

    Triage only; I have not made any code changes.

  3. added
    bug
    on Oct 28, 2026
  4. added a commit that references this issue on Oct 28, 2026
    b8b4766
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