Skip to content

fix(api-server): require auth for /health/detailed and fail closed on weak keys - #56260

Merged
teknium1 merged 1 commit into
mainfrom
salvage/44073-b-api-server
Jul 1, 2026
Merged

fix(api-server): require auth for /health/detailed and fail closed on weak keys#56260
teknium1 merged 1 commit into
mainfrom
salvage/44073-b-api-server

Conversation

@teknium1

@teknium1 teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The API server's /health/detailed endpoint now requires Bearer auth, and the server refuses to start on a weak/placeholder key on any bind — closing two external-surface fail-open paths.

Salvaged from #44073 (@SahilRakhaiya05), split into a focused PR per maintainer request.

Changes

  • gateway/platforms/api_server.py:
    • /health/detailed now runs _check_auth — it exposed gateway state, connected platforms, active-agent counts, PID, and exit reason with no auth. Plain /health stays open for container liveness probes.
    • Refuse to start on a placeholder or <16-char API_SERVER_KEY on all binds (previously only network-accessible binds). A guessable key on a terminal-capable endpoint is RCE-adjacent even on loopback. The required-key check was already unconditional; this extends the strength floor.
    • Startup guards (_api_key_passes_startup_guard, _port_is_available) are hoisted above app + background-task creation so a rejected start leaves no partial state.
  • Tests: /health/detailed → 401 without auth / 200 with; weak key → refuse start with no app and no background tasks.

Validation

Before After
/health/detailed no auth 200 (leaks state) 401
/health/detailed with auth 200
Weak key on loopback starts refuses, no partial state
Plain /health liveness 200 200 (unchanged)
test_api_server* pass 194 pass

Note: existing loopback deployments with a <16-char API_SERVER_KEY will now be refused at startup — intentional for a terminal-capable endpoint. Fix is to set a strong key (openssl rand -hex 32).

Infographic

API server fail closed

@alt-glitch alt-glitch added type/security Security vulnerability or hardening comp/gateway Gateway runner, session dispatch, delivery area/auth Authentication, OAuth, credential pools sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data P2 Medium — degraded but workaround exists labels Jul 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Salvage of #44073 (split into a focused PR). Competes with #33847 / #22280 / #41754 on the same /health/detailed endpoint — related_to; a maintainer should pick the canonical fix. Not a duplicate.

@teknium1
teknium1 force-pushed the salvage/44073-b-api-server branch 2 times, most recently from 2569988 to 43c6dd2 Compare July 1, 2026 10:30
… weak keys

/health/detailed leaked runtime state (gateway state, connected
platforms, active-agent counts, PID, exit reason) with no auth. Gate it
behind the same Bearer auth as other API routes; plain /health stays
open for liveness probes.

Also refuse to start on a placeholder/too-short (<16 char) API_SERVER_KEY
regardless of bind address — a guessable key on a terminal-capable
endpoint is RCE-adjacent even on loopback, since any local process can
reach it. The required-key check was already unconditional; this extends
the strength floor to loopback binds too. Startup guards are hoisted
above app/background-task creation so a rejected start leaves no partial
state.

Salvaged from #44073 (external-surface hardening), split into a focused
PR per maintainer request.

Co-authored-by: Hermes Agent <agent@nousresearch.com>
@teknium1
teknium1 force-pushed the salvage/44073-b-api-server branch from 43c6dd2 to a1141c3 Compare July 1, 2026 11:03
@teknium1
teknium1 merged commit 2d8d08c into main Jul 1, 2026
31 checks passed
@teknium1
teknium1 deleted the salvage/44073-b-api-server branch July 1, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants