Documentation
¶
Index ¶
- func CSRFProtection(exemptPaths []string) func(http.Handler) http.Handler
- func ClientIP(next http.Handler) http.Handler
- func ExemptFromCSRF(paths []string) func(http.Handler) http.Handler
- func GetCSPNonce(r *http.Request) string
- func GetClientIP(r *http.Request) string
- func NewCORS() func(http.Handler) http.Handler
- func RateLimit() func(http.Handler) http.Handler
- func RateLimitByEndpoint(requests int, window time.Duration) func(http.Handler) http.Handler
- func RateLimitByKey(requests int, window time.Duration, keyFunc httprate.KeyFunc) func(http.Handler) http.Handler
- func RedisRateLimitMiddleware(client *redis.Client) func(http.Handler) http.Handler
- func SecurityHeaders() func(http.Handler) http.Handler
- func SecurityHeadersWithNonce() func(http.Handler) http.Handler
- func SessionRefresh(db *sql.DB) func(http.Handler) http.Handler
- type RateLimitConfig
- type RedisRateLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CSRFProtection ¶
CSRFProtection returns a CSRF protection middleware using gorilla/csrf Paths in exemptPaths are excluded from CSRF checks (exact path match, not prefix)
func ClientIP ¶ added in v0.44.18
ClientIP extracts the real client IP, trusting X-Forwarded-For only from localhost (Caddy proxy)
func ExemptFromCSRF ¶
ExemptFromCSRF is kept for backwards compatibility but not used Use CSRFProtection(exemptPaths) instead
func GetCSPNonce ¶ added in v0.44.18
GetCSPNonce retrieves the CSP nonce from the request context. Returns an empty string if no nonce is found (e.g., middleware not applied).
func GetClientIP ¶ added in v0.44.18
GetClientIP retrieves client IP from request context
func RateLimitByEndpoint ¶
RateLimitByEndpoint returns middleware that rate limits per endpoint
func RateLimitByKey ¶
func RateLimitByKey(requests int, window time.Duration, keyFunc httprate.KeyFunc) func(http.Handler) http.Handler
RateLimitByKey returns middleware that rate limits using custom key function
func SecurityHeaders ¶
SecurityHeaders returns a middleware that sets comprehensive security headers. It configures headers for clickjacking protection, XSS protection, CSP with nonce, referrer policy, permissions policy, HSTS (production only), and removes fingerprinting headers like Server and X-Powered-By.
func SecurityHeadersWithNonce ¶ added in v0.44.18
SecurityHeadersWithNonce returns a middleware that sets security headers including a randomly generated CSP nonce stored in the request context.
Types ¶
type RateLimitConfig ¶
RateLimitConfig defines rate limit parameters
type RedisRateLimiter ¶
type RedisRateLimiter struct {
// contains filtered or unexported fields
}
func NewRedisRateLimiter ¶
func NewRedisRateLimiter(client *redis.Client) *RedisRateLimiter