@wardenjs/ssr-authn
v0.2.0
Published
Authentication for Fetch-API servers: signed JWT session cookies, a provider-agnostic auth decorator, password policy, lockout and scrypt hashing.
Maintainers
Readme
@wardenjs/ssr-authn
Part of warden's server track: security controls as decorators for any Fetch-API handler (Next.js route handlers, Hono, Bun, Deno, Workers). Here SSR means server side, not server-side rendering.
Who is calling: signed sessions, a generic authentication decorator, password policy, lockout, and scrypt hashing.
npm i @wardenjs/ssr @wardenjs/ssr-authn joseimport { authenticate, lockout, sessions } from '@wardenjs/ssr-authn';
import { passwordHasher } from '@wardenjs/ssr-authn/node';
// Your own sessions (JWT in a __Host- cookie):
const session = sessions({ secret: process.env.SESSION_SECRET!, issuer: 'https://app.example.com' });
export const GET = chain().use(session.required()).handle(async (_r, { principal }) => Response.json(principal));
// Or wrap the provider you already have (Auth.js, Clerk, API keys):
const auth = authenticate(async (request) => toPrincipal(await getProviderSession(request)));Sessions
- Idle timeout (default 30 min) slides on activity; the absolute deadline (default 12 h) never moves. Renewal happens past half the idle window.
- Algorithm pinned, issuer and audience checked,
alg: noneimpossible. - An invalid cookie gets 401 and is cleared. A handler that sets the cookie itself (login, logout) has the last word.
rotate()on every privilege change, against session fixation.- Revocation: put a
versionin the session and compare it inload; bumping it signs out every device.
Credentials
checkPasswordStrength: NIST 800-63B: length, common and leet variants, sequences, the user's own name and email.checkPasswordAgainstBreaches(password, fetch): HIBP k-anonymity (5 hash characters leave), fails open.lockout({ store }): delays after a soft threshold, a bounded lock at a hard one. Pair with an IP rate limit; per-account alone misses credential stuffing./nodepasswordHasher(): scrypt, versioned format, bounded parameters,needsRehash, andverifyOrEqualiseso unknown accounts take as long as wrong passwords.
