Skip to content

Security: app session minting is opt-in; revoke/rotate end minted sessions (v0.2.1) - #4

Merged
astherath merged 1 commit into
mainfrom
fix/app-session-optin
Oct 20, 2026
Merged

astherath merged 1 commit into
mainfrom
fix/app-session-optin

Conversation

@astherath

Copy link
Copy Markdown
Contributor

Fixes a HIGH-severity issue in the 0.2.0 app-session endpoint (POST /v1/apps/self/users/{subject}/sessions, #2).

Problem. Any linked app with trust_email (the default, so every existing app key) could mint full cvs_ sessions for anyone it could provision or link by email. Those sessions could create never-expiring access tokens. apps revoke and apps rotate only touched the apps row, so minted sessions and their tokens survived incident response.

Fix

  • Migration 0007_app_sessions_opt_in (13 migrations total) adds:

    • apps.allow_sessions boolean NOT NULL DEFAULT false;
    • sessions.created_by_app and sessions.max_expires_at;
    • access_tokens.created_by_app.

    It also tags pre-0.2.1 minted sessions, best effort, from the app.user.session audit rows.

  • Minting needs allow_sessions AND trust_email; otherwise it returns 403 sessions_not_allowed (or trust_email_required). The policy is re-checked in the mint transaction under a FOR SHARE lock on the live app row and key, so a concurrent revoke or rotate either sees the new session or the mint fails with 401.

  • Tagging. Minted sessions carry created_by_app. POST /v1/tokens copies the session's created_by_app onto the token, under FOR SHARE on the session row.

  • Revocation.

    • apps revoke deletes the app's tagged sessions and revokes its tagged tokens. It does this even when the app is already revoked.
    • apps rotate does the same by default; --keep-sessions opts out.
    • The counts are printed and audited (sessions_ended / tokens_revoked).
  • TTL cap. limits.app_session_ttl_hours (default 720, 0 = no cap) is a non-sliding cap on minted sessions.

  • CLI

    • apps create --allow-sessions
    • apps set|update <app> --allow-sessions true|false
    • apps show <app>
    • Every apps subcommand accepts an id or a name (case-insensitive).
    • apps list shows whether each app can mint, plus its live minted sessions/tokens.
  • doctor lists the apps that can mint, warns about allow_sessions without trust_email, and warns when [[delegated_sign_in]] is configured but no app can mint.

  • API and docs.

    • stats → app.allow_sessions; /v1/info limits → app_session_ttl_hours.
    • OpenAPI updated to 0.2.1.
    • Docs updated: apps, auth (delegated sign-in), operations (upgrade note), configuration, security, architecture.
    • CHANGELOG ## 0.2.1 has Security and Breaking sections. Workspace version bumped to 0.2.1.

Breaking. Existing apps can't mint sessions until an operator opts them in with canvas-cloud apps set <app> --allow-sessions true.

Tests (native PostgreSQL)

  • Mint is refused without allow_sessions, including for trust_email apps, for allow_sessions without trust_email, and after the flag is turned off.
  • Mint works with allow_sessions and tags the session; the TTL cap applies and the session doesn't slide past it.
  • Revoke and rotate kill minted sessions and their tokens; the person's own credentials survive.
  • --keep-sessions keeps minted sessions.
  • End to end through the CLI: set by name, the update alias, show, list, rotate, revoke, audit counts, and name ambiguity.
  • Migration 0007 on a 0.2.0-shaped schema defaults allow_sessions to false and backfills the minted session.

…minted sessions (0.2.1)

0.2.0 let every linked app with trust_email (the default) mint full cvs_ sessions with
POST /v1/apps/self/users/{subject}/sessions, those sessions could create never-expiring
access tokens, and apps revoke / apps rotate only touched the apps row, so minted
credentials survived incident response.

- migration 0007: apps.allow_sessions (default false), sessions.created_by_app +
  max_expires_at, access_tokens.created_by_app; best-effort backfill of minted sessions
  from app.user.session audit rows
- mint requires allow_sessions AND trust_email (403 sessions_not_allowed), re-checked under
  a share lock on the app row; minted sessions are tagged and capped at
  limits.app_session_ttl_hours (default 720, non-sliding)
- tokens created from a minted session copy created_by_app
- apps revoke / apps rotate delete tagged sessions and revoke tagged tokens, print and audit
  the counts; apps rotate --keep-sessions opts out
- CLI: apps create --allow-sessions, apps set/update --allow-sessions, apps show, id-or-name
  app references, apps list shows minting status and minted credentials
- doctor lists apps that may mint and warns on misconfiguration
- docs, openapi, CHANGELOG 0.2.1 (Security, Breaking), version 0.2.1
@astherath
astherath merged commit aee8e1e into main Oct 20, 2026
4 checks passed
@astherath
astherath deleted the fix/app-session-optin branch October 20, 2026 20:31
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