Repository navigation
fix(cli): validate normalized upload destinations before dispatch - #1928
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: 4d0756ca95
ℹ️ 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: 8abb40565a
ℹ️ 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: c655134892
ℹ️ 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: 47300a226b
ℹ️ 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 |
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]>
c75ddfc to
456dd50
Compare
|
@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". |
## 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. --------- Signed-off-by: phernandez <[email protected]>
## 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 Nested directory ignore rules were compared to individual components, so explicitly excluded paths remained selected for indexing and export. Review also reproduced fnmatch differences for separators, globstars, and caret-negated classes. Fixes #1913. ## What Changed Use pathspec for trailing-slash directory rules in the shared should_ignore_path helper. All consumers, including indexing, uploads, and ZIP planning, use the same matching behavior. Keep existing non-directory matching and unordered exclusion-set behavior. ## Implementation Details Declare pathspec >=1.1.1,<2 as a runtime dependency and lock it at 1.1.1. Compile complete directory-rule collections with the pure-Python backend and a bounded cache of 32 ignore sets. A large rule set compiles once across files rather than churning a per-rule cache. Preserve raw directory-rule escapes when loading ignore files. Distinguish directories from files with a trailing slash when matching. Remote and ZIP callers pass their known file kind explicitly so a conflicting local directory cannot silently hide a virtual file. Two narrow normalizations retain Git behavior that differs from this pathspec release: whole components containing two or more stars use globstar semantics, and terminal directory globstars must consume a directory. Literal leading !/# names retain their existing exclusion-set meaning. The custom component-matching algorithm is removed. Compile patterns independently inside each cached collection so invalid lines cannot disable valid directory or file exclusions; invalid pathspec patterns and invalid regex ranges are skipped consistently with Git tolerance. Based on main after #1928; this PR is independent of the project/storage/YAML stack. ## Testing - Before correction: nested rules, separator boundaries, zero-level and terminal globstars, longer-star components, and caret-negated classes reproduced failures. - `uv run pytest tests/cli/test_nested_ignore_rules.py tests/cli/test_ignore_utils.py tests/importers/test_project_zip_import.py tests/cli/cloud/test_upload_destination.py tests/cli/cloud/test_webdav_transfer.py -q --no-cov`: 165 passed. - Virtual-file regression: a remote file named `keys` was omitted when the local side held a directory at `keys` and the rules included `keys/`; the real transfer-plan regression failed before the fix and passes afterward, while `keys/secret.md` remains excluded. - Cache regression: 513 rules across three real files constructed 1,539 regex patterns before the fix and 513 after. The regression counts actual pathspec calls with cProfile, without replacing its implementation or timing thresholds. - Invalid-rule regressions: four combinations of unusable directory rules and valid directory/file exclusions failed before isolation and pass after it. - Real Git comparison across 180,069 generated file/directory cases: zero differences. Includes directory pruning, all-star components, and caret/exclamation-negated character classes. - `just fast-check`: passed, including repository type checking. - `just package-check`: passed all consolidated package checks. - `just doctor`: passed sandboxed write/index/search self-test. ## Risks / Follow-ups This adds a runtime dependency. It uses pathspec's supported pattern syntax with the explicit globstar compatibility cases above; it does not promise every Git extension. Ordered ignore-file negation is unchanged and remains outside this fix because the existing loaders return unordered exclusion sets. Non-directory matching is unchanged. --------- Signed-off-by: phernandez <[email protected]>
Why
Legacy upload normalizes literal POSIX backslashes into separators without validating the resulting destination. A real temporary filename
safe\..\..\other-project\leak.mdbecamesafe/../../other-project/leak.md; the HTTP client dispatched its PUT to/webdav/other-project/leak.md. Fixes #1905.What Changed
Validate every destination using the shared portable relative-path contract before sizing, dry-run reporting, or any authenticated request. Reject the batch when a destination carries traversal, a drive, or an absolute root.
Implementation Details
Reject literal backslash filenames instead of remapping them to another remote key. Convert native directory separators with Path.as_posix(), then use the shared portable path-value validator with filename-preserving behavior. This preserves distinct edge-space and Unicode filename spellings. Skip archive validation because archives never reach dispatch. Cover both directory discovery and explicitly selected files. Regression tests run real files and a FastAPI HTTP receiver through ASGITransport, without mocking upload behavior.
Stacked on #1927; only upload destination validation and its tests are new here.
Testing
uv run pytest tests/cli/cloud/test_upload_destination.py tests/cli/cloud/test_upload_symlinks.py tests/cli/cloud/test_upload_path.py tests/cli/test_upload.py -q --no-cov: 30 passed.just fast-check: passed, including repository type checking.just doctor: passed sandboxed write/index/search self-test.Risks / Follow-ups
A client-side route escape is reproduced, not a hosted authorization bypass: server-side project authorization is still a separate boundary. Single-file and directory uploads reject unsupported literal backslashes. Native upload filenames explicitly allow literal colons, including one-letter prefixes, because these names are discovered relative to the selected tree and URL-encoded. Path-reference callers retain the default Windows-drive restriction. Filename spaces and Unicode spelling are preserved; three added real HTTP regressions failed before the spelling fix.