Repository navigation
fix(hooks): bound curl -o, -d and -H in the localhost rule - #291
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
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 に記載.-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