Skip to content

fix(redaction): recognize signatures only at protocol positions - #983

Merged
tbphp merged 3 commits into
mainfrom
claude/ghsa-5xr7-w8hc-xgwx-check-f98ac5
Nov 18, 2026
Merged

tbphp merged 3 commits into
mainfrom
claude/ghsa-5xr7-w8hc-xgwx-check-f98ac5

Conversation

@tbphp

@tbphp tbphp commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

关联 Issue / Related Issue

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.
Copilot AI balanced review requested due to automatic review settings November 18, 2026 01:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T01:59:27.559103Z 4e8c531 New commits
🔒 Security Review ✅ Completed 2026-11-18T02:01:20.441441Z 4e8c531 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tbphp tbphp self-assigned this Nov 18, 2026
@tbphp tbphp added the bug Something isn't working label Nov 18, 2026
@tbphp tbphp added this to the v2.0.0 milestone Nov 18, 2026
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

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: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(redaction): recognize signatures only at protocol positions”与变更内容一致。变更将签名识别限制在协议位置,并排除 Gemini 占位签名。标题简洁、具体,能说明主要变更。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed PR 描述基本完整。已填写关联项(说明为 None,并概述目的)、变更类型(Bug 修复)、详细变更内容、验证方式(make check 已通过并列出新增测试)以及兼容性影响说明。自查清单中有两项未勾选:未更新公开文档或发布说明,以及 PR 中未说明该项为何不适用。这些属于非关键项,不影响判断。关键信息足以理解变更范围、风险和验证情况。

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Other comments: 1

internal/requestredact/signature.go: 1

351-351: Minor · Security & Privacy · Quick win

包装后的占位签名仍会进入精确还原分支。

signaturePosition 只检查包装后的字符串。包装串不等于占位值,因此占位检查不生效。响应侧 signPayload 也不过滤占位值,会把非空占位签名包装进还原记录。

上游返回占位签名时,下一轮请求的签名块若与记录完全一致,就走精确还原分支。此时上游原文和原签名原样回传,正文不加密。这与 PR 的意图不一致:占位内容应与其他上游历史一样脱敏。

请在解包后检查 record.Signature。若它是占位值,应跳过精确还原分支,把占位值作为未记录的签名处理,并按普通上游内容加密正文。同时增加回归测试:上游返回包装占位签名,回放请求时正文应被加密。

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • 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.

Comment thread internal/requestredact/redact.go Resolved
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.
@tbphp

tbphp commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

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.

@tbphp
tbphp merged commit ca9e0e7 into main Nov 18, 2026
12 checks passed
@tbphp
tbphp deleted the claude/ghsa-5xr7-w8hc-xgwx-check-f98ac5 branch November 18, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants