Skip to content

Warn at dashboard startup when the control-plane token is unset #187

Done

Description

@w4ffl35

Problem

The dashboard's control-plane token (HEADLESSCODE_DASHBOARD_TOKEN, src/dashboard/server.ts) is optional: unset = no auth at all on POST /api/session/*, POST /api/tool/execute, POST /api/checkpoints/restore, and settings writes. That is a deliberate local-first default (binds 127.0.0.1), but nothing tells the operator they are running unauthenticated — and downstream sidecar composes have shipped with the token set to "". SECURITY.md documents the risk; the runtime stays silent.

Architecture (independent solution)

Warn loudly, change no default:

  1. At dashboard startup (startDashboardServer / dashboard CLI path), if no token is configured, print one stderr banner: control-plane routes are unauthenticated, bound to loopback only, and how to set HEADLESSCODE_DASHBOARD_TOKEN. Print once, not per request.
  2. If a token is set, print a single line confirming gated routes (never print the token).
  3. Keep bind address and gating logic untouched.

Scope / non-goals

  • No fail-closed change, no new auth system, no compose changes in other repos (documented as follow-up in the hardening-docs issue).

Acceptance

  • Dashboard without token: banner visible in startup output; session/tool routes still work locally.
  • Dashboard with token: no warning banner; unauthenticated POST still 401.

Tests (happy / sad / bad)

  • Happy: token set → no warning, 401 without header, 200 with header (existing server tests cover the latter two; add the log assertion).
  • Sad: token unset → server starts, warning emitted once.
  • Bad: empty-string env treated as unset (matching the compose "" failure mode).

Contributor notes

Good first issue. Find the dashboard CLI entry (headlesscode dashboard) and mirror its existing stderr idiom; don't add a logging dependency.

Activity

  1. added
    enhancement
    good first issue
    help wanted
    on Nov 29, 2026
  2. w4ffl35 commented on Dec 5, 2026

    @w4ffl35
    MemberAuthor

    Issue 187 — Closing Report

    Files changed

    • src/dashboard/server.ts (new exported warnControlPlaneAuth(): stderr banner when token unset/empty — names unauthenticated control-plane routes, 127.0.0.1-only binding, and the env var; single gated line when set, never prints the token; called once from startDashboardServer listen callback)
    • src/dashboard/tests/server.test.ts (5 new tests: warning content, gated-no-leak, empty-string-as-unset, startup-warns-but-serves, startup-gated line; shortened 5 pre-existing over-length labels to fit the 80-col rule)

    Baseline (before)

    Dashboard startup printed only [dashboard] listening on .... No operator signal that control-plane POSTs were unauthenticated; compose ships the token as "" silently.

    Baseline (after)

    • No token: [dashboard] WARNING: no HEADLESSCODE_DASHBOARD_TOKEN set — control-plane routes (...) are unauthenticated. Bound to 127.0.0.1 only. Set HEADLESSCODE_DASHBOARD_TOKEN to gate them. on stderr, once, at startup; routes still serve locally (asserted 200/500 on /api/summary).
    • Token set: [dashboard] control-plane routes are gated by HEADLESSCODE_DASHBOARD_TOKEN, token never echoed (asserted).
    • Empty-string token: takes the warning path (cli.ts || undefined maps "" → unset; unit-tested at warnControlPlaneAuth({token: ""})).
    • Bind address and gating logic untouched; All 15 dashboard server tests passed (10 pre-existing + 5 new).
    • npx tsc --noEmit clean; new code adds zero standards violations (one 81-char import fixed in passing in the Fleet file).

    Boot check

    Live probe: startDashboardServer({port: 0}) → warning banner on stderr; with token: "sekret" → gated line. Full npm test: run-tests: all 341 file(s) passed.

    Residual risk / notes

    Warning goes to stderr via process.stderr.write (matches existing dashboard CLI idiom; no logging dependency). Tests that capture stderr restore the original write in finally. The banner prints on every startDashboardServer call, including test-spawned servers — by design (once per process in production; the CLI starts exactly one server).

    PR: #204

  3. added a commit that references this issue on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions