Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: block CONNECT tunnels to private/reserved IP ranges - #23109

Merged
ssncferreira merged 4 commits into
mainfrom
ssncf/feat-block-private-ip
Mar 20, 2026
Merged

feat: block CONNECT tunnels to private/reserved IP ranges#23109
ssncferreira merged 4 commits into
mainfrom
ssncf/feat-block-private-ip

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Description

Blocks CONNECT tunnels to private and reserved IP ranges in aibridgeproxyd, preventing the proxy from being used to reach internal networks.

The Coder access URL is always exempt (hostname+port match) so the proxy can reach its own deployment. It is possible to exempt additional ranges via CODER_AIBRIDGE_PROXY_ALLOWED_PRIVATE_CIDRS.

DNS rebinding is handled differently per path:

  • Direct (no upstream proxy): validate the resolved IP right before the TCP dial, no window between check and connect.
  • Upstream proxy: Resolves and checks before forwarding to the upstream dialer. A small rebinding window exists since the upstream proxy re-resolves independently.

Changes

  • Add blocked IP denylist covering private, reserved, and special-purpose ranges
  • Add AllowedPrivateCIDRs option with CLI flag and env var
  • Wire IP checks into proxy.ConnectDial for both upstream and direct paths
  • Add tests for blocked/allowed cases across direct dial, upstream proxy, CIDR exemptions, and CoderAccessURL exemption

Notes: documentation will be handled in a follow-up PR.
Closes: https://github.com/coder/security/issues/124

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ssncferreira
ssncferreira force-pushed the ssncf/feat-block-private-ip branch 5 times, most recently from e57c496 to 9bc1dcb Compare March 17, 2026 12:15
@ssncferreira
ssncferreira marked this pull request as ready for review March 17, 2026 12:27
@coderagents

coderagents Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/ai-coder/ai-bridge/ai-bridge-proxy/setup.md - The Security Considerations → Restricting proxy access section currently states "Requests to non-allowlisted domains are tunneled through the proxy without restriction." This is no longer accurate. The section should be updated to:
    • Mention that private/reserved IP ranges are now blocked by default (SSRF protection)
    • Document the CODER_AIBRIDGE_PROXY_ALLOWED_PRIVATE_CIDRS / --aibridge-proxy-allowed-private-cidrs option for exempting specific internal CIDR ranges
    • Note that the Coder access URL is automatically exempt

Automated review via Coder Tasks

Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
Comment thread cli/testdata/coder_server_--help.golden
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd_test.go
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
return xerrors.Errorf("invalid resolved IP %q", resolvedIP)
}

if s.isBlockedIP(ip, host, port) {

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.

Nit: there's a bit of duplication with checkBlockedIP; these two funcs need to stay in-sync to ensure consistent behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only duplication here is the isBlockedIP check, the other logic is slightly different, so not sure if I can make create a helper function 😕

Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go
Comment thread enterprise/aibridgeproxyd/aibridgeproxyd.go

@jdomeracki-coder jdomeracki-coder 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.

Looking good!
Left some additional hardening comments

@dannykopping dannykopping 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.

LGTM!

@ssncferreira
ssncferreira force-pushed the ssncf/feat-block-private-ip branch from da66596 to 9b15f62 Compare March 19, 2026 13:54

@jdomeracki-coder jdomeracki-coder 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.

Approved ✅

One thing I'd like to verify experimentally is if this wouldn't break legitimate workloads attempting to communicate with the Cloud IMDS 🧪

@ssncferreira
ssncferreira merged commit 139594a into main Mar 20, 2026
32 of 33 checks passed
@ssncferreira
ssncferreira deleted the ssncf/feat-block-private-ip branch March 20, 2026 09:49
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants