sandbox_network

package
v0.0.0-...-bb730e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	AllInternetTrafficCIDR = "0.0.0.0/0"

	DefaultNameserver = "8.8.8.8"
)

Variables

View Source
var DeniedSandboxCIDRs = []string{

	"10.0.0.0/8",
	"100.64.0.0/10",
	"127.0.0.0/8",
	"169.254.0.0/16",
	"172.16.0.0/12",
	"192.168.0.0/16",

	"::1/128",
	"fc00::/7",
	"fe80::/10",
}
View Source
var DevAllowedProxyEndpointCIDRs = func() []string {
	if !env.IsDevelopment() {
		return nil
	}

	return parseCIDRsEnv("BYOP_DEV_ALLOWED_PROXY_CIDRS")
}()

DevAllowedProxyEndpointCIDRs is a dev-only allowlist that overrides DeniedSandboxCIDRs at BYOP validation time. Populated from BYOP_DEV_ALLOWED_PROXY_CIDRS (comma-separated CIDRs) only when running in a development build; ignored in production so a stray env var cannot widen the BYOP endpoint allowlist.

View Source
var ErrEgressProxyInternalEndpoint = errors.New("egress proxy endpoint resolves to an internal / denied IP range")

ErrEgressProxyInternalEndpoint is returned when a configured BYOP endpoint resolves to an IP in DeniedSandboxCIDRs.

Functions

func AddressStringToCIDR

func AddressStringToCIDR(addressString string) string

AddressStringToCIDR converts a string address to the CIDR format. Supports only IPv4 addresses.

func AddressStringsToCIDRs

func AddressStringsToCIDRs(addressStrings []string) []string

AddressStringsToCIDRs converts a list of string addresses to the CIDR format. Supports only IPv4 addresses.

func DefaultHostResolver

func DefaultHostResolver(ctx context.Context, host string) ([]net.IP, error)

DefaultHostResolver uses net.DefaultResolver.LookupIPAddr and honors ctx.

func IsIPDevAllowedAsProxyEndpoint

func IsIPDevAllowedAsProxyEndpoint(ip net.IP) bool

IsIPDevAllowedAsProxyEndpoint reports whether ip falls into any CIDR in DevAllowedProxyEndpointCIDRs.

func IsIPInDeniedSandboxCIDRs

func IsIPInDeniedSandboxCIDRs(ip net.IP) bool

IsIPInDeniedSandboxCIDRs reports whether ip must be denied as a BYOP egress proxy endpoint: the unspecified addresses, "this network" block (0.0.0.0/8) or any IP in DeniedSandboxCIDRs. 0.0.0.0/8 is checked here because it cannot be encoded into the kernel nftables denylist.

func IsIPOrCIDR

func IsIPOrCIDR(s string) bool

IsIPOrCIDR checks if a string is a valid IP address or CIDR notation.

func IsSpecifiedIPOrCIDR

func IsSpecifiedIPOrCIDR(s string) bool

IsSpecifiedIPOrCIDR checks if a string is a valid IP address or CIDR notation with a specified (non-zero) IP. It rejects unspecified addresses like 0.0.0.0 or :: (which cause errors in nftables), but allows 0.0.0.0/0 as a special case.

func IsValidWildcardDomainPattern

func IsValidWildcardDomainPattern(pattern string) bool

IsValidWildcardDomainPattern reports whether pattern contains exactly one leading wildcard label followed by a DNS-1123 subdomain.

func MatchDomainPattern

func MatchDomainPattern(hostname, pattern string) bool

MatchDomainPattern reports whether hostname matches an exact domain, the all-domains wildcard, or a leading-label wildcard such as *.example.com.

func ParseAddressesAndDomains

func ParseAddressesAndDomains(entries []string) (addresses []string, domains []string)

ParseAddressesAndDomains separates a list of strings into IP addresses/CIDRs and domain names.

Types

type EgressProxyConfig

type EgressProxyConfig struct {
	Address  string
	Username string
	Password string
}

EgressProxyConfig is a transport-agnostic view of a BYOP SOCKS5 proxy configuration. Mirrors EgressProxy{Address,Username,Password} on db/pkg/types.SandboxNetworkEgressConfig.

func ValidateEgressProxy

func ValidateEgressProxy(ctx context.Context, cfg *EgressProxyConfig, resolve HostResolver) (*EgressProxyConfig, error)

ValidateEgressProxy checks a BYOP SOCKS5 config and rejects configurations that would expose E2B infrastructure or are malformed. On success it returns a canonical copy (host lower-cased, whitespace trimmed); the input is not mutated. cfg == nil returns (nil, nil). resolve defaults to DefaultHostResolver.

Rules:

  • Address must parse as "host:port" with a non-zero port.
  • Host must be an IP literal or resolve via the provided resolver.
  • Every resolved A/AAAA record must NOT be in DeniedSandboxCIDRs.
  • If Username == "" then Password must also be "" (no orphan password).
  • Username and Password are each capped at 255 bytes (RFC 1929).

type HostResolver

type HostResolver func(ctx context.Context, host string) ([]net.IP, error)

HostResolver resolves a hostname to one or more IPs. IP literals are returned without touching DNS. Implementations must honor ctx.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL