middleware

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 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(rps float64, burst, trustedProxyDepth int) func(http.Handler) http.Handler

RateLimit is a token-bucket throttle keyed by the trusted client IP. rps is the sustained refill rate, burst the bucket size; over-limit requests get 429 + Retry-After. Probes are exempt. trustedProxyDepth controls X-Forwarded-For handling (see clientIP): 0 trusts none and keys on RemoteAddr. Outer abuse control over the auth/write surfaces; reads share the same bucket as defence in depth.

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

This section is empty.

Jump to

Keyboard shortcuts

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