Better Auth security hardening

Hardens a Better Auth deployment: secret handling, rate limits, CSRF, trusted origins, session and cookie settings, OAuth token encryption, proxy IP headers, audit hooks and a pre-deploy checklist. Use when preparing a Better Auth app for production.

SecurityPack: Better Auth skillslinkbetter-auth-security
Author
Source
better-auth/skills/security @ 20c9e88
License
none stated

About this skill

What it does

The skill walks through the settings that harden a Better Auth deployment. The secret is read from options.secret, then BETTER_AUTH_SECRET, then AUTH_SECRET; placeholders are rejected in production, and a secret under 32 characters or 120 bits of entropy draws a warning. Rate limiting is on in production: 100 requests per 10 seconds, 3 on sign-in, sign-up, password and email change, with counters in memory, the database, secondary storage such as Redis or your own customStorage. CSRF protection (Origin header, Fetch Metadata, first-login protection) stays on.

Trusted origins can be a list, wildcards (*.example.com, exp:// for Expo), the BETTER_AUTH_TRUSTED_ORIGINS variable or a per-request function; a callbackURL or redirectTo outside them gets a 403. Further sections cover session lifetime and cookie-cache strategies (jwe for sensitive session data), cookie defaults and cross-subdomain cookies, OAuth (automatic PKCE and state, encryptOAuthTokens with AES-256-GCM), client IP headers behind a proxy, background tasks on serverless and account-enumeration defences.

Audit logging runs on databaseHooks: session created and revoked, email changed, account linked; a before hook that returns false stops the operation. A full sample config and a ten-item pre-deploy checklist close it. The folder holds only SKILL.md.

When to use it, and when not

Use it before a Better Auth app goes to production, and when it moves behind a proxy, onto serverless, across subdomains or gains a mobile client.

It tunes auth settings and does not read the rest of your code for vulnerabilities. On Neon's Managed Better Auth, trusted domains are a Neon setting (neon neon-auth domain add).

How to run it

We do not copy this skill: the author's repository has no licence. Install it from there with the button to the source. The Claude Code plugin in the repository's .claude-plugin/marketplace.json (auth-skills) carries only create-auth and best-practices, so copy the root security folder into your agent's skills directory. The name is better-auth-security-best-practices:

  • Claude Code: /better-auth-security-best-practices, or ask for the skill by name.
  • Codex: $better-auth-security-best-practices.
  • Cursor: type / in the Agent chat and pick better-auth-security-best-practices.

Example: /better-auth-security-best-practices Check auth.ts before launch: we run on Vercel behind Cloudflare, with app. and admin. subdomains.

How it differs from similar skills

Security review audits a diff in any stack and reports only exploitable findings, sessions and CSRF among them. Security best-practice review checks Express, Next.js and other stacks against framework rules on cookies, CSRF and CORS. The pack's setup and create-auth skills each carry a short security list; this is the full version. Env and config audit finds secrets committed to git, which this skill only warns against.

Install

This skill is not copied to the catalog: the author's repository has no licence text. Install it from there.

Open the source

Connect through AnyModel API

This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.

More from the pack Better Auth skills