Document safe parsing for preToolUse.toolArgs when it is a JSON-encoded string
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Ambito
- documentation, security
Direzione di ricerca
Inizia con il riferimento a Hooks e la relativa sezione sul payload di preToolUse. Documenta che toolArgs può essere una stringa codificata in JSON, quindi aggiungi esempi sicuri di parsing in Bash e Python che gestiscano valori non validi o non oggetto; il lavoro è completato quando gli autori degli hook possono ispezionare in modo affidabile campi come command, path o url.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Shell
- Stelle
- 11.2k
- Fork
- 1.9k
- Merge medio
- 14h 16m
- PR unite (30g)
- 6
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di github/copilot-cli
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
github/copilot-cli#4848 ·
-
area:agents area:mcp
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
github/copilot-cli#4729 ·
-
area:sessions
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
github/copilot-cli#4712 ·
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
github/copilot-cli#4638 ·
-
Expose large_output_file_path on TaskShellProgress so clients can read complete shell-task output Apertaarea:tools
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
github/copilot-cli#4630 · 1 commento ·
Tutte le issue di github/copilot-cli
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
danielmiessler/LifeOS#2218 ·
-
docs(agents): strengthen the no-backslash-escaped-backticks rule with an issue-creation example Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Update ghgrab to 2.1.0 Apertapackage-update
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
oSoWoSo/vOid_Community_repOsitory#148 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
chore
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
alunduil/alunduil-chezmoi#792 ·