Skip to content

fix(claude): contain main credentials to canonical forward routes - #1358

Merged
Wibias merged 1 commit into
lidge-jun:devfrom
luvs01:agent/fix-claude-main-credential-boundary
Aug 10, 2026
Merged

fix(claude): contain main credentials to canonical forward routes#1358
Wibias merged 1 commit into
lidge-jun:devfrom
luvs01:agent/fix-claude-main-credential-boundary

Conversation

@luvs01

@luvs01 luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Keep Claude replay's optional main-account enrichment for canonical OpenAI routes and internal OpenAI sidecars.
  • Strip the internally injected bearer and account ID when the final resolved wire adapter is a noncanonical openai-responses forward destination.
  • Apply the boundary after shadow routing and model-level wire overrides, and add direct plus shadow/model-override regressions.

This keeps existing key/OAuth adapters and sidecar behavior intact while preventing an internal main-account credential from following a final custom forward route.

Verification

  • bun test tests/claude-messages-endpoint.test.ts -t 'custom forward|shadow-call' — 2 passed.
  • Canonical OpenAI positive control — 1 passed.
  • Routed OpenAI sidecar positive control — 1 passed.
  • bun run typecheck
  • bun run privacy:scan
  • git diff --check
  • Independent final diff review found no P0–P3 findings.
  • The whole endpoint file reached 37 passing tests; one existing 5-second lifecycle timeout and its following cleanup EBUSY reproduced on an unchanged dev control. Exact-head GitHub CI remains required.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were not needed for this internal routing boundary.
  • Security-sensitive changes require explicit maintainer security review.

Review readiness checklist

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Claude Messages replays now enable credential stripping for noncanonical OpenAI Responses forwards. Responses handling clears native authentication and Codex routing metadata. Tests cover direct custom forwarding and shadow-call rerouting.

Changes

Claude forward authentication

Layer / File(s) Summary
Conditional authentication stripping
src/server/responses/core.ts, src/server/claude-messages.ts
HandleResponsesOptions adds stripClaudeMainAuthForNoncanonicalForward at lines 634-639. Claude replay enables it at line 735. For noncanonical OpenAI Responses forwards, lines 1710-1727 release the Codex probe lease, reset authentication, remove runtime fields and credential headers, clear account routing metadata, and update the provider name.
Credential forwarding regression coverage
tests/claude-messages-endpoint.test.ts
Lines 689-739 test direct custom forwarding without authorization or chatgpt-account-id. Lines 741-802 test shadow-call rerouting with the same credential checks and a successful streamed response.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClaudeMessagesReplay
  participant HandleResponses
  participant AuthContext
  participant CustomOpenAIResponsesRoute
  ClaudeMessagesReplay->>HandleResponses: enable credential stripping
  HandleResponses->>AuthContext: reset auth and remove native headers and routing metadata
  HandleResponses->>CustomOpenAIResponsesRoute: forward request without main credentials
  CustomOpenAIResponsesRoute-->>ClaudeMessagesReplay: return streamed response
Loading

Possibly related PRs

  • lidge-jun/opencodex#626: Shares the Claude Messages replay and endpoint test areas but addresses cache-key and session-ID stabilization.
  • lidge-jun/opencodex#634: Shares the routed Claude Messages/OpenAI replay flow but addresses cache and session stabilization.

Suggested reviewers: wibias, lidge-jun, devmello

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing main credentials from reaching noncanonical Claude forward routes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently. If no CodeRabbit review appears, comment @coderabbitai review to request one.
Maintainers: @lidge-jun @Ingwannu @Wibias

@luvs01

luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/claude-messages-endpoint.test.ts`:
- Line 693: Remove the duplicate captured declarations within the test()
callbacks so each callback has only one declaration. Apply this at
tests/claude-messages-endpoint.test.ts lines 693-693 and 745-745, retaining the
single declaration needed by each test.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 018ae3a4-151b-40e8-a848-2e65bd069496

📥 Commits

Reviewing files that changed from the base of the PR and between 4f746d1 and cb1cb39.

📒 Files selected for processing (3)
  • src/server/claude-messages.ts
  • src/server/responses/core.ts
  • tests/claude-messages-endpoint.test.ts

Comment thread tests/claude-messages-endpoint.test.ts

Wibias commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Please rebase this PR onto the latest dev (e8ce2b93dd3ef8074d96dee407704c5dc06e2699) before merge, then rerun the exact-head CI checks.

@luvs01
luvs01 force-pushed the agent/fix-claude-main-credential-boundary branch from cb1cb39 to 9eaae1b Compare August 9, 2026 23:25
@Wibias
Wibias marked this pull request as ready for review August 9, 2026 23:45
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Rate Limit Exceeded

@github-actions[bot] have exceeded the limit for the number of chat messages per hour. Please wait 48 minutes and 25 seconds before sending another message.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="lidge-jun/opencodex"
pr_number="1358"
required_dev_sha="e8ce2b93dd3ef8074d96dee407704c5dc06e2699"

echo "== Pull request metadata =="
gh pr view "$pr_number" --repo "$repo" \
  --json number,state,isDraft,headRefName,headRefOid,baseRefName,baseRefOid,mergeStateStatus,statusCheckRollup \
  --jq '{
    number,
    state,
    isDraft,
    headRefName,
    headRefOid,
    baseRefName,
    baseRefOid,
    mergeStateStatus,
    checks: [.statusCheckRollup[]? | {
      name,
      status,
      conclusion,
      workflowName,
      startedAt,
      completedAt,
      detailsUrl
    }]
  }'

echo
echo "== Required dev commit =="
gh api "repos/$repo/commits/$required_dev_sha" \
  --jq '{sha, commit: {message: .commit.message, committer: .commit.committer}}'

echo
echo "== Is the required dev commit an ancestor of the exact PR head? =="
head_sha="$(gh pr view "$pr_number" --repo "$repo" --json headRefOid --jq '.headRefOid')"
comparison="$(gh api "repos/$repo/compare/$required_dev_sha...$head_sha")"
printf '%s\n' "$comparison" | jq '{
  status,
  ahead_by,
  behind_by,
  merge_base_commit: .merge_base_commit.sha
}'

echo
echo "== Check runs attached to the exact PR head =="
gh api "repos/$repo/commits/$head_sha/check-runs?per_page=100" \
  --jq '[.check_runs[] | {
    name,
    status,
    conclusion,
    started_at,
    completed_at,
    details_url
  }]'

Length of output: 19838


🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="lidge-jun/opencodex"
pr_number="1358"

head_sha="$(gh pr view "$pr_number" --repo "$repo" --json headRefOid --jq '.headRefOid')"
current_dev_sha="$(gh api "repos/$repo/git/ref/heads/dev" --jq '.object.sha')"

echo "== Current dev versus PR head =="
echo "current_dev_sha=$current_dev_sha"
echo "pr_head_sha=$head_sha"
gh api "repos/$repo/compare/$current_dev_sha...$head_sha" \
  --jq '{
    status,
    ahead_by,
    behind_by,
    merge_base_commit: .merge_base_commit.sha
  }'

Length of output: 907


@github-actions[bot] Verified for PR #1358.

  • PR head 9eaae1b22e5ab2115c97626284c13cbebd27f142 is 1 commit ahead and 0 commits behind current dev at d517161aeaa3a974ad3c0360ff0c97b03b4c4520.
  • It also contains the previously required dev commit e8ce2b93dd3ef8074d96dee407704c5dc06e2699.
  • The exact-head ci check succeeded.
  • The PR is open, not a draft, and GitHub reports merge state CLEAN.

The PR meets the stated rebase and exact-head CI requirements.

You are interacting with an AI system.

@Wibias
Wibias merged commit c2cc244 into lidge-jun:dev Aug 10, 2026
31 of 35 checks passed

Wibias commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks @luvs01 — really appreciate the careful credential-boundary hardening here, especially covering final-route overrides and shadow rerouting with regressions. Merged! 🙏

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

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants