Skip to content

fix: end every sign-in on admin force logout, no-store on API answers - #1495

Merged
MBombeck merged 11 commits into
mainfrom
fix/asvs-session-and-cache
Nov 26, 2026
Merged

MBombeck merged 11 commits into
mainfrom
fix/asvs-session-and-cache

Conversation

@MBombeck

Copy link
Copy Markdown
Owner

Three security fixes for the next patch.

Admin force logout ends every sign-in. The route deleted web sessions only, so the native app's refresh family and paired access token survived until the refresh window ran out. It now runs destroyAllSessions, the same function as the password change and the admin password reset (moved to src/lib/auth/end-all-sessions.ts, re-exported from the session module). tests/integration/session-termination-paths.test.ts drives force logout, admin reset, password change, admin deletion and self deletion through their routes and checks that the browser, the app's access and refresh tokens and an API token are refused and the device push credentials are gone; the force-logout case fails on the old route. session-termination-guard.test.ts holds session.deleteMany to the listed places. Guardian revocation was checked: it clears the acting sessions and every guardian-minted link is re-checked against the live grant at serve time, so nothing changes there.

Cache-Control: private, no-store on every API answer. Set in apiHandler when a route names no posture (plus Pragma: no-cache), and applied by the OAuth routes and the MCP endpoint, which run outside the wrapper. The remaining weaker postures are listed with reasons in api-cache-control-guard.test.ts (public files, static category map, deprecated flag route, versioned avatar, ETag-revalidated dose list and calendar feeds). The batch routes' "do not replay" signal for the idempotency layer was no-store; it is now an internal header removed on every path. The service worker stores no API answer and the warm-start cache lives in its own IndexedDB store, so offline behaviour is unchanged.

SECURITY.md said SameSite=Strict; the cookie is Lax, which is correct for the OAuth returns and the OIDC redirect chain. The doc and the security diagram now say so, with the reason.

Gates run locally: typecheck, lint, prettier, full unit suite, full integration suite (one unrelated flake under load, green alone), OpenAPI regenerated.

The admin force logout deleted the account's web sessions only. The
native app's refresh token family and its paired access token survived,
so the app stayed signed in for the rest of its refresh window, and the
route's own comment claimed the opposite.

The route now runs destroyAllSessions, the function the password change
and the admin password reset already use: web sessions, native sign-ins,
API tokens and the rest of credentialRevocations, then the push
credentials of the devices left signed out. destroyAllSessions moves to
its own module, re-exported from the session module, and reports how many
web sessions and live device sign-ins it ended, for the route's answer
and audit row. The confirmation text names what else stops working.

An integration test drives every path that ends an account's sessions
(force logout, admin reset, password change, admin and self deletion)
and checks from the outside that the browser, the app's access and
refresh tokens and an API token are refused and the device takes no more
pushes. A guard holds every session.deleteMany to the listed places.
Most data routes sent no Cache-Control, so whether a reading, a
medication list or a lab result was kept on disk was left to the
browser's heuristics and to whatever proxy sits in front of the server.

apiHandler now sends private, no-store (with Pragma: no-cache) on every
answer that names no posture of its own. The OAuth routes and the MCP
endpoint, which cannot use the wrapper, apply the same policy; the MCP
transport's stream no-cache is raised to no-store. The coach and
document chat streams send no-store as well. Five reads that used the
bfcache-friendly max-age=0 go back to the default: the pages they serve
are no-store already, so bfcache never applied, and the helper module
goes with them.

The routes that keep a weaker posture are listed with their reason in a
guard (public files, the static category map, the deprecated flag
route, the versioned avatar, the ETag-revalidated dose list and calendar
feeds), and the guard fails on a new one or on a route handler outside
apiHandler without the policy.

The batch routes used no-store to keep a transient failure out of the
idempotency cache. Now that every answer is no-store, that signal moves
to an internal header (markNotReplayable) that withIdempotency reads and
removes on every path.

The service worker stores no API answer and the dashboard warm start
keeps its data in its own IndexedDB store, so offline behaviour is
unchanged.

The size baselines grow by the lines the policy call and the marker
take: apiHandler and the token route by one and two lines, the
idempotency module by its marker.
…ason

SECURITY.md and the security model diagram said Strict; the cookie has
always been issued Lax. Lax is the right value: the OAuth return of an
integration is a top-level navigation from another site that needs the
session, and an OIDC sign-in reaches the app through a redirect chain
that starts at the identity provider. Under Strict both would land
signed out. Cross-site writes are refused separately by the
Sec-Fetch-Site and Origin check.

SECURITY.md also states that ending a user's sessions ends the native
app's sign-ins and API tokens, and that API answers are not cached; the
changelog records all three under Security.
…cache

# Conflicts:
#	CHANGELOG.md
#	SECURITY.md
#	src/__tests__/baselines/version-stamp-comments.json
With API responses no-store, the browser no longer drains an unread
body into its cache. The briefing read returned on a 422, 429, 503 or
403 without reading the body, so the request stayed open for the life
of the page and held its connection; the tablet shell e2e waited for
network idle on /insights and timed out.
…cache

# Conflicts:
#	src/app/api/insights/targets/route.ts
@MBombeck
MBombeck merged commit c4d11f4 into main Nov 26, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant