Skip to content

fix(claude): bind proxy admission tokens to local destinations - #1360

Merged
Wibias merged 3 commits into
lidge-jun:devfrom
luvs01:agent/fix-claude-admission-token-boundary
Aug 10, 2026
Merged

fix(claude): bind proxy admission tokens to local destinations#1360
Wibias merged 3 commits into
lidge-jun:devfrom
luvs01:agent/fix-claude-admission-token-boundary

Conversation

@luvs01

@luvs01 luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Inject OpenCodex admission credentials only when Claude Code is targeting the running local HTTP proxy.
  • Remove inherited proxy-owned credentials from both Anthropic credential slots before an external gateway launch, while preserving user-owned API keys and auth tokens.
  • Reuse the shared proxy-admission-secret classifier so current, rotated generated, environment, management, session, and legacy proxy tokens follow the same no-forward contract.
  • Normalize stale IPv4, localhost, and IPv6 loopback destinations to the running proxy port and add focused destination/ownership regressions.

This keeps external gateway overrides supported without allowing OpenCodex-owned admission credentials or the proxy marker to follow them.

Verification

  • bun test tests/claude-auth-mode.test.ts tests/claude-cli.test.ts — 62 passed, 0 failed on Bun 1.3.14.
  • bun run typecheck — passed.
  • bun run privacy:scan — passed.
  • git diff --check — passed.
  • Independent final diff review found no actionable P0–P3 findings.
  • A repository-wide run was stopped after unrelated existing API-key persistence and usage-cache tests failed or timed out on Windows; no changed-path failure was observed.

Checklist

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

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • 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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved proxy detection for localhost and loopback addresses, including IPv4, IPv6, trailing dots, and default ports.
    • Prevented credentials from being sent to untrusted or malformed proxy destinations.
    • Preserved user-provided API keys when connecting to external gateways.
    • Removed stale authentication markers and restricted local admission tokens to trusted proxy connections.
    • Improved handling of proxy authentication across HTTP and HTTPS connections.
    • Prevented sensitive credentials from leaking when proxy destinations are unexpectedly redirected or replaced.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d77e4dd2-adde-452a-a386-1794a9e07d4b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Claude proxy authentication now recognizes normalized loopback URLs, removes stale proxy markers, separates user credentials from admission secrets, and limits admission-token and host-assertion injection to eligible local proxy targets.

Changes

Claude proxy authentication

Layer / File(s) Summary
Proxy target detection and stale-marker cleanup
src/cli/claude.ts, tests/claude-auth-mode.test.ts
src/cli/claude.ts:38-60 validates credential-free HTTP Anthropic URLs for localhost and IPv4/IPv6 loopback hosts, normalized trailing dots, default ports, and malformed URLs. src/cli/claude.ts:81,122-127 removes stale markers, replaces stale local proxy URLs, and sanitizes warning output. Tests cover whitespace-wrapped markers, IPv6 targets, default ports, and credential-free warnings.
Credential sanitization and authentication markers
src/cli/claude.ts, tests/claude-auth-mode.test.ts
src/cli/claude.ts:139-158,173-185,207 removes inherited admission secrets from external destinations, preserves user credentials, handles key rotation, and injects admission data or host-managed authentication only for local proxy targets without a user API key. Tests cover external gateways, credential precedence, token rotation, and API-key protection.

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

Sequence Diagram(s)

sequenceDiagram
  participant Claude
  participant ProxyValidator
  participant LocalProxy
  participant ExternalGateway
  Claude->>ProxyValidator: classify Anthropic base URL
  ProxyValidator-->>Claude: local or external target
  alt local proxy without user API key
    Claude->>LocalProxy: inject admission token and host marker
  else external gateway or user API key
    Claude->>ExternalGateway: preserve user credential without host marker
  end
Loading

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun, wibias

🚥 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 binding Claude proxy admission tokens to local destinations, which is the main change.
✨ 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 has been marked 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 notified: @lidge-jun @Ingwannu @Wibias

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-admission-token-boundary branch from a2360b9 to 2a33dbc Compare August 9, 2026 23:25
@Wibias
Wibias marked this pull request as ready for review August 9, 2026 23:45

@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: 2

