wifi-densepose/v2/crates/homecore-api/src
ruv 408cfd4f03 fix(homecore-api/sec): close HC-01/HC-02 — real bearer-token store
Replaces the P1 "any non-empty bearer" placeholder with a real
LongLivedTokenStore (HashSet<String>) on SharedState. Closes the
two Critical findings from the iter-10 security audit
(docs/security/HOMECORE-security-audit-iter10.md HC-01 + HC-02).

New module `homecore-api::tokens`:
- LongLivedTokenStore::empty() — default-deny
- LongLivedTokenStore::from_env() — reads HOMECORE_TOKENS=t1,t2,t3
- LongLivedTokenStore::allow_any_non_empty() — DEV-only, warns
  on every check, preserves legacy behaviour for migrating users
- register / revoke / is_valid / len / is_dev_mode — full API

Wired through:
- SharedState gains `tokens: LongLivedTokenStore`; constructors
  with_tokens(...) for explicit injection; with_metadata defaults
  to DEV (allow_any) for backwards compat with existing smoke tests
- BearerAuth::from_headers now async + takes &LongLivedTokenStore;
  checks store.is_valid(token) before returning Ok
- All 6 REST handlers updated to thread the store and await the
  validation
- homecore-server reads HOMECORE_TOKENS at boot; if set, builds
  the store from env; if unset, falls back to DEV with a warn log

Test count: 4 → 15 (+11 token-store + auth-with-store tests).
Smoke verified end-to-end:

  HOMECORE_TOKENS=good homecore-server --bind 127.0.0.1:8126
  → "LongLivedTokenStore provisioned with 1 bearer token(s)"
  curl -H "Authorization: Bearer good" .../api/states   → 200
  curl -H "Authorization: Bearer wrong" .../api/states  → 401
  curl -H "Authorization: Bearer " .../api/states       → 401
  curl .../api/states                                   → 401

Refs: docs/security/HOMECORE-security-audit-iter10.md (HC-01 + HC-02)
Refs: docs/adr/ADR-130-homecore-rest-websocket-api.md §3 auth
Refs: #798
Refs: #800

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-25 20:59:09 -04:00
..
bin feat(homecore/p1 iter-2): API (ADR-130) + plugins (ADR-128) scaffolds in parallel 2026-05-25 18:14:14 -04:00
app.rs feat(homecore/p1 iter-2): API (ADR-130) + plugins (ADR-128) scaffolds in parallel 2026-05-25 18:14:14 -04:00
auth.rs fix(homecore-api/sec): close HC-01/HC-02 — real bearer-token store 2026-05-25 20:59:09 -04:00
error.rs feat(homecore/p1 iter-2): API (ADR-130) + plugins (ADR-128) scaffolds in parallel 2026-05-25 18:14:14 -04:00
lib.rs fix(homecore-api/sec): close HC-01/HC-02 — real bearer-token store 2026-05-25 20:59:09 -04:00
rest.rs fix(homecore-api/sec): close HC-01/HC-02 — real bearer-token store 2026-05-25 20:59:09 -04:00
state.rs fix(homecore-api/sec): close HC-01/HC-02 — real bearer-token store 2026-05-25 20:59:09 -04:00
tokens.rs fix(homecore-api/sec): close HC-01/HC-02 — real bearer-token store 2026-05-25 20:59:09 -04:00
ws.rs feat(homecore/p1 iter-2): API (ADR-130) + plugins (ADR-128) scaffolds in parallel 2026-05-25 18:14:14 -04:00