MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / guardedDialControl

Function guardedDialControl

internal/webhook/ssrf.go:38–51  ·  view source on GitHub ↗

guardedDialControl is a net.Dialer.Control hook that rejects a connection whose resolved address is a disallowed (private/loopback/link-local/…) IP. It runs AFTER DNS resolution with the concrete address the socket will connect to, so the IP that is validated is exactly the IP that is dialed — no re

(_, address string, _ syscall.RawConn)

Source from the content-addressed store, hash-verified

36// no resolve-then-re-resolve TOCTOU. This is the second line of defense the
37// registration-time check cannot provide once a hostname's DNS can change.
38func guardedDialControl(_, address string, _ syscall.RawConn) error {
39 host, _, err := net.SplitHostPort(address)
40 if err != nil {
41 return fmt.Errorf("webhook dial: bad address %q: %w", address, err)
42 }
43 ip := net.ParseIP(host)
44 if ip == nil {
45 return fmt.Errorf("webhook dial: unparseable resolved address %q", host)
46 }
47 if IsDisallowedWebhookIP(ip) {
48 return fmt.Errorf("webhook dial blocked: resolved to disallowed IP %s", ip)
49 }
50 return nil
51}

Callers 1

TestGuardedDialControlFunction · 0.85

Calls 1

IsDisallowedWebhookIPFunction · 0.85

Tested by 1

TestGuardedDialControlFunction · 0.68