API security: lock down the fan-control surface#2
Merged
Conversation
The control API was unauthenticated on 0.0.0.0:8086 — any LAN host could pin fans at 1% indefinitely, and overrides bypassed the min/max clamp. - Bearer-token auth (api.token config key / API_TOKEN env) on all mutating endpoints (POST/DELETE override, POST/DELETE hint) via middleware with constant-time comparison. Read-only endpoints and dashboard stay open. - No-token mode: mutating requests restricted to loopback peers (403 otherwise, judged from RemoteAddr — forwarded headers ignored and spoof-proof), with a loud startup warning. - Overrides clamped to min_speed/max_speed at the controller layer (plus defense-in-depth in calculateTarget); duration capped at 24h so overrides can no longer be infinite. Critical-temp emergency ramp still beats any override. - Stored XSS fixed: hint/GPU/CPU fields escaped before innerHTML in the dashboard; server-side hint validation (charset, length, closed sets) rejects script payloads outright. - api.token excluded from /api/config responses; no request logging that could leak it. - Docs: README API Security + migration note, config.example.yaml exposure comments, unraid template masked API_TOKEN field, hint-client.sh sends the bearer token (and its lost exec bit is restored). Tests: httptest coverage for the full auth matrix, loopback/spoofing, clamping, validation, token non-leakage. go vet and go test -race clean. Task: dex ttm1g3x0 - Tier 2: API security Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EQmqj1Hj8DL3GGAcBDNm8v
This was referenced Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #1 — merge that first, then retarget/merge this.
The control API was unauthenticated on
0.0.0.0:8086: any LAN host could pin fans at 1% indefinitely, overrides bypassed the speed clamp, and the dashboard had a stored XSS via hint fields. This PR closes all three:api.token/API_TOKENenv) on all mutating endpoints, constant-time comparison, token never leaked via/api/configor logs. Read-only endpoints and the dashboard stay open.X-Forwarded-Forspoofing tested and ineffective), loud startup warning.min_speed/max_speedat the controller layer; duration capped at 24h (no more infinite overrides). Critical-temp emergency ramp still beats any override — regression-tested live.innerHTML.config.example.yamlexposure comments, Unraid template maskedAPI_TOKENfield,hint-client.shsends the bearer token.Backward compatible: existing deployments keep working; adding a token is a config-only change.
Review & verification
2cka7723); reviewer independently probed loopback-bypass edge cases (IPv6 zones, mapped addresses, malformed peers — all fail closed) and confirmed zero Tier 1 safety regression.go vet+go test -race -count=1 ./...clean; newinternal/apihttptest suite covers the auth matrix.hint-client.shruns against a token-protected server, speed-100 request clamped to 80, duration-0 capped at exactly 24h, XSS payload rejected, critical ramp beat an active low override in one tick.Task: dex ttm1g3x0 — Tier 2: API security
🤖 Generated with Claude Code