ip4 (handlerutil/ssrf.go)

9router-go · internal/handlerutil/ssrf.go · go · MIT
infra, tag:knn-classified

Utility functions for parsing IPv4/IPv6 addresses and blocking private ranges in Go.

// Source: https://github.com/luqman-v1/9router-go | License: MIT | Copyright 2024-2026 decolua and contributors
// Provided via justclaw.it.com; keep this notice with the code.
package handlerutil

import (
	"context"
	"fmt"
	"net"
	"net/url"
	"regexp"
	"strconv"
	"strings"
)

// blockedHostnames are exact-match hostnames that are never allowed.
var blockedHostnames = map[string]bool{
	"localhost":     true,
	"ip6-localhost": true,
	"ip6-loopback":  true,
}

// blockedSuffixes are hostname suffixes that are never allowed.
var blockedSuffixes = []string{".internal", ".local", ".localhost"}

// blockedIPv4Ranges defines private/reserved IPv4 ranges in CIDR-like form.
// Each entry is (network_int, maskBits).
var blockedIPv4Ranges = []struct {
	network uint32
	mask    uint8
}{
	{ip4(0, 0, 0,

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key