Symlink-to-file inside scanned root reads file content outside the root without --follow-symlinks

未关闭 适合新手
#354 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli, security

调研方向

从 discover_files() 构建队列的文件发现代码开始,然后沿着已入队的条目进入 read_file_with_binary_check。比较 Path::is_file() 和 entry.metadata() 对 root 内 symlink 与 symlink_metadata 的报告结果,并用该 issue 的 canary 设置和在默认模式下运行 code2prompt -q -O - <root> 来复现。完成意味着默认模式不输出任何 canary 字节,且有一个测试覆盖指向 root 外部的 symlink。

由索引模型根据 Issue 内容生成。

描述

Summary

discover_files() enqueues any entry whose relative path strips inside the canonical root when Path::is_file() is true. Path::is_file() follows symlinks, so a symlink to an outside regular file is queued even with follow_links=false (default). entry.metadata() returns symlink lstat metadata, whose len is the target path string length, so read_file_with_binary_check opens the link target and reads min(8192, symlink_target_len) bytes of the outside file.

To reproduce

Create an outside canary file, then an in-root symlink pointing to it (../canary.txt), and run 'code2prompt -q -O - '. Default mode still emits the canary prefix.

Expected

Symlink targets must not be read when follow_symlinks is false.

Actual

Output contains the first symlink_target_len bytes of the outside canary

Independent CLI reproduction in default mode (no -L) leaked the first 35 bytes of a canary file located outside the scanned root through an in-root symlink. The leak is bounded by the symlink target path string length (min(8192, symlink_target_len, target_file_len)); it is not a full-file read.

Observed side effect:

Project Path: v1-root-1795224537

Source Tree:

```txt
v1-root-1795224537
└── leak.txt

leak.txt:

INDEPENDENT_VERIFIER_CANARY_MARKER_

## Impact

Partial read outside the configured root, bounded by symlink target path length (up to PATH_MAX ~4096 bytes).

## Version

v4.2.0
主要语言
Rust
星标
7.8k
派生
459
平均合并
3 天 20 小时
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

mufeedvh/code2prompt 的其他 Issue

查看 mufeedvh/code2prompt 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。