validator

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 8 Imported by: 0

README

🛡️ Validator Module (internal/validator)

internal/validator provides security validation utilities for the PingGopher runtime engine, with primary emphasis on Server-Side Request Forgery (SSRF) prevention.


🎯 Security Features

  1. URL Protocol Scheme Enforcer: Only permits http:// and https:// target URL schemes. Protocols such as file://, gopher://, dict://, and ftp:// are rejected.

  2. CIDR Blocklist Validation: Validates hostname resolutions against private RFC 1918 networks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), loopback (127.0.0.0/8, ::1/128), link-local (169.254.0.0/16, fe80::/10), and cloud provider Instance Metadata Service (IMDS) endpoints (169.254.169.254).

  3. IPv4-Mapped IPv6 Normalization: Normalizes IPv4-mapped IPv6 addresses (::ffff:169.254.169.254) via ip.To4() prior to CIDR evaluation.

  4. Connect-Time Socket Dialer (SafeDialContext): Provides validator.SafeDialContext(timeout) for HTTP transports and TLS dialers to re-verify resolved target IP addresses at TCP socket creation time, protecting against DNS TTL=0 TOCTOU rebinding attacks.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidScheme   = errors.New("invalid URL scheme: only http and https are permitted")
	ErrEmptyHost       = errors.New("invalid URL: missing host")
	ErrSSRFForbiddenIP = errors.New("prohibited target IP address: private, loopback, or cloud metadata endpoints are not allowed")
)

Functions

func SafeDialContext added in v0.3.0

func SafeDialContext(timeout time.Duration) func(ctx context.Context, network, addr string) (net.Conn, error)

SafeDialContext returns a custom DialContext function that resolves DNS and validates IP blocklists at connect time to prevent TOCTOU DNS rebinding SSRF attacks.

func ValidateSafeURL

func ValidateSafeURL(targetURL string) error

ValidateSafeURL checks if a target URL is safe for synthetic probing and protects against SSRF attacks.

Types

This section is empty.

Jump to

Keyboard shortcuts

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