Skip to content

fix(hooks): bound curl -o, -d and -H in the localhost rule - #291

Merged
furedea merged 3 commits into
mainfrom
fix/local-curl-paths
Oct 22, 2026
Merged

furedea merged 3 commits into
mainfrom
fix/local-curl-paths

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

概要

localhost 向け curl の literal_words ルールが,出力先パス・送信ファイル・ヘッダーを制限していなかった問題を修正する.

背景

  • curl -s -o /Users/kaito/.zshrc http://localhost/ はサーバーの応答で任意のファイルを上書きできた.
  • curl -s -d @/etc/passwd http://localhost/ は任意のファイルをローカルサーバーへ送信できた.
  • curl -s -H 'Host: evil.com' http://localhost/ が許可されていた.

書き込みを制限しないサンドボックスのプロバイダーとフックを共有しているため,ルール側で制限する.

変更内容

  • -o: /dev/null のみ許可.それ以外のファイル出力はすべて ask.
    • フックは -o のパスを,curl が実際に開くファイルに結び付けられない.実行時の作業ディレクトリがペイロードの cwd と異なることがあり,チェック後にシンボリックリンクを作成することもできる.
    • そのため,相対パス・隠しパス・シンボリックリンクを判定する方式(is_local_output と cwd の受け渡し)は廃止し,完全一致の /dev/null のみを許可する形にした.
    • /dev/null/,/dev/./null,//dev/null,- も ask.
  • -d: @ で始まる値(シングルクォート内を含む)は ask.
  • -H: Accept,Content-Type,User-Agent のみ許可(大文字小文字不問,制御文字なし).Authorization,Cookie,Host,その他は ask.理由はルールの justification に記載.
  • PR 287 の形式(シングルクォートの -w,-D -,--compressed,読み取り専用フィルターのパイプ,固定のオプション順)は維持.

テスト

  • tests/agents/hooks/test_request_command.py で,すべてのファイル出力が ask になり /dev/null だけが通ることを確認.-d と -H の ask/allow も追加.
  • tests/agents/hooks/test_allowed_command.py の localhost ダウンロード例を -o /dev/null に更新.
  • uv run --frozen pytest tests/agents: 2283 passed.vulture,deptry,lefthook も成功.

Closes #289

🤖 Generated with Claude Code

furedea and others added 3 commits October 22, 2026 14:43
Allow -o only for /dev/null or relative paths without parent segments,
ask for -d values that start with @, and allow only Accept,
Content-Type, and User-Agent headers.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Resolve the -o target against the payload cwd and ask when it has a
hidden component or goes through a symlink, so it cannot write
.git/hooks or reach outside the working tree.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A hook cannot bind the -o path to the file curl opens: the execution
workdir can differ from the payload cwd, and a symlink can be created
after the check. Drop the path and cwd checks and ask for every file
output.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea
furedea merged commit f1159ee into main Oct 22, 2026
11 checks passed
@furedea
furedea deleted the fix/local-curl-paths branch October 22, 2026 10:11
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.

localhost への curl の許可で,-o と -d @file が任意のパスを扱える

1 participant