Skip to content

Check resolved project ancestry without string-prefix containment #1891

Closed

Description

@phernandez

Problem

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

Reviewed evidence and scope

  • K4 (scan ID c949ff1a-cdb3-4354-9b75-67cf21ee7d38, review A, Medium): Resolved containment uses string startswith, allowing sibling-prefix paths through existing symlinks. Use path ancestry; local configured-root scope.
    Source at current baseline: src/basic_memory/services/project_service.py:291.

Fix and validation

  • Check resolved project ancestry without string-prefix containment.
  • 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 (security hardening, code-level)
    • Priority: Medium. This is a local, configured-root scope concern. The issue doesn't establish production exploitation.
    • Component: Core services (ProjectService.add_project). Not Cloud-specific, though the code path only runs when project_root is set, which is how cloud deployments configure it.
    • Complexity: Simple

    Findings

    • The check is at src/basic_memory/services/project_service.py:291. It uses resolved_path.startswith(base_path.resolve().as_posix()). If project_root is /app/data, a resolved path of /app/data-evil/x passes the check. A symlink under the root that points to a sibling directory would reach that case.
    • The check is marked # pragma: no cover, so no test currently exercises it.
    • The fix is to compare path ancestry, for example Path(resolved_path).is_relative_to(base_path.resolve()), instead of comparing strings.
    • A regression test should create a symlink inside project_root that points to a sibling directory with the same prefix, such as root-evil. It should assert that add_project raises ValueError, and it should fail before the fix.
    • Remove the pragma: no cover once the test covers the branch, because the repo requires 100% coverage.
    • I found no duplicate issues.

    Per triage scope, I haven't made any code changes.

  3. added
    bug
    on Oct 28, 2026
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