🤖 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 `@src/cli/claude.ts`:
- Around line 151-155: Update the authentication handling around the
proxy-marker injection and host-managed assertion to derive a
hostOwnsAuthentication flag requiring a local proxy target, no user API key, and
either PROXY_MARKER or a proxy admission secret. Use this flag when setting
CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST instead of checking only for
ANTHROPIC_AUTH_TOKEN, and extend the external user-token coverage in
claude-auth-mode.test.ts to verify the host-managed assertion is absent.
- Around line 122-125: Update the stale URL replacement logging in the Claude
loopback handling to avoid logging raw existingBaseUrl; use parsed.origin or
omit the old destination while preserving the replacement message. Add a
regression test covering URL credentials and assert console.error does not
include them.
🪄 Autofix

❌ Autofix failed (check again to retry)

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: 3cf62c35-6b21-431e-a99b-5481002dcbd8

📥 Commits

Reviewing files that changed from the base of the PR and between d517161 and 2a33dbc.

📒 Files selected for processing (2)
  • src/cli/claude.ts
  • tests/claude-auth-mode.test.ts

Comment thread src/cli/claude.ts
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] Acknowledged. I will review the current PR head and validate the changes against the stated admission and credential-handling requirements.

⚠️ Action not completed

Already reviewed.

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 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions The PR gate reports that the PR is ready at head 2a33dbc22f4d8730fefe9340b2325b3b1ebef556. I will review the current head.

⚠️ Action not completed

Already reviewed.

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 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

An unexpected error occurred while generating fixes: Not Found - https://docs.github.com/rest/git/refs#get-a-reference

@luvs01
luvs01 force-pushed the agent/fix-claude-admission-token-boundary branch from 2a33dbc to e6e1bff Compare August 10, 2026 00:28
@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 26 minutes and 34 seconds before sending another message.

@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 00:29
@github-actions
github-actions Bot marked this pull request as ready for review August 10, 2026 00:29
@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 25 minutes and 41 seconds before sending another message.

@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 25 minutes and 29 seconds before sending another message.

@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 25 minutes and 19 seconds before sending another message.

@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 `@src/cli/claude.ts`:
- Around line 122-125: Update the loopback URL replacement branch around
isClaudeLoopbackHostname so it compares the active proxy port with the URL’s
effective port, treating an empty parsed.port as HTTP port 80, consistent with
targetsLocalClaudeProxy. Replace stale default-port loopback URLs such as
http://localhost when the proxy uses another port, and add a regression case in
claude-auth-mode.test.ts covering http://localhost with port 10100.
🪄 Autofix

❌ Autofix failed (check again to retry)

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: aedef045-9efd-4dc6-872c-7482d139e823

📥 Commits

Reviewing files that changed from the base of the PR and between 2a33dbc and e6e1bff.

📒 Files selected for processing (2)
  • src/cli/claude.ts
  • tests/claude-auth-mode.test.ts

Comment thread src/cli/claude.ts Outdated
@Wibias
Wibias marked this pull request as draft August 10, 2026 00:31
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

An unexpected error occurred while generating fixes: Not Found - https://docs.github.com/rest/git/refs#get-a-reference

@luvs01
luvs01 force-pushed the agent/fix-claude-admission-token-boundary branch from e6e1bff to c01de68 Compare August 10, 2026 01:11
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] Acknowledged. I will review the current PR head e6e1bff402962453e0ff950743837fe10676acf9.

✅ 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.

@Wibias
Wibias marked this pull request as ready for review August 10, 2026 01:17
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:19
@Wibias
Wibias marked this pull request as ready for review August 10, 2026 01:20
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:21
@Wibias
Wibias marked this pull request as ready for review August 10, 2026 01:21
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:21
@Wibias
Wibias marked this pull request as ready for review August 10, 2026 01:21
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:22
@github-actions
github-actions Bot marked this pull request as ready for review August 10, 2026 01:27
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The PR is marked ready at c01de68e58f29ef02f296eb04731faf7112265c3. I will review the current head.

⚠️ Action not completed

Already reviewed.

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.

@Wibias
Wibias merged commit f38d960 into lidge-jun:dev Aug 10, 2026
44 of 53 checks passed

Wibias commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks @luvs01! Great work tightening the Claude credential boundary and covering the tricky loopback/default-port cases. Appreciate the thorough review follow-up. 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