fix(coderouter): pin the OpenCode provider address per request

Merged
LA
2mo ago
+200-10

The OpenCode proxy checked the provider hostname's addresses and then let fetch resolve the name again, so a DNS change between the two could send the provider credential to an internal address. The checked address is now pinned: resolveProviderURL returns the URL with that address, and the upstream request goes through pinnedFetch (node:http(s) with a lookup that returns only the pinned address). The hostname still sets the Host header, TLS SNI and certificate verification; request and response bodies stream, and cancellation still reaches the upstream.

Found by a Codex Security audit. Commit 1 adds the failing test, commit 2 the fix.

Verification: bun test tests/coderouter-opencode-proxy.test.ts (13 pass), bun run typecheck, eslint on the changed files (one pre-existing warning).

Changelog

Fixed: The OpenCode provider proxy connects only to the provider address it validated.

šŸ¤– Generated with Claude Code


Summary by cubic

Pins the OpenCode provider address per request so DNS changes can no longer redirect the provider credential to an internal address. resolveProviderURL now returns the URL pinned to the first validated address, and the upstream request goes through pinnedFetch (a node:http/https request whose lookup returns only that address), picked from the URL by pinnedFetchFor. The hostname still sets the Host header, TLS SNI, and certificate verification; response bodies are decompressed as fetch would, and a failed client body aborts the upstream request. Includes a regression test that verifies the proxy connects only to the pinned address even when the hostname does not resolve. Found by a Codex Security audit.

Verification: bun test tests/coderouter-opencode-proxy.test.ts (13 pass), bun run typecheck, eslint on the changed files (one pre-existing warning).

Summary by CodeRabbit

  • Bug Fixes
    • Provider requests now connect to a verified network address while preserving the provider’s hostname for request headers and secure connection checks. This helps ensure requests reach the address that was checked, even when the hostname cannot be resolved again during connection setup. Custom request handling continues to use the configured fetch method.