Skip to content

fix(redact): leave JSON keys and identifiers alone; keep PEM matches inside one string - #330

Merged
fylorn merged 1 commit into
mainfrom
fix/redact-structural-fields
Oct 12, 2026
Merged

fylorn merged 1 commit into
mainfrom
fix/redact-structural-fields

Conversation

@fylorn

@fylorn fylorn commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Problem

  • A custom redaction rule is matched as a substring over the whole request body, including item ids. Codex sends ids like fco_<uuid v7> (hex), so a rule such as abc123 can land inside one; the placeholder makes the id invalid and the upstream rejects the request (invalid input[N].id ... contained additional characters). The history is resent every turn, so the conversation stays broken.
  • The private-key rule searched for its END marker across the whole body. A lone -----BEGIN ... PRIVATE KEY----- header in one message joined up with an END in a later message, and every item in between was replaced by one placeholder (items silently dropped, two items merged into one object).

Fix

  • flow::hits drops hits inside JSON keys and inside the values of identifier keys: id, *_id, *Id, type, role, name, namespace, model, status, object, phase — next to the base64 payloads it already skipped. One shared JSON string walker (json_strings) serves both.
  • private_keys looks for the header end and END only within the JSON string the header is in.

Tests

  • keys_and_identifiers_are_left_alone: Responses, Anthropic and Bedrock shaped ids, call ids, tool names, keys and model stay; text, tool output and arguments are still replaced.
  • a_pem_does_not_reach_into_the_next_string.
  • cargo test -p tw-guard, cargo test -p tw-gateway, clippy and fmt pass locally.

🤖 Generated with Claude Code

…inside one string

Outbound redaction ran its rules over the whole request body, so a custom
rule such as `abc123` matched inside item ids (Codex sends `fco_<uuid>`),
call ids, tool names and keys. The placeholder made the id invalid and the
upstream rejected the request; since the history is resent every turn, the
conversation stayed broken.

Hits now skip every key and the values of identifier keys (`id`, `*_id`,
`*Id`, `type`, `role`, `name`, `namespace`, `model`, `status`, `object`,
`phase`), alongside the base64 payloads that were already skipped.

The private-key rule searched for the END marker across the whole body: a
lone `-----BEGIN` in one message joined up with an END in a later one and
replaced every item in between with a single placeholder. In JSON it now
looks only within the string the header is in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit a2ba209 into main Oct 12, 2026
6 checks passed
@fylorn
fylorn deleted the fix/redact-structural-fields branch October 12, 2026 04:37
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant