Skip to content

Security Overview

HTTPC is secure by default -- all security features work out of the box.

Security Feature Overview

FeatureDefaultDescription
TLS minimum versionTLS 1.2Rejects TLS 1.0/1.1
SSRF protectionOnBlocks private IP connections
URL validationOnValidates URL format and protocol
Header validationOnPrevents CRLF injection
Content-Length strict checkingOnPrevents response smuggling
Cookie security validationOptionalValidates cookie security attributes
Response body size limit10MBPrevents memory exhaustion
Decompressed body size limit100MBPrevents decompression bombs
Redirect limit10 timesPrevents infinite redirects

TLS Security

go
cfg := httpc.DefaultConfig()
// Default TLS 1.2-1.3
cfg.Security.MinTLSVersion = tls.VersionTLS12
cfg.Security.MaxTLSVersion = tls.VersionTLS13

DANGER

InsecureSkipVerify is for testing only. Never set to true in production.

SSRF Protection

SSRF (Server-Side Request Forgery) is an attack where an attacker uses the server to make internal network requests.

go
// Default: blocks private IPs
cfg := httpc.DefaultConfig()
// AllowPrivateIPs = false -> blocks 127.0.0.1, 10.x, 192.168.x, etc.

// Exempt specific CIDRs (e.g. VPN, VPC)
cfg.Security.SSRFExemptCIDRs = []string{
    "10.0.0.0/8",       // VPC internal
    "100.64.0.0/10",    // Tailscale
}

// Secure preset: strongest SSRF protection
client, _ := httpc.New(httpc.SecureConfig())

Blocked IP Ranges

RangeDescription
127.0.0.0/8Loopback address
10.0.0.0/8Class A private
172.16.0.0/12Class B private
192.168.0.0/16Class C private
169.254.0.0/16Link-local
100.64.0.0/10CGNAT (includes Alibaba Cloud metadata 100.100.100.200)
240.0.0.0/4Class E reserved
::1/128IPv6 loopback
fc00::/7IPv6 unique local
fe80::/10IPv6 link-local

The table above lists the main ranges; for the full list (including 0.0.0.0/8, TEST-NET, the IPv6 documentation prefix 2001:db8::/32, NAT64 64:ff9b::/96, etc.) see the source isPrivateOrReservedIP.

Header Validation

Automatically prevents CRLF injection and header smuggling:

go
// The following headers are rejected
httpc.WithHeader("X-Custom", "value\r\nInjected: header") // CRLF injection
httpc.WithHeader("X-Bad", "value\x00null")                // Control characters
go
// Strict cookie security
cfg := httpc.DefaultConfig()
cfg.Security.CookieSecurity = httpc.StrictCookieSecurityConfig()
// Requires: Secure, HttpOnly, SameSite=Strict

Redirect Security

go
// Disable redirects (security-sensitive scenarios)
cfg := httpc.SecureConfig() // FollowRedirects = false

// Limit redirect domains
cfg := httpc.DefaultConfig()
cfg.Security.RedirectWhitelist = []string{
    "api.example.com",
    "auth.example.com",
}

Audit Middleware

go
auditMiddleware := httpc.AuditMiddleware(func(event httpc.AuditEvent) {
    // URL is masked (credentials removed)
    log.Printf("[AUDIT] %s %s -> %d (%v)",
        event.Method, event.URL, event.StatusCode, event.Duration)
})

cfg := httpc.DefaultConfig()
cfg.Middleware.Middlewares = []httpc.MiddlewareFunc{auditMiddleware}

Configurable Audit

go
auditCfg := &httpc.AuditMiddlewareConfig{
    Format:         "json",
    IncludeHeaders: true,
    MaskHeaders:    []string{"Authorization", "Cookie"},
    SanitizeError:  true,
}
auditMiddleware := httpc.AuditMiddlewareWithConfig(func(event httpc.AuditEvent) {
    data, _ := json.Marshal(event)
    log.Println(string(data))
}, auditCfg)

Next Steps