Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex r3): drop the false fail-closed claim; report auth state honestly
[._.]/ Adam Eivy2ed83fb799dd
diff --git a/docs/COMPANION_APP_API.md b/docs/COMPANION_APP_API.mdindex 24b2de9228..9426f06584 100644--- a/docs/COMPANION_APP_API.md+++ b/docs/COMPANION_APP_API.md@@ -55,7 +55,7 @@ any credential.| `instanceId` | Stable per-install UUID (`crypto.randomUUID()`, persisted in `data/instances.json`). The identity key the app stores per connection; survives hostname changes. `null` before the self-identity is first created. || `name` | User-set display name for the instance (`self.name`), falling back to `hostname` when unset. This is what to show in the instance list. || `hostname` | OS hostname of the machine. |-| `authRequired` | `true` when the password gate is on — the app must obtain a password and send it on subsequent requests. `false` when off — no credential needed. Lets the app decide whether to prompt **without** a second round-trip to `/api/auth/status`. Fails **closed** (reports `true`) if the auth state can't be read. |+| `authRequired` | `true` when the password gate is on — the app must obtain a password and send it on subsequent requests. `false` when off — no credential needed. Lets the app decide whether to prompt **without** a second round-trip to `/api/auth/status`. Mirrors the server's `isAuthEnabled()`; the app should still handle a `401` on a gated request as the authoritative signal to (re)prompt. || `scheme` | `"http"` or `"https"` — the scheme `:5555` serves, decided once at boot. Use it to build request URLs and label the connection's security. || `version` | PortOS release the instance is running — useful for compatibility gating. |diff --git a/server/lib/authGate.js b/server/lib/authGate.jsindex eae3e4a293..50b3d60cda 100644--- a/server/lib/authGate.js+++ b/server/lib/authGate.js@@ -121,20 +121,7 @@ const isCrossOrigin = (req) => {// allows the small public set above; gates the rest behind a valid token in// the cookie or Authorization: Bearer header.export const authGate = async (req, res, next) => {- let enabled;- try {- enabled = await isAuthEnabled();- } catch {- // Fail closed: if the auth state can't be read (e.g. a transient- // settings-read failure on the cold path before isAuthEnabled's cache is- // primed), assume auth is ON so no gated route slips through — but do NOT- // 500 the whole request here. Fall through to the public-path checks below- // so the intentionally pre-auth endpoints (/api/system/health discovery,- // the login UI) stay reachable. This is what makes the health route's- // documented fail-closed `authRequired: true` actually observable — its own- // isAuthEnabled().catch(() => true) never runs if the gate rejects first.- enabled = true;- }+ const enabled = await isAuthEnabled();if (!enabled) return next();// CSRF guard runs FIRST, before isPublicPath — public endpoints like// /api/auth/logout still mutate state (clear the cookie + revoke thediff --git a/server/lib/authGate.test.js b/server/lib/authGate.test.jsindex cd6de4dd91..e380be8200 100644--- a/server/lib/authGate.test.js+++ b/server/lib/authGate.test.js@@ -63,26 +63,6 @@ describe('authGate middleware', () => {expect(result.called).toBe(true);});- it('fails closed but keeps public discovery paths reachable when the auth-state read throws', async () => {- // Simulate isAuthEnabled() rejecting on the cold path (e.g. a transient- // settings read failure before its cache is primed). The gate must not- // 500 the request: public paths stay reachable (so /api/system/health- // discovery works pre-auth) while gated routes fail closed as if auth is on.- const auth = await import('../services/auth.js');- const spy = vi.spyOn(auth, 'isAuthEnabled').mockRejectedValue(new Error('settings unreadable'));- const { authGate } = await import('./authGate.js');-- const health = await runGate(authGate, { path: '/api/system/health', headers: {} });- expect(health.called).toBe(true);-- const gated = await runGate(authGate, { path: '/api/cos', headers: {} });- expect(gated.called).toBe(false);- expect(gated.res.statusCode).toBe(401);- expect(gated.res.body).toEqual({ error: 'Authentication required', code: 'AUTH_REQUIRED' });-- spy.mockRestore();- });-it('blocks /api routes with no token', async () => {const auth = await import('../services/auth.js');await auth.setPassword({ newPassword: 'correct-horse' });diff --git a/server/routes/systemHealth.js b/server/routes/systemHealth.jsindex 4c17d0b01d..5047d377ec 100644--- a/server/routes/systemHealth.js+++ b/server/routes/systemHealth.js@@ -43,11 +43,11 @@ router.get('/health', asyncHandler(async (req, res) => {const [self, version, authRequired] = await Promise.all([getSelf().catch(() => null),getCurrentVersion(),- // Fail closed: if the auth state can't be read, tell the client a password- // may be required so it prompts rather than silently sending unauthenticated- // requests that would 401. This endpoint stays public (PUBLIC_API_PATHS) so a- // companion client can read identity before it holds any credential.- isAuthEnabled().catch(() => true)+ // Whether the optional password gate is on, so a companion client knows to+ // prompt for a password without a second round-trip to /api/auth/status.+ // This endpoint stays public (PUBLIC_API_PATHS) so the client can read+ // identity before it holds any credential.+ isAuthEnabled()]);const hostname = os.hostname();res.json({