Skip to content

Security Overview

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

Security Features Overview

FeatureDefaultDescription
Minimum TLS versionTLS 1.2Rejects TLS 1.0/1.1
SSRF protectionEnabledBlocks private IP connections
URL validationEnabledValidates URL format and protocol
Header validationEnabledPrevents CRLF injection
Strict Content-Length checkEnabledPrevents response smuggling
Cookie security validationOptionalValidates cookie security attributes
Response body size limit10MBPrevents memory exhaustion
Decompressed body size limit100MBPrevents decompression bombs
Redirect limit10Prevents 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 it to true in production.

SSRF Protection

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

go
// Default: block 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
}

// Security 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
::1/128IPv6 loopback
fc00::/7IPv6 unique local
fe80::/10IPv6 link-local

Header Validation

Automatically prevents CRLF injection and header smuggling:

go
// The following headers will be 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

// Restrict 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 sanitized (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}

Audit with Configuration

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