Skip to content

fix(core): match nested directory ignore rules by ancestry - #1929

Merged
phernandez merged 9 commits into
mainfrom
codex/security-nested-ignore-rules
Oct 29, 2026
Merged

phernandez merged 9 commits into
mainfrom
codex/security-nested-ignore-rules

Conversation

@phernandez

@phernandez phernandez commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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.

@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-29T00:51:14.607666Z e1c2fb7 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8694d3ef9d

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 813e940765

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez
phernandez force-pushed the codex/security-nested-ignore-rules branch from 813e940 to e9b26b8 Compare October 28, 2026 21:44
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9b26b84fa

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d3acb3c84

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@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: 157a9f2de7

ℹ️ 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 157a9f2 to 0ab764e Compare October 28, 2026 23:01
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@phernandez
phernandez force-pushed the codex/security-upload-destination branch from c75ddfc to 456dd50 Compare October 28, 2026 23:05
@phernandez
phernandez force-pushed the codex/security-nested-ignore-rules branch from 0ab764e to 145a5ec 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: 0ab764eca8

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 145a5ecdd5

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76c7149ee3

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

Comment thread src/basic_memory/ignore_utils.py Resolved
Base automatically changed from codex/security-upload-destination to main October 28, 2026 23:29
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a37883d170

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb92ca2042

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5b36f57bb

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@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: d5b36f57bb

ℹ️ 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 added a commit that referenced this pull request Oct 29, 2026
## 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]>
@phernandez
phernandez force-pushed the codex/security-nested-ignore-rules branch from d5b36f5 to 9ecdca9 Compare October 29, 2026 00:37
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ecdca92b9

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

Comment thread src/basic_memory/ignore_utils.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: e1c2fb7f1b

ℹ️ 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 merged commit d2942b7 into main Oct 29, 2026
55 checks passed
@phernandez
phernandez deleted the codex/security-nested-ignore-rules branch October 29, 2026 01:04
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.

Apply nested ignore rules to their anchored relative paths

1 participant