Repository navigation
fix(core): enforce project boundaries at import and storage sinks - #1931
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2146f0d32a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
678b3a2 to
51e7300
Compare
2146f0d to
a29f24d
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47f7789fc6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
51e7300 to
1f8f180
Compare
47f7789 to
21d4111
Compare
|
@codex review |
21d4111 to
f2939a7
Compare
1f8f180 to
b20b121
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
f2939a7 to
4923a55
Compare
b20b121 to
23333cb
Compare
|
@codex review |
23333cb to
dbb46a2
Compare
4923a55 to
46d3ab7
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
dbb46a2 to
982b178
Compare
46d3ab7 to
f610f1d
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
982b178 to
29935e1
Compare
f610f1d to
4c483a3
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
29935e1 to
f86424e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
416add7 to
0719993
Compare
f86424e to
1ed4f67
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0719993b75
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e347ea275
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f08aa8bf4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
c5ceade to
c6f0eb1
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
CodeQL alert 95 was inspected, including its SARIF data flows. The flagged sink is Path.resolve() in the shared containment validator. The resolved path must pass is_relative_to(resolved_root) before it is returned for any content I/O; this is the normalize-then-validate sequence recommended by the alert itself. Existing real traversal, sibling-prefix, absolute/symlink, move-preflight, materialization reuse, and cleanup regressions reject escapes and preserve outside bytes. Dismissed alert 95 as a sanitizer-model false positive: https://github.com/basicmachines-co/basic-memory/security/code-scanning/95 . No code or guards changed. |
## Why Project creation and project moves duplicated resolved-root checks, and note moves maintained separate portable-path syntax checks. The user requested shared path helpers across these security boundaries. ## What Changed Reuse resolve_path_within_root for project creation and project moves, requiring strict descendants of a configured root. Reuse valid_project_path_value for note-move syntax. Uploads already use that portable validator in #1928; storage/import/materialization guards already share resolved containment in #1931. ## Implementation Details The shared helpers live in the preceding PRs. This PR removes the remaining project and note-move copies and adds controls for root permissions, sibling-prefix and symlink escapes, filename spelling, and literal tildes. Filename normalization remains an explicit operation policy; reference validation keeps its existing default restrictions. Object-storage keys do not resolve against the host filesystem. Stacked on #1931. The ignore-rule PR (#1929) is held separately and is not a dependency. ## Testing - `uv run pytest tests/utils/test_path_containment.py tests/utils/test_validate_project_path.py tests/utils/test_remote_project_paths.py tests/runtime/test_note_move_destination.py tests/services/test_destination_containment.py tests/services/test_project_move_root.py tests/services/test_project_root_containment.py tests/cli/cloud/test_upload_destination.py -q --no-cov`: 118 passed on the final stack. - `just fast-check`: passed, including repository type checking. - `just doctor`: passed sandboxed write/index/search self-test. ## Risks / Follow-ups Note moves apply the shared portable restrictions, including control characters and Windows-normalized traversal segments. File storage explicitly permits literal tildes because it never expands home markers. Native POSIX storage preserves literal-colon names; remote keys and reference validation retain their drive restrictions. Archive syntax remains a separately stricter format contract. --------- Signed-off-by: phernandez <[email protected]>
Why
Importer destinations, local accepted-note materialization, and regular-file moves can escape the selected project through traversal, absolute paths, or existing symlink ancestors. Twelve bounded real-filesystem regressions reproduced writes or moves outside the project. A complete directory-call audit reproduced two additional bypasses in Memory JSON and Claude project imports, which now use the guarded importer helper. Fixes #1908 (K34/K41/K42).
What Changed
Add one explicit FileService project-path guard and call it at importer folder/write boundaries, all local materialization storage reads/writes/deletes and cleanup alias checks, and regular-file move source/destination boundaries. Reject before creating directories or changing files.
Implementation Details
Reuse the existing portable relative-path validator and resolved local ancestry check. Absolute spellings remain supported within the chosen local root, including resolved aliases. Object storage validates relative logical keys without consulting the host filesystem. Validate EntityService move paths before existence preflight and rollback probes; remove its redundant mkdir so the guarded storage move owns parent creation. Storage paths permit literal tildes because these boundaries do not expand home markers. Native local POSIX storage also preserves literal-colon names; remote keys retain the portable drive restriction. The shared resolved-root helper also translates resolution failures, including Python 3.12 symlink-loop RuntimeError, into validation errors before storage mapping. General directory creation stays available for choosing arbitrary local project roots.
Stacked on #1930; only these destination boundaries and their regressions are new here.
Testing
uv run pytest tests/importers/test_import_directory_containment.py tests/services/test_destination_containment.py tests/importers/test_importer_base.py tests/services/test_file_service.py tests/cloud/test_note_content_materialization.py -q --no-cov: 75 passed.uv run pytest tests/services/test_non_markdown_moves.py tests/services/test_destination_containment.py tests/importers/test_import_directory_containment.py tests/services/test_file_service.py tests/utils/test_validate_project_path.py -q --no-cov: 74 passed.uv run pytest tests/services/test_materialization_containment.py tests/services/test_destination_containment.py tests/cloud/test_note_content_materialization.py -q --no-cov: 59 passed.just fast-check: passed, including repository type checking.just doctor: passed sandboxed write/index/search self-test.Risks / Follow-ups
This enforces the selected project boundary while preserving arbitrary project-root selection. It does not claim to prevent a concurrent local process swapping symlinks after validation. Symlink regressions skip Windows where privileges may be needed. Hosted adapters overriding these file operations retain their own storage authorization responsibilities.