Skip to content

API security: lock down the fan-control surface#2

Merged
sethpjohnson merged 1 commit into
mainfrom
claude/ttm1g3x0-api-security
Jul 17, 2026
Merged

API security: lock down the fan-control surface#2
sethpjohnson merged 1 commit into
mainfrom
claude/ttm1g3x0-api-security

Conversation

@sethpjohnson

@sethpjohnson sethpjohnson commented Jul 17, 2026

Copy link
Copy Markdown
Owner

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:

  • Bearer-token auth (api.token / API_TOKEN env) on all mutating endpoints, constant-time comparison, token never leaked via /api/config or logs. Read-only endpoints and the dashboard stay open.
  • No-token mode fails safe: mutations restricted to loopback peers judged from the real connection (X-Forwarded-For spoofing tested and ineffective), loud startup warning.
  • Override hardening: clamped to min_speed/max_speed at the controller layer; duration capped at 24h (no more infinite overrides). Critical-temp emergency ramp still beats any override — regression-tested live.
  • XSS closed at both layers: server-side charset/length/closed-set validation rejects payloads (400); everything server-derived is escaped before innerHTML.
  • Docs/tooling: README API Security section + migration note, config.example.yaml exposure comments, Unraid template masked API_TOKEN field, hint-client.sh sends the bearer token.

Backward compatible: existing deployments keep working; adding a token is a config-only change.

Review & verification

  • Principal review → APPROVED WITH SUGGESTIONS first-pass (follow-ups: dex 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; new internal/api httptest suite covers the auth matrix.
  • Acceptance-verified live in demo mode: 401/403/200 matrix, real hint-client.sh runs 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant