better-auth-dbsc
v0.2.0
Published
Device Bound Session Credentials (DBSC) plugin for Better Auth: bind sessions to a device key so stolen cookies stop working.
Maintainers
Readme
better-auth-dbsc
Device Bound Session Credentials (DBSC) for Better Auth.
Infostealer malware copies session cookies and replays them from another machine, which skips passwords, 2FA and passkeys entirely. With DBSC, a supporting browser binds each session to a private key kept in hardware (TPM, Secure Enclave). This plugin then refuses the Better Auth session cookie of a bound session unless the request also carries a short-lived cookie that only the key holder can renew. A stolen session cookie stops working on any other device.
- Implements the current W3C editor's draft (
Secure-Session-*headers,dbsc+jwtproofs) as Chrome ships it. - Enforces the binding on every session read through Better Auth's endpoints and
auth.api. - Works with every sign-in method, including SSO and OAuth callbacks and server-side sign-ins.
- Progressive: browsers without DBSC keep working exactly as before.
- Runs anywhere Better Auth runs (Node, Bun, Cloudflare Workers, edge runtimes, Convex). Crypto by
@nobleand@scure/base.
Install
npm install better-auth-dbscUsage
// auth.ts
import { betterAuth } from "better-auth";
import { dbsc } from "better-auth-dbsc";
import { anonymous, bearer, twoFactor } from "better-auth/plugins";
export const auth = betterAuth({
plugins: [
bearer(),
twoFactor(),
dbsc(), // after bearer(), twoFactor() and crossDomain()
anonymous(), // plugins whose hooks read the session go after dbsc()
],
});dbsc() checks the plugin order at startup. Then create the dbscSession table:
npx auth generate # Drizzle, Prisma, Convex…
npx auth migrate # built-in Kysely adapterThat is all: the browser runs the protocol from response headers. The optional client plugin adds a typed status call:
import { dbscClient } from "better-auth-dbsc/client";
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({ plugins: [dbscClient()] });
const { data } = await authClient.dbsc.status(); // { bound, algorithm, boundAt }Browser support
DBSC works in Chrome on Windows (TPM) and macOS (Secure Enclave), and in Edge on Windows. Firefox and Safari do not support it yet: their sessions are not bound and work as before, without this protection. Details.
Documentation
- Getting started
- How it works
- Integrations: Convex, proxies, server components, links from other sites, subdomains
- Configuration
- API reference
- Security model: read it before relying on the plugin
- Local testing and troubleshooting
Security
Report vulnerabilities privately: see SECURITY.md.
Credits
Built and maintained by Helix Nebula.
License
MIT
