[bug]Fix dot-dot-prefixed repo path filtering#1395
Open
stale2000 wants to merge 1 commit into
Open
Conversation
Repo files such as ..generated/schema.json are valid children, but several containment checks treated any relative path beginning with two dots as traversal. Centralize the check so only actual parent-directory segments are rejected, then use that rule in repo-relative conversion and checkpoint metadata walkers. Constraint: Git and local filesystems allow names that merely start with two dots Rejected: Keep ad hoc HasPrefix checks | they repeat the original false-positive pattern and drift from IsSubpath Confidence: high Scope-risk: narrow Directive: Keep traversal checks segment-aware; do not reject prefixes like ..generated unless product policy explicitly bans those filenames Tested: go test ./cmd/entire/cli/paths ./cmd/entire/cli/checkpoint Tested: local throwaway repo reproduced old ToRelativePath drop and fixed behavior Not-tested: mise run check after removing unrelated auth fixture change Entire-Checkpoint: a77f6e131de5
34d53ca to
966164a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Entire session log: https://entire.io/gh/stale2000/cli/session/019eaaa8-c4a4-71b2-93d0-e249a631f82c
Issue
Repo-relative path filtering treated any relative path beginning with two dots as path traversal. That is too broad: the path segment
..means parent directory, but names like..generated,..cache, or..schemaare ordinary legal filenames/directories when they are inside the repository.The affected logic showed up in two places:
paths.ToRelativePathreturned an empty string for anyfilepath.Relresult with a..prefix.path traversal detected.Effects
A valid repo file such as:
is inside
/repo, and Git reports it as repo-relative path:Before this fix, Entire could treat that path as outside the repo because it starts with
... The practical effects were:ToRelativePathsilently returned"", so legal files could be filtered out of checkpoint file tracking.path traversal detectederror.Simple Reproduction
Create a clean repo with a legal child path that starts with two dots:
Git treats the file as in-repo:
The old check behaved like this:
The correct distinction is:
Fix
This PR centralizes traversal detection in
paths.IsRelativeTraversaland makes it segment-aware:..../..\..generated/schema.jsonToRelativePath,IsSubpath, and the checkpoint metadata walkers now use the shared helper instead of repeating broadstrings.HasPrefix(rel, "..")checks.Tests
Added regression coverage for:
paths.ToRelativePathpreserving..generated/schema.json..parent segmentsVerification
go test ./cmd/entire/cli/paths ./cmd/entire/cli/checkpoint..generated/schema.jsonand the fixed logic preserves itRelated Work
I checked existing issues and PRs. The closest prior work was #1365, which hardened real path traversal through attacker-controlled session/tool/subagent IDs. This PR covers a different bug: false positives for legal repo child paths whose names start with
...