Skip to content

fix(rg): gate explicit symlink dereference behind --follow - #1688

Merged
chaliy merged 1 commit into
mainfrom
2026-05-22-propose-fix-for-rg-symlink-vulnerability
May 24, 2026
Merged

chaliy merged 1 commit into
mainfrom
2026-05-22-propose-fix-for-rg-symlink-vulnerability

Conversation

@chaliy

@chaliy chaliy commented May 22, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • rg previously dereferenced explicit symlink targets at the builtin layer regardless of follow settings, bypassing the VFS no-follow contract and enabling reads outside the intended search root or across mounts.

Description

  • Threaded follow_symlinks into explicit-path resolution by adding a follow_symlinks parameter to resolve_rg_explicit_path and updating its callers so explicit user paths are only dereferenced when -L/--follow is enabled.
  • Updated directory-detection and helper call sites (has_directory_path, collect_rg_inputs, collect_rg_file_list, meta_is_file_and_matches) to use the new follow_symlinks flag for consistent behavior.
  • Preserved existing recursive -L traversal behavior while restoring default no-follow semantics for explicit paths to re-establish the VFS containment guarantee.
  • Adjusted symlink differential tests so the explicit-file and explicit-directory symlink cases are exercised under -L.

Testing

  • Ran cargo test -p bashkit --lib builtins::rg::tests::diff_rg_matches_real_rg_symlink_cases -- --nocapture, and the test passed.
  • The changes are validated by the repository's symlink differential cases that cover both recursive -L and explicit-path scenarios and now succeed under the updated contract.

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 22, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 86f41ec Commit Preview URL May 22 2026, 10:21 PM

@chaliy
chaliy merged commit f516844 into main May 24, 2026
34 checks passed
@chaliy
chaliy deleted the 2026-05-22-propose-fix-for-rg-symlink-vulnerability branch May 24, 2026 09:06
chaliy added a commit that referenced this pull request May 30, 2026
### Motivation
- `rg` previously dereferenced explicit symlink targets at the builtin
layer regardless of follow settings, bypassing the VFS no-follow
contract and enabling reads outside the intended search root or across
mounts.

### Description
- Threaded `follow_symlinks` into explicit-path resolution by adding a
`follow_symlinks` parameter to `resolve_rg_explicit_path` and updating
its callers so explicit user paths are only dereferenced when
`-L/--follow` is enabled.
- Updated directory-detection and helper call sites
(`has_directory_path`, `collect_rg_inputs`, `collect_rg_file_list`,
`meta_is_file_and_matches`) to use the new `follow_symlinks` flag for
consistent behavior.
- Preserved existing recursive `-L` traversal behavior while restoring
default no-follow semantics for explicit paths to re-establish the VFS
containment guarantee.
- Adjusted symlink differential tests so the explicit-file and
explicit-directory symlink cases are exercised under `-L`.

### Testing
- Ran `cargo test -p bashkit --lib
builtins::rg::tests::diff_rg_matches_real_rg_symlink_cases --
--nocapture`, and the test passed.
- The changes are validated by the repository's symlink differential
cases that cover both recursive `-L` and explicit-path scenarios and now
succeed under the updated contract.

------
[Codex
Task](https://chatgpt.com/codex/cloud/tasks/task_e_6a105c02a8f0832b8cd57510ed01dc69)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant