Skip to content

Fix bedrock DNS resolution when behind a corporate proxy#906

Open
LouisClt wants to merge 2 commits into
Zoo-Code-Org:mainfrom
LouisClt:fix_bedrock_proxy
Open

Fix bedrock DNS resolution when behind a corporate proxy#906
LouisClt wants to merge 2 commits into
Zoo-Code-Org:mainfrom
LouisClt:fix_bedrock_proxy

Conversation

@LouisClt

@LouisClt LouisClt commented Jul 16, 2026

Copy link
Copy Markdown

When behind a corporate proxy, Node.js resolves DNS locally before contacting the proxy. If the proxy is the only path to the endpoint, the request fails with ENOTFOUND.

HttpsProxyAgent uses CONNECT tunneling so the proxy handles DNS resolution. Configure NodeHttpHandler with HttpsProxyAgent when a system proxy is detected.

I had the need to use bedrock behind a corporate proxy, as there was no fix available, I made one so that I could use it, using Claude code. Here is a proposed PR if you want to merge it to the main branch ...
I reviewed the changes myself, and it seems to be good, but I am no typescript expert so ...

Related GitHub Issue

Closes: #905

Description

Node.js resolves DNS locally before contacting the proxy. When behind a corporate proxy that blocks external DNS, Bedrock calls fail with ENOTFOUND.

This configures NodeHttpHandler with HttpsProxyAgent in BedrockRuntimeClient, which uses CONNECT tunneling so the proxy handles DNS resolution.

Proxy is detected from HTTPS_PROXY/HTTP_PROXY env vars or VS Code http.proxy setting (which seems to be filled from the windows configured proxy).

Test Procedure

Test Procedure

  • Unit tests: pnpm test -- bedrock.spec → 102 passing
  • Windows: Configure proxy in Internet Options, restart VS Code → works automatically

Pre-Submission Checklist

Documentation Updates

[x] No documentation updates are required.

Additional Notes

VS Code automatically detects Windows system proxy, so this works transparently for users with proxy configured in Internet Options.

Get in Touch

I have no discord username for the moment.

Thanks

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Amazon Bedrock connectivity issues when running behind a corporate HTTPS proxy, including improved DNS/proxy resolution.
    • Bedrock now automatically detects proxy settings from environment variables or VS Code configuration and routes requests through the configured proxy.
    • Proxy behavior remains correct when API key authentication is enabled.
  • Tests
    • Added coverage to verify proxy configuration behavior for Bedrock requests.

When behind a corporate proxy, Node.js resolves DNS locally before contacting
the proxy. If the proxy is the only path to the endpoint, the request fails
with ENOTFOUND.

HttpsProxyAgent uses CONNECT tunneling so the proxy handles DNS resolution.
Configure NodeHttpHandler with HttpsProxyAgent when a system proxy is detected.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Bedrock now resolves proxy settings from environment variables or VS Code configuration and routes AWS requests through an HTTPS proxy agent when configured. Tests cover proxied, direct, and API-key authentication scenarios, with dependencies and a patch changeset added.

Changes

Bedrock proxy routing

Layer / File(s) Summary
System proxy discovery
src/utils/networkProxy.ts
Adds getSystemProxyUrl() with HTTPS/HTTP environment-variable precedence, VS Code http.proxy fallback, and failure handling.
Bedrock request-handler integration
src/api/providers/bedrock.ts, src/api/providers/__tests__/bedrock.spec.ts, src/package.json, .changeset/itchy-moles-thank.md
Configures NodeHttpHandler and HttpsProxyAgent when a proxy is available, validates proxy and non-proxy behavior, and declares the required dependencies and patch release.

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

Sequence Diagram(s)

sequenceDiagram
  participant AwsBedrockHandler
  participant getSystemProxyUrl
  participant HttpsProxyAgent
  participant NodeHttpHandler
  participant BedrockRuntimeClient
  AwsBedrockHandler->>getSystemProxyUrl: Resolve system proxy URL
  getSystemProxyUrl-->>AwsBedrockHandler: Return URL or undefined
  AwsBedrockHandler->>HttpsProxyAgent: Create proxy agent
  AwsBedrockHandler->>NodeHttpHandler: Create request handler
  AwsBedrockHandler->>BedrockRuntimeClient: Set requestHandler
Loading

Suggested reviewers: edelauna

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main fix: Bedrock DNS resolution behind a corporate proxy.
Description check ✅ Passed The PR description includes the linked issue, implementation summary, testing notes, checklist, and other required sections.
Linked Issues check ✅ Passed The changes implement proxy detection, proxy-enabled Bedrock HTTP handling, and tests, matching issue #905's expected fix.
Out of Scope Changes check ✅ Passed The changes stay focused on Bedrock proxy support, with only supporting tests, dependency updates, and a release note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@LouisClt LouisClt force-pushed the fix_bedrock_proxy branch from ad39470 to 204a5da Compare July 16, 2026 10: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: 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/utils/networkProxy.ts`:
- Around line 354-360: Update the environment proxy selection in the surrounding
proxy-resolution function to trim the chosen
HTTPS_PROXY/https_proxy/HTTP_PROXY/http_proxy value before returning it, and
treat the trimmed result as unset when blank so resolution can continue to the
fallback path. Preserve the existing HTTPS-over-HTTP precedence.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6711a1da-2a4c-48ec-a911-3f1c9a030d08

📥 Commits

Reviewing files that changed from the base of the PR and between ad39470 and 204a5da.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .changeset/itchy-moles-thank.md
  • src/api/providers/__tests__/bedrock.spec.ts
  • src/api/providers/bedrock.ts
  • src/package.json
  • src/utils/networkProxy.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • .changeset/itchy-moles-thank.md
  • src/package.json
  • src/api/providers/bedrock.ts
  • src/api/providers/tests/bedrock.spec.ts

Comment thread src/utils/networkProxy.ts
Comment on lines +354 to +360
// Standard proxy environment variables (HTTPS takes precedence over HTTP)
const fromEnv =
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy
if (fromEnv) return fromEnv

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Trim environment proxy values before returning them.

Unlike the VS Code fallback, environment values are not trimmed. A whitespace-only HTTPS_PROXY/HTTP_PROXY value is truthy and will be passed to HttpsProxyAgent as an invalid proxy URL, preventing Bedrock client initialization. Normalize the selected environment value and treat blank values as unset.

Proposed fix
-	const fromEnv =
+	const fromEnv = (
 		process.env.HTTPS_PROXY ||
 		process.env.https_proxy ||
 		process.env.HTTP_PROXY ||
 		process.env.http_proxy
-	if (fromEnv) return fromEnv
+	)?.trim()
+	if (fromEnv) return fromEnv
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Standard proxy environment variables (HTTPS takes precedence over HTTP)
const fromEnv =
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy
if (fromEnv) return fromEnv
// Standard proxy environment variables (HTTPS takes precedence over HTTP)
const fromEnv = (
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy
)?.trim()
if (fromEnv) return fromEnv
🤖 Prompt for 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.

In `@src/utils/networkProxy.ts` around lines 354 - 360, Update the environment
proxy selection in the surrounding proxy-resolution function to trim the chosen
HTTPS_PROXY/https_proxy/HTTP_PROXY/http_proxy value before returning it, and
treat the trimmed result as unset when blank so resolution can continue to the
fallback path. Preserve the existing HTTPS-over-HTTP precedence.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/utils/networkProxy.ts 66.66% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bedrock provider does not work behind a proxy

1 participant