Skip to content

fix(core): escape literal directory prefixes before moves - #1915

Merged
phernandez merged 1 commit into
mainfrom
codex-security-literal-directory-prefix
Oct 28, 2026
Merged

phernandez merged 1 commit into
mainfrom
codex-security-literal-directory-prefix

Conversation

@phernandez

@phernandez phernandez commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Why

A directory name containing _ or % was interpolated into a SQL LIKE pattern. Moving team_a therefore also selected and moved canonical notes in teamXa. Fixes #1887; part of basicmachines-co/basic-memory-cloud#2825.

What Changed

Directory-prefix selection now escapes SQL metacharacters and keeps the trailing directory separator. Added API and repository regressions for sibling isolation, nested folders, and literal wildcard characters.

Implementation Details

Use SQLAlchemy startswith(..., autoescape=True) to retain existing backend casing behavior and project filtering while treating the supplied prefix as a literal path. The API test verifies the unselected sibling's actual Markdown bytes, accepted path, and revision stay unchanged.

Testing

  • Before the fix, the API regression moved the unrelated sibling note and failed.
  • uv run pytest test-int/test_directory_moves.py tests/repository/test_entity_repository.py tests/repository/test_directory_prefix_literals.py -q --no-cov: 64 passed (SQLite).
  • just fast-check: passed, including type checking.
  • BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/test_directory_moves.py tests/repository/test_directory_prefix_literals.py -q --no-cov: 8 passed, 1 intentional SQLite-only case-sensitivity skip.
  • uv run pytest test-int/mcp/test_move_directory_integration.py -q --no-cov: 7 passed.

Risks / Follow-ups

The existing SQLite case-insensitive matching and PostgreSQL case-sensitive matching are retained. No production changes or data repair are performed by this PR.

@phernandez phernandez added the security Security hardening and vulnerability fixes label Oct 28, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T18:55:43.091796Z b5a77ef PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@phernandez
phernandez added this pull request to stack #1918 October 28, 2026 19:51
@phernandez
phernandez merged commit b8b4766 into main Oct 28, 2026
53 checks passed
@phernandez
phernandez deleted the codex-security-literal-directory-prefix branch October 28, 2026 20:24
phernandez added a commit that referenced this pull request Oct 28, 2026
## Why

A cyclic ChatGPT conversation graph keeps expanding children even after
its message has been seen. Cycles through message-less nodes hang too.
Fixes #1888 (deep-scan K45 / Cloud C35); part of
basicmachines-co/basic-memory-cloud#2825.

## What Changed

Track visited mapping keys before expanding children. Retain existing
message deduplication and conversation order. Add bounded subprocess
tests at the real CLI import boundary for self-cycles on the root, a
message, and an empty node, plus shared descendants.

## Implementation Details

Graph identity is the mapping key used by child references, so traversal
uses a separate set from the existing embedded-message identity set.
This bounds expansion to the finite input graph without changing
ordinary exports or silently abandoning unrelated conversations.

Stacked on #1915; only the ChatGPT traversal and its tests are new in
this PR.

## Testing

- Before the fix: three real CLI imports exceeded the 15-second
subprocess limit; subprocesses were killed by the test.
- `uv run pytest tests/importers/test_chatgpt_graphs.py
tests/cli/test_import_chatgpt.py tests/mcp/tools/test_chatgpt_tools.py
-q --no-cov`: 33 passed.
- `just fast-check`: passed, including type checking.

## Risks / Follow-ups

Cloud must update its Core dependency after these fixes land. No
production deployment is included. Other import/resource-budget findings
remain separate issues.

Signed-off-by: phernandez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security Security hardening and vulnerability fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Treat directory prefixes as literal paths when selecting notes to move

1 participant