middleware

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(next http.Handler) http.Handler

CORS reflects the request Origin on the public OAuth/MCP surface (/oauth/*, /.well-known/*, /mcp) for browser-based public clients. Credentials are never allowed — Bearer JWT + PKCE secures these endpoints, so no credentialed-origin allowlist is kept (unlike hilo). Other paths get no CORS headers.

func MaxBytes

func MaxBytes(n int64) func(http.Handler) http.Handler

MaxBytes wraps r.Body in an http.MaxBytesReader so an oversized body fails at the ceiling instead of being fully buffered (or embedded on the /api path). Covers the /api JSON decode and /mcp streamable paths. n <= 0 disables the cap.

func RateLimit

func RateLimit(cfg RateLimitConfig) func(http.Handler) http.Handler

RateLimit is a token-bucket throttle keyed by the trusted client IP, reading rps/burst/proxy-depth live from cfg per request; rps <= 0 or a nil cfg disables it, and the limiter is rebuilt only when rps or burst change.

func SecurityHeaders

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders sets the CSP plus nosniff/no-referrer on every response. Outermost layer, so 429/413/OPTIONS responses carry them too; defence in depth behind the UI's DOMPurify — even a sanitizer bypass can't load an off-origin script.

Types

type RateLimitConfig added in v1.1.1

type RateLimitConfig interface {
	RateLimitRPS() float64
	RateLimitBurst() int
	TrustedProxyDepth() int
}

RateLimitConfig supplies the live rate-limit knobs, read per request so a config change applies without a restart. RPS <= 0 disables the throttle.

Jump to

Keyboard shortcuts

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