Repository navigation
Open
Labels
enhancementNew feature or requestproduct / authFixes and upgrades for the Appwrite Auth / Users / Teams services.
Description
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
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]
- Cookie: the
a_session_prefix meansgeneral.phpalready strips it before forwarding requests to functions and sites. - Schema: store the public key on the session, which needs a
sessionsattribute 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=, whichrequest.phpalready 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. Usecontinue: falseor a 401 on refresh. - Attributes:
credentials.attributesmust match the cookie's Domain, Path, Secure, HttpOnly and SameSite, or the browser keeps refreshing. - Same-site apps:
app.myapp.comcallingapi.myapp.comisn't same-origin, so it needsallowed_refresh_initiators. The project's web platforms can supply the list. - SSR apps: forwarding the cookie through
x-appwrite-sessionwould 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
domainVerificationpasses. This leaves cross-site apps unprotected, but avoids shared hosts, third-party cookie blocking and thelocalStoragepath. - 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-sessionsfile 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
-
sessionsschema attribute and migration - Registration and refresh endpoints
- Device check behind all
sessionVerifycall 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
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestproduct / authFixes and upgrades for the Appwrite Auth / Users / Teams services.
Activity