FileStore: symlinked parent directories escape the store root

未关闭
#2,078 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@caiotheodoro 已经在做这个了。

开始于 2026年11月25日。

  • #2079 来自 @caiotheodoro —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend, security

调研方向

Start with anthropic/lib/tools/_file_store.py and trace how each listed operation resolves paths beneath the store root; the issue identifies parent symlinks as the gap in the leaf-only O_NOFOLLOW check. Run the reproduction on macOS or Linux and check the FileStore tests for the affected verbs. Done means paths through a symlinked parent raise FileStoreError instead of accessing files outside the root; an open linked pull request is already addressing this issue.

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

描述

FileStore paths can escape the root through a symlinked parent

FileStore blocks lexical .. paths and refuses symlinked leaf files, but it doesn't validate symlinked directories in the middle of a path. A pre-existing symlink below the root is enough to read, write, move, or delete files outside the store.

Repro on macOS/Linux:

import os
import tempfile
from pathlib import Path

import anyio

from anthropic.lib.tools._file_store import FileStore

async def repro():
    with tempfile.TemporaryDirectory() as td:
        base = Path(td)
        outside = base / "outside"
        outside.mkdir()
        (outside / "secret.md").write_text("secret")

        store = await FileStore.open(base / "store")
        await store.create_root()
        os.symlink(outside, store.root().path / "link")

        await store.put("link/new.md", "written outside")
        assert (outside / "new.md").read_text() == "written outside"

        assert await store.get("link/secret.md") == b"secret"

        await store.remove("link/secret.md")
        assert not (outside / "secret.md").exists()

anyio.run(repro)

Expected: each operation raises FileStoreError, since link/... escapes the confined root.

Actual: the operations follow the symlink and act on the outside directory.

This affects every verb that resolves a path below the root (put, get, ls, find_symlinks, hashtree, hash_file, move, and remove). The leaf-only O_NOFOLLOW check doesn't protect parent components.

主要语言
Python
星标
4.1k
派生
915
PR 合并指标
30 天内没有已合并 PR

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

anthropics/anthropic-sdk-python 的其他 Issue

查看 anthropics/anthropic-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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