Skip to content

fix(tools): refuse symlinked init targets and bound ignore-file reads - #217

Merged
lg2m merged 7 commits into
fix/eng-973-cap-raise-reachablefrom
fix/eng-974-init-symlink-ignore-bounds
Sep 29, 2026
Merged

lg2m merged 7 commits into
fix/eng-973-cap-raise-reachablefrom
fix/eng-974-init-symlink-ignore-bounds

Conversation

@lg2m

@lg2m lg2m commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Stack ENG-968 (v0.1.5 readiness), 6 of 9. Merge in order; diff shown is this layer only.

Bugs

  • qq init --project --force followed a symlinked .qq or .qq/config.ron and truncated the link's target.
  • .gitignore/.ignore/.qqignore were read whole regardless of size; a FIFO in their place blocked the walk forever.

Fix

InitError::Symlink for either path. Ignore files: regular file only, ≤ 256 KiB (bounded read), else treated as absent.

Tests

force_refuses_to_write_through_a_symlinked_project_config, a_fifo_or_oversized_ignore_file_is_skipped_not_read.

Measured (search_walk, 10k files, 20 it, before/after)

content_rare 5306/5055 µs · definition_full 21847/21697 µs · tree_depth2 5350/5235 µs: no regression from the added stat.

Docs: design/tools.md § read-side walk. Linear: ENG-974.

Verification (top of stack)

cargo test --workspace 1970 passed / 0 failed / 7 ignored; cargo clippy --workspace --all-targets --all-features -- -D warnings clean; cargo fmt --all -- --check clean; cargo test -p qq-provider --no-default-features --features test-support passed.

qq init --project --force followed a symlinked .qq or .qq/config.ron and
truncated the link's target; both are now refused with InitError::Symlink.

Ignore files (.gitignore, .ignore, .qqignore) were read whole whatever their
size, and a FIFO in their place blocked the walk at open. Only a regular file
of at most 256 KiB is read now; anything else counts as absent.

search_walk bench before/after (10k files, 20 iterations): content_rare
5306/5055 us, definition_full 21847/21697 us, tree_depth2 5350/5235 us; no
regression from the added stat.

Refs: ENG-974
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 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-09-29T06:36:33.930123Z b363ecd New commits
ℹ️ 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.

@lg2m
lg2m added this pull request to stack #221 September 29, 2026 02:17

@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: a7fcb67ddc

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/init.rs Resolved
Comment thread crates/qq-core/src/tools/walk.rs Resolved
…eck atomic with the open

Review (Codex, #217): both checks ran before the open, so a writer in the
directory could swap in a symlink (init --force would then truncate the
target) or a FIFO (the walk would block at open) in between.

- qq init opens the target relative to an O_NOFOLLOW|O_DIRECTORY handle on
  its directory, with O_NOFOLLOW (and O_EXCL unless --force); ELOOP/ENOTDIR
  map to InitError::Symlink. Root enables rustix's fs feature on unix
  (no new crate or version: Cargo.lock gains only the qq -> rustix edge).
- Ignore files open O_NOFOLLOW|O_NONBLOCK and the type and size are checked
  on the opened descriptor.

Regressions (each fails on the old check-then-open code):
the_open_itself_refuses_links_swapped_in_after_the_check,
an_ignore_file_swapped_for_a_fifo_or_link_after_listing_is_not_read.
search_walk bench unchanged within noise (tree_depth2 5069 us, content_rare
5396 us).

Also merges #216 into this branch.

Refs: ENG-974
…w option

Pre-push review: the O_NOFOLLOW|O_NONBLOCK flags were passed as raw custom
flags. cap-primitives' manual path resolution (macOS, or Linux without
openat2) reads ELOOP as a symlink to follow unless its own follow option is
No, so a symlinked .gitignore could still be read there. Set follow(No) and
nonblock through cap-primitives' options instead.

Refs: ENG-974

@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: b363ecd63d

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/init.rs
Comment on lines +307 to +311
.write(true)
.create_new(!force)
.create(force)
.truncate(force)
.open(path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Refuse Windows reparse points in the forced open

On Windows, when --force targets a project directory writable by another user or process, that writer can replace config.ron with a symlink or junction after symlink_metadata succeeds; this ordinary OpenOptions::open follows the reparse point and truncates its target. The fresh evidence after the prior Unix fix is this new cfg(not(unix)) branch, which still separates the check from the destructive open even though Windows is a shipped release target; open without following reparse points and validate the opened handle atomically.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Won't fix now: before this PR Windows had no symlink check at all, and the Unix path is atomic. Opening without following reparse points needs FILE_FLAG_OPEN_REPARSE_POINT via Windows APIs we don't depend on yet. Follow-up for the Windows target.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@lg2m
lg2m merged commit 0f6a10e into main Sep 29, 2026
@lg2m
lg2m deleted the fix/eng-974-init-symlink-ignore-bounds branch September 29, 2026 18:56
lg2m added a commit that referenced this pull request Sep 29, 2026
)

* test(store): upgrade a v0.1.4 (schema 35) session store to current

v0.1.5 carries migrations 36 to 39. A store populated through the runtime is
rewound to the v0.1.4 shape (no sessions.approval_delegate, schema_version
35), then reopened: it migrates to STORE_SCHEMA_VERSION, keeps the session
and its prompt, invents no delegate override, accepts SetApprovalDelegate,
and reopens as a no-op. Removing the 36 step makes the test fail.

Refs: ENG-975

* Merge #217 into test/eng-975; address Codex review

Review (Codex, #218):
- The reopen only rechecked schema_version. It now reopens the runtime and
  asserts the delegate written before closing (off) and the transcript are
  unchanged.
- The prompt was matched anywhere in the serialized snapshot, which the
  session title also contains. The test now asserts the focused message
  rows: the user prompt text and a complete, non-empty assistant reply.

Refs: ENG-975
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.

1 participant