Skip to content

fix(proxy): strip OpenRouter hop-by-hop request headers#1898

Open
yovinchen wants to merge 5 commits into
mainfrom
codex/issue-1888-interception-matrix
Open

fix(proxy): strip OpenRouter hop-by-hop request headers#1898
yovinchen wants to merge 5 commits into
mainfrom
codex/issue-1888-interception-matrix

Conversation

@yovinchen
Copy link
Copy Markdown
Collaborator

@yovinchen yovinchen commented Apr 5, 2026

Summary

  • strip hop-by-hop request headers only for Codex requests routed to OpenRouter chat/responses endpoints
  • keep Claude official messages requests unchanged and leave response-side behavior out of this patch
  • add focused unit coverage for the OpenRouter guard and dynamic Connection token stripping

Testing

  • cargo test --manifest-path src-tauri/Cargo.toml should_guard_openrouter_codex_headers_only_for_openrouter_chat_and_responses
  • cargo test --manifest-path src-tauri/Cargo.toml should_strip_openrouter_codex_request_header_covers_static_and_dynamic_hop_by_hop_headers
  • cargo test --manifest-path src-tauri/Cargo.toml rewrite_claude_transform_endpoint_strips_beta_for_chat_completions
  • cargo clippy --manifest-path src-tauri/Cargo.toml --lib -- -W clippy::too_many_arguments

Closes #1888
Closes #1913

Scope the guard to Codex OpenRouter chat/responses requests only.

Refs #1888
@yovinchen
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@farion1231
Copy link
Copy Markdown
Owner

Hi, I owe you an apology for the long silence. As the sole maintainer of this project, I've been overwhelmed and fell behind on reviews — but that's on me, not on you. Your contribution matters and I will review this PR. If it needs a rebase, just let me know or I can handle it. Thank you for your time and patience.

@yovinchen
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The issue-1888 branch only stripped hop-by-hop headers for Codex requests hitting a narrow set of OpenRouter endpoints. That left Claude-compatible paths and custom-domain OpenRouter relays forwarding Connection-derived headers.

The forwarder now treats any OpenRouter provider as eligible, keyed by providerType with openrouter.ai as a backward-compatible fallback, and keeps the helper coverage focused on both static and dynamic header names.

Constraint: Existing issue-1888 logic already depended on forwarder-side header rewriting
Rejected: Endpoint-specific allowlist | still misses Claude-compatible and custom-domain OpenRouter routes
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep providerType-based OpenRouter matching ahead of hostname heuristics when this path evolves
Tested: cargo test --manifest-path src-tauri/Cargo.toml forwarder::tests
Tested: cargo clippy --manifest-path src-tauri/Cargo.toml --lib -- -W clippy::too_many_arguments
Not-tested: Live request against a custom-domain OpenRouter relay
Copy link
Copy Markdown
Owner

@farion1231 farion1231 left a comment

Choose a reason for hiding this comment

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

P1
动态剥离后又补回 anthropic-beta
在 OpenRouter 的 Claude-compatible 路径里,如果客户端发送 Connection: anthropic-beta 和 anthropic-beta: context-management-2025-06-27,这里的动态 token 逻辑会跳过原始 anthropic-beta,但 saw_anthropic_beta 仍是 false;后面的补头逻辑又会把预计算的 anthropic_beta_value 追加回去。结果 OpenRouter 仍会收到 context-management-*,#1888/#1913 的失败路径没有被真正消除。建议在动态 token 命中 anthropic-beta 时抑制或过滤 anthropic_beta_value,并加一个覆盖 Connection: anthropic-beta 的单测。

P2
自定义域 OpenRouter 没有实际写入 providerType
这个 helper 只有在 meta.providerType 已经是 openrouter,或 base_url 包含 openrouter.ai 时才启用。PR 的测试覆盖了 relay.example + providerType=openrouter,但前端 OpenRouter 预设没有写入 providerType,类型也只允许 github_copilot/codex_oauth;用户把 OpenRouter 改成自定义中转域名后 meta.providerType 通常仍为空,base_url fallback 也失效,动态 hop-by-hop 头仍会泄露。需要给 OpenRouter 预设和保存路径写入 openrouter,或换一个能识别 OpenRouter relay 的持久标记。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants