fix(web): the charts stop lying about time, and logging out logs you out

The stats charts drew every sample as an evenly-spaced slot, because recharts
defaults to a category axis. A capture that idled for two minutes rendered that
gap as a single step — so the one view you open specifically to find where the
time went was the view least able to show it. All three charts use a numeric time
axis now, so the spacing is the elapsed time.

They also joined samples across a session boundary into one continuous line,
implying a continuity that never existed: the stream stopped and somebody else
started a new one. A capture is split at each `session_id` change now. And the
live card plotted the whole capture-so-far every 2 s, re-serialising and
re-plotting an unbounded series for a capture left running all evening; it plots
a bounded tail and says so, with the full series still in the saved recording.

Logging out only deleted the browser's copy of the cookie. The session is
stateless, so a value captured beforehand — a shared machine, a shell history, a
TLS-inspecting proxy — stayed valid for its full 7-day TTL and there was nothing
the operator could do about it. Sessions carry an epoch now and logging out bumps
it, which invalidates every cookie issued so far. Verified end to end: a captured
cookie works, survives nothing across a logout, and a fresh login still works.

The rest:

- The update card could not show its own timeout warning. It was suppressed by a
  `job` field read from the last snapshot — which, when the host has gone away
  mid-job, is exactly the case the warning exists for. Nothing ever cleared the
  applying state either, so the card waited forever with no way out; there is a
  button now. "Check now" also surfaces the host's 429 instead of looking dead.
- A running install survives a reload: the job id lived only in component state,
  so refreshing lost sight of an install that was still running while the Install
  buttons stayed armed against a host that answers 409. The host keeps the list —
  ask it.
- An all-sources-failed catalog said "no plugins available". That is a successful
  request carrying nothing, not an empty store; it names the sources that failed.
- The Installed tab rendered "vundefined" for a plugin with no recorded version
  (nullable in the contract, typed required here).
- The Displays "In effect" badges were computed from the local draft, so they
  restated the operator's unsaved edits back to them as though the host had
  adopted them. They read the API's `effective` now. A failed background poll no
  longer replaces a form someone is editing, and leaving the page with unsaved
  edits prompts — the old `beforeunload` guard never fired for in-app navigation,
  which is how you actually leave.
- Enter or Space on a preset's rename/update/delete icon applied the preset
  instead of running the action: keydown bubbled to the card.
- Dates follow the console's locale, not the browser's. The dashboard's
  PIN-pending tile says "Waiting"/"None" instead of "●"/"—".
- The Bun entry warns when TLS is half-configured, or when PUNKTFUNK_UI_SECURE
  is set without it — both of which silently break login.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-01 00:20:10 +02:00
co-authored by Claude Opus 5
parent de17ceb8f8
commit b9b0df349d
18 changed files with 415 additions and 78 deletions
+5 -1
View File
@@ -15,6 +15,7 @@ import {
isPublicPath,
type SessionData,
sessionConfig,
sessionEpoch,
uiPassword,
} from "../util/auth";
@@ -64,7 +65,10 @@ export default defineEventHandler(async (event) => {
}
const session = await useSession<SessionData>(event, sessionConfig());
if (session.data.authenticated) return; // authenticated — let it through
// The epoch check is what makes logout mean something: a cookie sealed before the last
// revocation unseals fine but no longer matches, so it is refused like any other bad session.
if (session.data.authenticated && session.data.epoch === sessionEpoch())
return; // authenticated — let it through
if (pathname.startsWith("/api")) {
setResponseStatus(event, 401);
+2 -1
View File
@@ -13,6 +13,7 @@ import {
peerAddress,
type SessionData,
sessionConfig,
sessionEpoch,
timingSafeEqual,
uiPassword,
} from "../../util/auth";
@@ -53,6 +54,6 @@ export default defineEventHandler(async (event) => {
}
recordLoginSuccess(ip);
const session = await useSession<SessionData>(event, sessionConfig());
await session.update({ authenticated: true });
await session.update({ authenticated: true, epoch: sessionEpoch() });
return { ok: true };
});
+12 -2
View File
@@ -1,9 +1,19 @@
// POST /_auth/logout — clear the session cookie.
// POST /_auth/logout — clear the session cookie AND revoke every session issued so far.
//
// Clearing alone only deletes the browser's copy: the cookie is stateless, so a captured value
// stayed valid for its whole 7-day TTL and "log out" logged nothing out. Bumping the epoch means
// the gate rejects every cookie sealed before now. Single-user console, so "log out" and "sign out
// everywhere" are the same action — which is the safer of the two to make the default.
import { defineEventHandler, useSession } from "h3";
import { type SessionData, sessionConfig } from "../../util/auth";
import {
revokeAllSessions,
type SessionData,
sessionConfig,
} from "../../util/auth";
export default defineEventHandler(async (event) => {
const session = await useSession<SessionData>(event, sessionConfig());
await session.clear();
revokeAllSessions();
return { ok: true };
});
+26
View File
@@ -195,4 +195,30 @@ export function safeNextPath(next: string | undefined): string {
export interface SessionData {
authenticated?: boolean;
/** The epoch this session was sealed under — see `sessionEpoch`. */
epoch?: number;
}
/**
* A revocation counter for issued sessions.
*
* The session is stateless: everything lives inside the sealed cookie, so `session.clear()` only
* deletes the BROWSER's copy. A cookie captured beforehand (a shared machine, a shell history, a
* TLS-inspecting proxy) stayed valid for its full 7-day TTL with nothing the operator could do
* about it — "log out" did not log anything out.
*
* Bumping this invalidates every previously issued cookie, because the gate compares the stamped
* epoch against the current one. It lives in memory, so a host restart also revokes — acceptable
* for a single-user console, and the safe direction to fail.
*/
let epoch = 1;
/** The epoch a new session is stamped with, and the one the gate requires. */
export function sessionEpoch(): number {
return epoch;
}
/** Invalidate every session issued so far (the "sign out everywhere" lever). */
export function revokeAllSessions(): void {
epoch += 1;
}