Document safe parsing for preToolUse.toolArgs when it is a JSON-encoded string
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 68/100
- issue の種類
- ドキュメント
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
調査の方向性
Hooks リファレンスと、その preToolUse ペイロードのセクションから始めます。toolArgs が JSON でエンコードされた文字列になる場合があることをドキュメント化し、無効な値やオブジェクトではない値を処理する安全な Bash および Python のパース例を追加します。hook の作成者が command、path、url などのフィールドを確実に調べられるようになれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
The Hooks reference documents preToolUse.toolArgs as unknown, but does not show how hook authors should safely parse it.
In actual Copilot CLI hook invocations I tested, toolArgs arrived as a JSON-encoded string rather than a parsed object. That may be valid under the current unknown contract, but it is easy for hook authors to assume object-style access and accidentally write hooks that fail to inspect tool arguments.
Because hook failures are fail-open, this is a security footgun for policy-enforcing hooks.
Observed behavior
For preToolUse, the documentation shows the camelCase payload shape as:
{
sessionId: string;
timestamp: number;
cwd: string;
toolName: string;
toolArgs: unknown;
}
In tested CLI/App-backed hook invocations, the payload effectively behaved like:
{
"toolName": "bash",
"toolArgs": "{\"command\":\"echo hello\"}"
}
rather than:
{
"toolName": "bash",
"toolArgs": {
"command": "echo hello"
}
}
I am not claiming the string form is invalid. Since the schema says unknown, this may be intentional or implementation-defined. The problem is that the docs do not tell hook authors how to handle it safely.
Why this matters
Security hooks commonly inspect fields like:
.toolArgs.command
.toolArgs.path
.toolArgs.url
If toolArgs is a JSON-encoded string, this kind of access does not work as expected. Depending on the script and shell settings, the hook may fail, emit invalid output, or skip the intended check.
Since hook failures are fail-open, a parsing mistake can silently bypass a security policy.
Request
Please document the expected handling for toolArgs and provide safe parsing examples.
At minimum, the docs should say something like:
toolArgsisunknownand may be a JSON-encoded string. Hook scripts should check its runtime type and parse it before inspecting tool arguments.
A Bash example would help:
INPUT="$(cat)"
TOOL_ARGS_JSON="$(
jq -c '
(.toolArgs // .tool_args // .tool_input // {}) as $args
| if ($args | type) == "string" then ($args | fromjson? // {}) else $args end
' <<< "$INPUT"
)"
COMMAND="$(jq -r '.command // ""' <<< "$TOOL_ARGS_JSON")"
Python example:
import json
import sys
payload = json.load(sys.stdin)
tool_args = payload.get("toolArgs", payload.get("tool_input", {}))
if isinstance(tool_args, str):
try:
tool_args = json.loads(tool_args)
except json.JSONDecodeError:
tool_args = {}
if not isinstance(tool_args, dict):
tool_args = {}
command = tool_args.get("command", "")
Expected improvement
This would make hook authoring safer, especially for security-focused preToolUse hooks, and reduce the chance of fail-open bypasses caused by incorrect assumptions about the runtime type of toolArgs.
- 主要言語
- Shell
- スター
- 11.2k
- フォーク
- 1.9k
- 平均マージ
- 14時間 16分
- マージ済み PR(30日)
- 6
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/copilot-cli のほかの issue
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
github/copilot-cli#4909 ·
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
github/copilot-cli#4906 ·
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
github/copilot-cli#4848 ·
-
area:agents area:mcp
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
github/copilot-cli#4729 ·
-
area:sessions
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
github/copilot-cli#4712 ·
github/copilot-cli の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
community-scripts/ProxmoxVE#17425 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
danielmiessler/LifeOS#2218 ·
-
agent-research-recommend agent-review-finding
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
jordansmall/spindrift#3714 · コメント 1 件 ·