You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(redaction): recognize signatures only at protocol positions - #983
None. Hardens signed-content handling in request redaction.
变更内容 / Change Content
Bug 修复 / Bug fix
新功能 / New feature
其他改动 / Other changes
Request redaction sends signed upstream content back unchanged when its signature carries no gateway record, so the upstream receives the exact bytes it signed. That rule assumes such content is unmodified upstream output. Two cases broke the assumption and let plaintext through:
Gemini placeholder signatures. Clients that move history from another model or source into Gemini fill skip_thought_signature_validator or context_engineering_is_the_way_to_go, the values Gemini documents for skipping signature validation. That content was never signed by the upstream and can hold plaintext the gateway restored earlier, yet it was forwarded unredacted. These values are no longer treated as signatures: the content is redacted like other upstream-authored history and the placeholder is kept.
Signature lookalikes outside protocol positions. The request side treated any object in upstream-authored history as signed if it looked like a signed block (any thinking or reasoning.* block, or any object with function, thoughtSignature, or thought_signature), while responses only record signatures at protocol positions. Content the gateway restored elsewhere, such as Chat thinking_blocks from LiteLLM-style upstreams, came back without a record and was forwarded unredacted. The request side now recognizes a signature only where responses record one: elements of the content, parts, reasoning_details, and tool_calls arrays held directly by an assistant or model message or a reasoning item (Claude thinking and Responses reasoning text in content, Gemini parts, reasoning details, and Gemini-compatible tool calls). Same-named arrays nested deeper, and everything else, are redacted as ordinary upstream-authored content.
Signed content at protocol positions without a record is still sent unchanged, so fixed replacement and turns without restoration keep valid signatures.
Compatibility: no migration or API change. A signature-like block outside the protocol positions whose text matches a rule is now rewritten; if the upstream validates that signature, the request fails instead of sending plaintext.
Verification: make check passed. New tests cover both placeholder values for Gemini parts (thoughtSignature and thought_signature) and Gemini-compatible tool calls, and signature lookalikes in Chat thinking_blocks, Anthropic text blocks, Gemini parts, reasoning details, or tool calls placed in content, same-named parts and content arrays nested under another field, and arrays nested inside content, in both replacement and encryption modes. The existing unrecorded-signature test now places each block at its real protocol position and adds Responses reasoning text. Gateway redaction and restore tests pass unchanged.
自查清单 / Checklist
我已运行 make check,或在说明中写明无法运行的原因和未验证范围。 / I ran make check, or documented why it could not run and what remains unverified.
本 PR 范围聚焦,未包含无关改动。 / This PR is focused and contains no unrelated changes.
我已更新必要的公开文档或发布说明。 / I updated any required public documentation or release notes.
我已确认提交、日志和测试数据不包含敏感信息。 / I confirmed that commits, logs, and fixtures contain no sensitive data.
如适用,我已说明兼容性或数据迁移影响。 / Where applicable, I documented compatibility or data-migration impact.
Gemini placeholder signatures are no longer treated as upstream signatures,
and signature-like blocks outside the positions responses record are
redacted as ordinary upstream-authored content.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
JSON 遍历现在传递当前字段名,并将其用于签名位置识别。签名识别限定于指定的 content、reasoning_details、tool_calls 和 parts 结构,并排除两种占位签名。测试覆盖协议签名保留、占位签名处理,以及非协议位置相似内容的脱敏。
Merge Risk: Moderate · up to 64302
The PR narrows signature recognition, but a signature-shaped "parts" object under a non-protocol field such as "extra" can still skip redaction and send its text unchanged. A smaller gap remains for placeholder signatures that were previously wrapped into gateway records. Fix the parent-context check before merging; the placeholder gap is a lower-priority follow-up.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
标题“fix(redaction): recognize signatures only at protocol positions”与变更内容一致。变更将签名识别限制在协议位置,并排除 Gemini 占位签名。标题简洁、具体,能说明主要变更。
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: QUIET
Plan: Advanced
Run ID: 06098e23-1c39-4ee4-b058-de228bcc0e6d
Commits
Reviewing files that changed from the base of the PR and between 6562e38 and 6430274.
Files selected for processing: 3
internal/requestredact/redact.go
internal/requestredact/signature.go
internal/requestredact/signature_test.go
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
Recognize signed blocks only in the content, parts, reasoning_details, and
tool_calls arrays held directly by a model message or reasoning item, so
same-named arrays nested deeper are redacted as ordinary content.
Re the placeholder note in the CodeRabbit review (wrapped placeholder signatures taking the exact-match branch): not changing this. The exact-match branch only fires when every string in the block matches the gateway's record, and it sends back the upstream's own original bytes (restored spans are swapped back to ciphertext), so no plaintext reaches the upstream. The placeholder rule only targets unrecorded content, where there is no such proof that the block is unmodified upstream output.
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
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.
关联 Issue / Related Issue
None. Hardens signed-content handling in request redaction.
变更内容 / Change Content
Request redaction sends signed upstream content back unchanged when its signature carries no gateway record, so the upstream receives the exact bytes it signed. That rule assumes such content is unmodified upstream output. Two cases broke the assumption and let plaintext through:
skip_thought_signature_validatororcontext_engineering_is_the_way_to_go, the values Gemini documents for skipping signature validation. That content was never signed by the upstream and can hold plaintext the gateway restored earlier, yet it was forwarded unredacted. These values are no longer treated as signatures: the content is redacted like other upstream-authored history and the placeholder is kept.thinkingorreasoning.*block, or any object withfunction,thoughtSignature, orthought_signature), while responses only record signatures at protocol positions. Content the gateway restored elsewhere, such as Chatthinking_blocksfrom LiteLLM-style upstreams, came back without a record and was forwarded unredacted. The request side now recognizes a signature only where responses record one: elements of thecontent,parts,reasoning_details, andtool_callsarrays held directly by an assistant or model message or a reasoning item (Claude thinking and Responses reasoning text incontent, Gemini parts, reasoning details, and Gemini-compatible tool calls). Same-named arrays nested deeper, and everything else, are redacted as ordinary upstream-authored content.Signed content at protocol positions without a record is still sent unchanged, so fixed replacement and turns without restoration keep valid signatures.
Compatibility: no migration or API change. A signature-like block outside the protocol positions whose text matches a rule is now rewritten; if the upstream validates that signature, the request fails instead of sending plaintext.
Verification:
make checkpassed. New tests cover both placeholder values for Gemini parts (thoughtSignatureandthought_signature) and Gemini-compatible tool calls, and signature lookalikes in Chatthinking_blocks, Anthropic text blocks, Gemini parts, reasoning details, or tool calls placed incontent, same-namedpartsandcontentarrays nested under another field, and arrays nested insidecontent, in both replacement and encryption modes. The existing unrecorded-signature test now places each block at its real protocol position and adds Responses reasoning text. Gateway redaction and restore tests pass unchanged.自查清单 / Checklist
make check,或在说明中写明无法运行的原因和未验证范围。 / I ranmake check, or documented why it could not run and what remains unverified.