da367a1bfd
security: harden against SAST findings (criticals through mediums)
...
Critical:
- Validate baseURL/sourceURL/upstreamURL at config load time
(prevents XML injection, XSS, SSRF via config/env manipulation)
- Use xml.Escape for OpenSearch XML template interpolation
High:
- Add security headers middleware (CSP, X-Frame-Options, HSTS, etc.)
- Sanitize result URLs to reject javascript:/data: schemes
- Sanitize infobox img_src against dangerous URL schemes
- Default CORS to deny-all (was wildcard *)
Medium:
- Rate limiter: X-Forwarded-For only trusted from configured proxies
- Validate engine names against known registry allowlist
- Add 1024-char max query length
- Sanitize upstream error messages (strip raw response bodies)
- Upstream client validates URL scheme (http/https only)
Test updates:
- Update extractIP tests for new trusted proxy behavior
2026-03-22 16:22:27 +00:00
13040268d6
feat: add global and burst rate limiters
...
Three layers of rate limiting, all disabled by default, opt-in via config:
1. Per-IP (existing): 30 req/min per IP
2. Global: server-wide limit across all IPs
- Lock-free atomic counter for minimal overhead
- Returns 503 when exceeded
- Prevents pool exhaustion from distributed attacks
3. Burst: per-IP burst + sustained windows
- Blocks rapid-fire abuse within seconds
- Returns 429 with X-RateLimit-Reason header
- Example: 5 req/5s burst, 60 req/min sustained
Config:
[global_rate_limit]
requests = 0 # disabled by default
window = "1m"
[burst_rate_limit]
burst = 0 # disabled by default
burst_window = "5s"
sustained = 0
sustained_window = "1m"
Env overrides: GLOBAL_RATE_LIMIT_REQUESTS, GLOBAL_RATE_LIMIT_WINDOW,
BURST_RATE_LIMIT_BURST, BURST_RATE_LIMIT_BURST_WINDOW,
BURST_RATE_LIMIT_SUSTAINED, BURST_RATE_LIMIT_SUSTAINED_WINDOW
Full test coverage: concurrent lock-free test, window expiry, disabled states,
IP isolation, burst vs sustained distinction.
2026-03-21 18:35:31 +00:00