better-auth-security-best-practices

Configure rate limiting, CSRF protection, and secure sessions for Better Auth deployments.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth.

What problem does it solve? Hardening a Better Auth deployment requires coordinating many security settings—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, session hijacking, or account enumeration 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 caches (compact, JWT, or JWE), secure cookie attributes, cross-subdomain cookies, and multi-layer CSRF protection with trusted origin validation including wildcards and dynamic per-tenant origins. - OAuth & Audit Security: Encrypt stored OAuth tokens with AES-256-GCM, configure PKCE state strategies, track client IPs behind proxies, and implement audit logging through database hooks. - Use Case: Before launching a SaaS app, apply the complete security configuration example and run through the production checklist to verify secrets, HTTPS, trusted origins, and rate limits are all correctly set. ## Quick Start Ask the AI to review your Better Auth configuration and apply the security best practices for rate limiting, trusted origins, and session cookies.

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?▼

Rate limiting in Better Auth is enabled by default in production with a 10-second window and 100-request maximum. Set rateLimit.storage to database or secondary-storage for persistence, and use customRules to apply stricter limits like 5 attempts per minute on sign-in endpoints.

How to set up trusted origins for Better Auth?▼

Configure trustedOrigins as an array of allowed origins in your Better Auth config or via the BETTER_AUTH_TRUSTED_ORIGINS environment variable. Wildcard patterns like *.example.com and dynamic async functions per request are supported, and invalid callback URLs receive a 403 response.

Does Better Auth encrypt OAuth tokens?▼

Better Auth supports OAuth token encryption by setting account.encryptOAuthTokens to true, which uses AES-256-GCM. Enable this when storing provider tokens to call APIs on behalf of users, and note PKCE is automatic for all OAuth flows.

Why is my Better Auth secret rejected in production?▼

Better Auth rejects default or placeholder secrets in production and warns when secrets are shorter than 32 characters or below 120 bits of entropy. Generate a valid secret with openssl rand -base64 32 and set it via the BETTER_AUTH_SECRET environment variable.

Can I use Better Auth rate limiting on serverless platforms?▼

In-memory rate limit storage resets on restart and should be avoided on serverless platforms. Use database storage or secondary-storage backed by Redis instead, and configure advanced.backgroundTasks with the platform waitUntil handler so emails and async work complete reliably.