Sanitize Hook Payloads
Treat host hook envelopes as untrusted, potentially huge, and potentially secret-bearing.
Workflow
- Trace the envelope from host stdin through normalization, mapping, and appendTrace.
- Set an input byte ceiling before parsing JSON.
- Reduce tool input to an allowlisted metadata summary before it reaches runtime state.
- Apply recursive redaction and serialized-size limits as defense in depth.
- Rotate traces by bytes and preserve atomic append behavior.
- Keep host hooks non-blocking while recording a bounded failure reason.
- Test equivalent envelopes for Claude Code, Codex, and Pi.
Tool summaries
- Write: keep path, byte length, hash, and contentOmitted.
- Edit: keep path, old/new lengths, hashes, and range metadata.
- Bash: keep classification, basename, and a bounded preview.
- Unknown: keep scalar metadata and key names only.
Redact content, old_string, new_string, patch, prompt, messages, authorization, tokens, passwords, secrets, and API keys case-insensitively.
Required invariants
- Never persist raw Write or Edit bodies.
- Never echo rejected stdin.
- Never rely only on host-provided sizes.
- Measure the serialized trace before writing.
- Keep trace rotation compatible with legacy trace.jsonl.
- Never delete the active segment.
- Keep safety ceilings effective even when configuration is malformed.
Dotcontext routing
- Keep host field mapping in src/integrations.
- Keep stdin limits in src/cli.
- Keep reusable sanitization and trace policy in src/harness.
- Update hook installer tests and public hook docs when observable behavior changes.
- Follow F-02.
Review gate
Verify a multi-megabyte Write produces a small trace, sensitive fixtures never appear on disk, oversized stdin stays non-blocking, rotation survives concurrent appends, and package smoke tests pass.
1---2name: sanitize-hook-payloads3description: Design, implement, or review safe lifecycle-hook payload capture and trace persistence. Use for Claude Code, Codex, or Pi hook dispatch; PostToolUse Write/Edit/Bash mapping; stdin parsing; trace redaction; trace quotas; rotation; or hook privacy and performance changes.4---56# Sanitize Hook Payloads78Treat host hook envelopes as untrusted, potentially huge, and potentially secret-bearing.910## Workflow11121. Trace the envelope from host stdin through normalization, mapping, and appendTrace.132. Set an input byte ceiling before parsing JSON.143. Reduce tool input to an allowlisted metadata summary before it reaches runtime state.154. Apply recursive redaction and serialized-size limits as defense in depth.165. Rotate traces by bytes and preserve atomic append behavior.176. Keep host hooks non-blocking while recording a bounded failure reason.187. Test equivalent envelopes for Claude Code, Codex, and Pi.1920## Tool summaries2122- Write: keep path, byte length, hash, and contentOmitted.23- Edit: keep path, old/new lengths, hashes, and range metadata.24- Bash: keep classification, basename, and a bounded preview.25- Unknown: keep scalar metadata and key names only.2627Redact content, old_string, new_string, patch, prompt, messages, authorization, tokens, passwords, secrets, and API keys case-insensitively.2829## Required invariants3031- Never persist raw Write or Edit bodies.32- Never echo rejected stdin.33- Never rely only on host-provided sizes.34- Measure the serialized trace before writing.35- Keep trace rotation compatible with legacy trace.jsonl.36- Never delete the active segment.37- Keep safety ceilings effective even when configuration is malformed.3839## Dotcontext routing4041- Keep host field mapping in src/integrations.42- Keep stdin limits in src/cli.43- Keep reusable sanitization and trace policy in src/harness.44- Update hook installer tests and public hook docs when observable behavior changes.45- Follow [F-02](../../../specs/performance/f-02-sanitize-hook-payloads.md).4647## Review gate4849Verify a multi-megabyte Write produces a small trace, sensitive fixtures never appear on disk, oversized stdin stays non-blocking, rotation survives concurrent appends, and package smoke tests pass.50