Skip to content

fix(core): preserve configured project root during moves - #1930

Merged
phernandez merged 6 commits into
mainfrom
codex/security-project-move-root
Oct 28, 2026
Merged

phernandez merged 6 commits into
mainfrom
codex/security-project-move-root

Conversation

@phernandez

@phernandez phernandez commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Why

Configured project-root containment applies during creation but was bypassed by move_project, which persisted arbitrary replacement paths. Fixes #1896.

What Changed

Require a move destination to resolve strictly beneath the configured root before any config or database mutation. Reject sibling-prefix paths, unrelated paths, the shared root itself, and symlink escapes. Preserve unconstrained local moves.

Implementation Details

Use the same resolved ancestry rule as project creation. Legitimate constrained destinations are stored in resolved form. The existing update_project API caller updates only active status; path moves run through move_project.

Stacked on #1928 (the ignore-rule PR is held separately for a compatibility decision); only move containment and its regression tests are new here.

Testing

  • Before the fix: all four escape regressions failed because config and database paths were updated.
  • uv run pytest tests/services/test_project_move_root.py tests/services/test_project_service.py tests/services/test_project_service_operations.py -q --no-cov: 78 passed, 2 existing skips.
  • Real config/database tests verify rejection leaves both unchanged and valid descendants still work.
  • just fast-check: passed, including repository type checking.
  • just doctor: passed sandboxed write/index/search self-test.

Risks / Follow-ups

This addresses a configured local-root boundary, not a demonstrated hosted tenant escape. Symlink creation tests skip Windows. It does not add protection against a concurrent local process replacing symlinks after validation.

@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-28T23:21:43.917968Z 1ed4f67 Manual request
ℹ️ 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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 51e73008d5

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-nested-ignore-rules branch from 813e940 to e9b26b8 Compare October 28, 2026 21:44
@phernandez
phernandez force-pushed the codex/security-project-move-root branch from 51e7300 to 1f8f180 Compare October 28, 2026 21:44
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 1f8f180947

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-project-move-root branch from 1f8f180 to b20b121 Compare October 28, 2026 22:17
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: b20b121300

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-project-move-root branch from b20b121 to 23333cb Compare October 28, 2026 22:23
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 23333cb545

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-project-move-root branch from 23333cb to dbb46a2 Compare October 28, 2026 22:26
@phernandez
phernandez force-pushed the codex/security-nested-ignore-rules branch from 94745ce to 157a9f2 Compare October 28, 2026 22:26
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: dbb46a25df

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-project-move-root branch from dbb46a2 to 982b178 Compare October 28, 2026 23:01
@phernandez
phernandez force-pushed the codex/security-nested-ignore-rules branch from 157a9f2 to 0ab764e Compare October 28, 2026 23:01
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 982b17827d

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-nested-ignore-rules branch from 0ab764e to 145a5ec Compare October 28, 2026 23:05
@phernandez
phernandez force-pushed the codex/security-project-move-root branch from 982b178 to 29935e1 Compare October 28, 2026 23:05
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 29935e110b

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-project-move-root branch from 29935e1 to f86424e Compare October 28, 2026 23:10
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: f86424efb8

ℹ️ 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".

@phernandez
phernandez force-pushed the codex/security-project-move-root branch from f86424e to 1ed4f67 Compare October 28, 2026 23:19
@phernandez
phernandez changed the base branch from codex/security-nested-ignore-rules to codex/security-upload-destination October 28, 2026 23:19
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 1ed4f67df9

ℹ️ 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".

@phernandez
phernandez changed the base branch from codex/security-upload-destination to main October 28, 2026 23:29
An error occurred while trying to automatically change base from codex/security-upload-destination to main October 28, 2026 23:29
@phernandez
phernandez merged commit c5501a7 into main Oct 28, 2026
52 checks passed
@phernandez
phernandez deleted the codex/security-project-move-root branch October 28, 2026 23:49
phernandez added a commit that referenced this pull request Oct 29, 2026
)

## 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

- Before the fix: all twelve traversal/absolute/symlink regressions
failed across the four real sinks.
- `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.
- Controls preserve in-root absolute paths and remote logical keys;
rejected operations preserve source bytes and create no outside
directory.
- A real EntityService symlink-move regression reproduced an outside
parent directory created before rejection; 25 move/import/sink tests
pass after removing the caller mkdir.
- Review follow-up: a real outside-existing-destination probe and a
literal-tilde file move both failed before correction. `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.
- Native-colon follow-up: two real local file moves failed before
correction; 83 focused storage, move, importer and validation tests
pass, including remote-key drive restrictions.
- Python 3.12 follow-up: four real symlink-loop move cases failed before
the shared resolver correction. The 3.12 destination suite passes 21
tests; 87 focused move/storage/import/validation tests pass on 3.14.
- Canonical-file follow-up: nine real
materialization/reuse/cleanup/alias/storage-access regressions failed
before adding the shared path guard at every adapter access. `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.

---------

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep project moves inside the authorized destination root

1 participant