better-auth-security-best-practices

Configure rate limiting, CSRF protection, trusted origins, and session security for Better Auth deployments.

Updated Jul 24, 2026
One-click install
npx skills add https://github.com/saad-tayyab/lumora --skill better-auth-security-best-practices-saad-tayyab
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-security-best-practices
Source: https://github.com/saad-tayyab/lumora/tree/main/.agents/skills/better-auth-security-best-practices
Command: npx skills add https://github.com/saad-tayyab/lumora --skill better-auth-security-best-practices-saad-tayyab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth.

What problem does it solve? Securing a Better Auth deployment requires correctly configuring many scattered options—secrets, rate limits, CSRF checks, trusted origins, cookies, and OAuth token encryption—and misconfiguring any one of them leaves the authentication layer exposed to brute force, CSRF, or session hijacking attacks. ## Core Features & Use Cases - Rate Limiting & Brute Force Defense: Configure global and per-endpoint rate limits with memory, database, or Redis-backed storage, including stricter rules for sign-in and sign-up endpoints. - Session, Cookie & CSRF Hardening: Set session expiration, encrypted cookie caching (compact, JWT, or JWE), secure cookie attributes, cross-subdomain cookies, and multi-layer CSRF protection with trusted origin validation including wildcard and dynamic patterns. - OAuth & Audit Security: Encrypt stored OAuth tokens with AES-256-GCM, manage state parameters, track client IP addresses, and implement audit logging through database hooks for sessions, users, and accounts. - Use Case: Before deploying a SaaS app to production, apply the complete security configuration example and run through the included checklist to verify secrets, HTTPS, trusted origins, rate limits, and audit logging are all in place. ## Quick Start Ask the AI to generate a production-ready Better Auth configuration with rate limiting, trusted origins, encrypted OAuth tokens, and audit logging for your application.

Frequently Asked Questions about better-auth-security-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure rate limiting in Better Auth?

Enable rate limiting in the betterAuth config with window and max values, defaulting to 100 requests per 10 seconds in production. Choose memory, database, or secondary-storage (Redis) backends, and define customRules for sensitive endpoints like sign-in.

How do I set trusted origins in Better Auth?

Pass a trustedOrigins array to the betterAuth config or set the BETTER_AUTH_TRUSTED_ORIGINS environment variable. Wildcard patterns like *.example.com and dynamic async functions resolving origins per request are supported.

Does Better Auth encrypt OAuth tokens?

Yes, set account.encryptOAuthTokens to true and Better Auth encrypts stored OAuth tokens using AES-256-GCM. This is recommended when storing provider tokens to call APIs on behalf of users.

How do I add audit logging to Better Auth?

Use databaseHooks to run callbacks after session creation, user updates, or account linking, and write events to your audit log. Returning false from a before hook prevents the operation entirely.

What are the secret requirements for Better Auth?

Better Auth reads the secret from options.secret, BETTER_AUTH_SECRET, or AUTH_SECRET in that order. It rejects default placeholder secrets in production and warns if the secret is under 32 characters or below 120 bits of entropy.

When should I disable CSRF checks in Better Auth?

Only disable CSRF checks via advanced.disableCSRFCheck for testing or when an alternative CSRF mechanism exists. Better Auth provides multi-layer protection through origin header validation and Fetch Metadata checks by default.