middleware

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserContextKey contextKey = "user"
)

Variables

This section is empty.

Functions

func CSRFMiddleware added in v1.6.1

func CSRFMiddleware(store *session.Store) func(http.Handler) http.Handler

CSRFMiddleware validates CSRF tokens on state-changing requests (POST, PUT, DELETE) Protects GOTH GUI forms from cross-site request forgery attacks CSRF token is read from X-CSRF-Token header or csrf_token form field

func GetClientIP

func GetClientIP(r *http.Request) string

GetClientIP extracts the real client IP address Exported for backward compatibility - delegates to netutil.GetClientIP Deprecated: Use netutil.GetClientIP directly for new code

func IPWhitelistMiddleware

func IPWhitelistMiddleware(cfg *config.Config) func(http.Handler) http.Handler

IPWhitelistMiddleware enforces IP-based access control SECURITY: Logs warning at startup if whitelist file is missing (all IPs will be denied)

func JWTAuthMiddleware

func JWTAuthMiddleware(cfg *config.Config) func(http.Handler) http.Handler

JWTAuthMiddleware validates JWT tokens The authService is created once and reused for all requests (performance optimization)

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

LoggingMiddleware logs all HTTP requests

func MaxBodySizeMiddleware added in v1.10.0

func MaxBodySizeMiddleware(maxBytes int64) func(http.Handler) http.Handler

MaxBodySizeMiddleware limits request body size to prevent memory exhaustion attacks Default limit is 1MB (1048576 bytes)

func SecurityHeadersMiddleware

func SecurityHeadersMiddleware(next http.Handler) http.Handler

SecurityHeadersMiddleware adds security headers to responses

func SessionAuthMiddleware added in v1.0.27

func SessionAuthMiddleware(store *session.Store) func(http.Handler) http.Handler

SessionAuthMiddleware validates session tokens (replacement for JWT) Uses in-memory session store for token validation Maintains backward compatibility by putting *auth.Claims in context

Types

type RateLimiter added in v1.10.0

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter provides IP-based rate limiting for brute force protection

func NewRateLimiter added in v1.10.0

func NewRateLimiter(limit int, window time.Duration) *RateLimiter

NewRateLimiter creates a new rate limiter with the specified limit and time window limit: maximum number of requests allowed per IP within the window window: time duration for the sliding window

func (*RateLimiter) Allow added in v1.10.0

func (rl *RateLimiter) Allow(ip string) bool

Allow checks if the given IP is allowed to make a request Returns true if the request is allowed, false if rate limit exceeded

func (*RateLimiter) GetAttemptCount added in v1.10.0

func (rl *RateLimiter) GetAttemptCount(ip string) int

GetAttemptCount returns the current number of attempts for an IP (for monitoring)

func (*RateLimiter) Middleware added in v1.10.0

func (rl *RateLimiter) Middleware(next http.Handler) http.Handler

Middleware returns HTTP middleware that rate limits requests by client IP When rate limit is exceeded, returns 429 Too Many Requests

func (*RateLimiter) MiddlewareFunc added in v1.10.0

func (rl *RateLimiter) MiddlewareFunc(next http.Handler) http.Handler

MiddlewareFunc returns HTTP middleware function for use with gorilla/mux This is compatible with mux.MiddlewareFunc signature

func (*RateLimiter) Reset added in v1.10.0

func (rl *RateLimiter) Reset(ip string)

Reset clears all rate limit data for an IP (e.g., after successful login)

func (*RateLimiter) WrapHandler added in v1.10.0

func (rl *RateLimiter) WrapHandler(handler http.HandlerFunc) http.HandlerFunc

WrapHandler wraps a single http.HandlerFunc with rate limiting Useful for applying rate limiting to specific routes without subrouters

Jump to

Keyboard shortcuts

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