Skip to content

Device-bound sessions with DBSC #15304

Open

Description

@ChiragAgg5k

Proposal

Bind browser sessions to the device with Device Bound Session Credentials (DBSC), so a copied session secret stops being enough to use a session. The browser handles the protocol, so SDKs don't change.

Status: proposal, nothing prototyped. Support: Chrome 145 on Windows and 147 on macOS. Firefox's position is negative and Safari has given no signal, so bound and unbound sessions must coexist. The spec is still an editor's draft.

Flow

sequenceDiagram
    participant B as Browser + TPM key
    participant A as Appwrite API
    B->>A: POST login
    A-->>B: long-lived a_session_<p> + Secure-Session-Registration
    B->>A: POST register (proof JWT with public key)
    A-->>B: scope + credentials, a_session_<p>_device (10 min)
    Note over B,A: device cookie expires
    B->>A: request held, POST refresh?project=<p>
    A-->>B: 403 Secure-Session-Challenge (skipped when cached)
    B->>A: POST refresh + signed challenge
    A-->>B: 200, new a_session_<p>_device
    B->>A: held request resumes
Loading

Gaps today

Today Consequence
The session cookie holds the long-lived secret No short-lived credential to bind
The secret arrives by cookie, _legacy cookie, x-appwrite-session or x-fallback-cookies Binding one cookie leaves three open
Cross-site apps keep the secret in localStorage It can be stolen without touching a cookie
9 sessionVerify call sites, including JWT creation, realtime and MQTT Each is a possible bypass
Shared hosts select the project by header, not path Scope can't separate projects, so one request could refresh every expired session on that host

Design

Keep the existing cookies and add a short-lived a_session_<project>_device. The long-lived secret is still checked on every request, so revocation stays immediate.

flowchart LR
    C[a_session_project] --> V[sessionVerify]
    L[a_session_project_legacy] --> V
    S[x-appwrite-session] --> V
    F[x-fallback-cookies] --> V
    V -->|secret valid| D{Device check}
    D -->|session not bound| OK[Authenticated]
    D -->|valid device cookie| OK
    D -->|device cookie missing| NO[401]
Loading
  • Cookie: the a_session_ prefix means general.php already strips it before forwarding requests to functions and sites.
  • Schema: store the public key on the session, which needs a sessions attribute and a migration.
  • Registration: refuse to re-register a bound session. Accept ES256 and RS256 only, because the spec also allows none.
  • Refresh: require the long-lived secret and a signed recent challenge, then issue a signed 10-minute cookie. A stateless token avoids a database write per refresh.
  • Project ID: refresh requests can't carry X-Appwrite-Project, so it goes in the URL as ?project=, which request.php already accepts.
{
  "session_identifier": "<sessionId>",
  "refresh_url": "/v1/<refresh>?project=<p>",
  "scope": { "origin": "https://api.myapp.com", "include_site": false },
  "credentials": [{
    "type": "cookie",
    "name": "a_session_<p>_device",
    "attributes": "Domain=api.myapp.com; Path=/; Secure; HttpOnly; SameSite=None"
  }],
  "allowed_refresh_initiators": ["app.myapp.com"]
}

The route name is a placeholder.

Traps

  • Revoked sessions: return 401 on refresh, not 403. A 403 means "retry with the cached challenge", while other 4xx responses end the DBSC session.
  • Secure-Session-Skipped: use it for telemetry only. An attacker can send it too, so it must never relax auth.
  • Logout: avoid Clear-Site-Data, which on a shared host would wipe other projects' sessions. Use continue: false or a 401 on refresh.
  • Attributes: credentials.attributes must match the cookie's Domain, Path, Secure, HttpOnly and SameSite, or the browser keeps refreshing.
  • Same-site apps: app.myapp.com calling api.myapp.com isn't same-origin, so it needs allowed_refresh_initiators. The project's web platforms can supply the list.
  • SSR apps: forwarding the cookie through x-appwrite-session would break on bound sessions, so projects must opt in. Sessions created with an API key are never registered.
  • Refresh endpoint: check Sec-Secure-Session-Id, keep CORS narrow and refuse embedding, because it can otherwise leak login state through timing.

Out of scope

  • Malware present during registration, or running on the device
  • A stolen device cookie, for up to 10 minutes
  • Non-supporting browsers, Linux and mobile
  • API keys

Open decisions

  • v1 coverage. Recommended: the Console first, then opt-in for projects where domainVerification passes. This leaves cross-site apps unprotected, but avoids shared hosts, third-party cookie blocking and the localStorage path.
  • Missing device cookie. Recommended: monitor mode first, then enforce with a 401 that keeps the session. Chrome can skip refresh when the endpoint is down or the TPM is busy, so enforcing risks occasional false logouts.
  • Existing sessions. Recommended: offer registration on authenticated responses until bound. The catch is that someone holding a stolen, unbound secret could bind it to their own device first.
  • Cookie lifetime. Recommended: start at 10 minutes and adjust from monitor-mode data. Shorter narrows the theft window but adds latency and TPM load.

Open questions

  • Does Chrome hold WebSocket handshakes for refresh, and how should realtime treat a socket that outlives the device cookie?
  • When the Console calls API subdomains, does it need site scope and a /.well-known/device-bound-sessions file on the registrable domain?
  • What load does refresh add per active bound session?

Progress

  • Agree on the decisions above
  • Console-only spike on Chrome for Windows or macOS
  • sessions schema attribute and migration
  • Registration and refresh endpoints
  • Device check behind all sessionVerify call sites
  • Realtime and MQTT handling
  • Console in monitor mode, measuring missing-cookie rates
  • Enforce on the Console
  • Project opt-in setting and Console UI
  • E2E coverage and docs

Activity

  1. added
    enhancement
    on Nov 4, 2026
  2. self-assigned this
    on Nov 4, 2026
  3. added
    product / auth
    on Nov 4, 2026
  4. added
    api / realtime
    product / databases
    product / domains
    product / functions
    product / migrations
    product / sites
    product / storage
    on Nov 4, 2026
  5. removed
    product / storage
    product / databases
    product / functions
    api / realtime
    product / migrations
    product / domains
    product / sites
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementproduct / auth

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions