Skip to content

fix(dialer): enforce IP block list before socket creation#124

Closed
yeikel wants to merge 0 commit into
dependabot:mainfrom
yeikel:patch-1
Closed

fix(dialer): enforce IP block list before socket creation#124
yeikel wants to merge 0 commit into
dependabot:mainfrom
yeikel:patch-1

Conversation

@yeikel
Copy link
Copy Markdown

@yeikel yeikel commented May 14, 2026

What are you trying to accomplish?

The blocked-IP check in safeControl runs after the OS creates the socket. On systems where a network family is unsupported (e.g. IPv6 disabled), socket creation fails first with "address family not supported by protocol" safeControl is never reached, so ErrForbiddenRequest is never returned and handleForbidden can't produce a 403.

Fix by checking resolved IPs against the block list inside DialContext, before net.Dialer.DialContext is called. safeControl is kept as a defence-in-depth fallback for any path that bypasses DialContext.

Fixes TestIPRestrictions/http://[::1]/ on CI runners without IPv6.

Anything you want to highlight for special attention from reviewers?

This only happens on self hosted runners that do not support IPv6 so it is difficult to provide a reproducer or test here

How will you know you've accomplished your goal?

Hosts without IPV6 support continue to work

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@yeikel yeikel marked this pull request as ready for review May 14, 2026 22:48
@yeikel yeikel requested a review from a team as a code owner May 14, 2026 22:48
@JamieMagee JamieMagee requested a review from Copilot June 3, 2026 16:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the proxy’s custom internal/dialer.Dialer to enforce the blocked-IP list before attempting to create a socket, so requests to blocked addresses (notably ::1 on hosts without IPv6 support) reliably surface as ErrForbiddenRequest and can be converted into an HTTP 403 by the proxy’s forbidden handler.

Changes:

  • Persist the blocked IP list on the Dialer instance.
  • Add a pre-dial check in DialContext to compare resolved IPs against the blocked list before calling into net.Dialer.DialContext.
Show a summary per file
File Description
internal/dialer/dialer.go Adds blocked IP storage on the dialer and performs blocked-IP checks prior to dialing to ensure forbidden requests are detected even when socket creation would fail first.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread internal/dialer/dialer.go Outdated
Comment on lines +55 to +59
parsed := net.ParseIP(ip)
for _, blocked := range d.blockedIPs {
if parsed != nil && parsed.Equal(blocked) {
return nil, ErrForbiddenRequest
}
@yeikel
Copy link
Copy Markdown
Author

yeikel commented Jun 3, 2026

I just noticed that there are some test failures but these failures are just related to dependabot/smoke-tests#277

@yeikel
Copy link
Copy Markdown
Author

yeikel commented Jun 3, 2026

I re-generated the tests here dependabot/smoke-tests#522

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants