better-auth-security-best-practices

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

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

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, cookies, OAuth token encryption, and audit logging—and misconfiguring any one of them leaves authentication endpoints exposed to brute force, CSRF, 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 origins including wildcard and dynamic patterns. - OAuth & Audit Security: Encrypt stored OAuth tokens with AES-256-GCM, configure state strategies, track client IPs, and implement audit logging via database hooks for sessions, users, and linked accounts. - Use Case: Before launching a production app, apply the complete security configuration example and run through the deployment checklist to verify secrets, HTTPS, trusted origins, and rate limits are all correctly set. ## Quick Start Review my Better Auth configuration and apply production security best practices including rate limiting, trusted origins, and encrypted sessions.

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 a time window and max request count, choosing memory, database, or secondary-storage (Redis) backends. Sensitive endpoints like sign-in and sign-up default to 3 requests per 10 seconds, and you can override them with customRules.

How do I set up trusted origins in Better Auth?▼

Pass a trustedOrigins array to the betterAuth config listing allowed origins such as your frontend and admin domains. It supports wildcard subdomains, custom schemes, environment variable configuration, and dynamic async functions that compute origins per request.

Does Better Auth encrypt OAuth tokens?▼

Yes, setting account.encryptOAuthTokens to true encrypts stored OAuth tokens using AES-256-GCM. Enable this when storing provider tokens to call APIs on behalf of users.

What session cookie strategies does Better Auth support?▼

Better Auth cookie caching supports three strategies: compact (Base64url with HMAC, smallest size), jwt (HS256 signed), and jwe (encrypted). Use jwe when session data cached in cookies contains sensitive information.

Why is my Better Auth rate limit resetting on serverless?▼

The default memory storage resets whenever the server restarts, which happens constantly on serverless platforms. Switch the storage option to database or secondary-storage backed by Redis for persistent rate limit counters.

How do I add audit logging to Better Auth?▼

Use databaseHooks to run callbacks after session creation, user updates, or account linking, recording events like email changes and IP addresses. Returning false from a before hook also lets you block operations.