npx skills add ...
npx skills add better-auth/skills --skill better-auth-security-best-practices
Configure rate limiting, manage auth secrets, set up CSRF protection, define trusted origins, secure sessions and cookies, encrypt OAuth tokens, track IP addresses, and implement audit logging for Better Auth. Use when users need to secure their auth setup, prevent brute force attacks, or harden a Better Auth deployment.
npx skills add better-auth/skills --skill better-auth-security-best-practices
Better Auth looks for secrets in this order:
options.secret in your configBETTER_AUTH_SECRET environment variableAUTH_SECRET environment variableopenssl rand -base64 32Enabled in production by default. Applies to all endpoints. Plugins can override per-endpoint.
Options: "memory" (resets on restart, avoid on serverless), "database" (persistent), "secondary-storage" (Redis, default when available).
Implement your own rate limit storage:
Sensitive endpoints default to 3 requests per 10 seconds (/sign-in, /sign-up, /change-password, /change-email). Override:
Multi-layer protection: origin header validation, Fetch Metadata checks, and first-login protection.
Only disable for testing or with an alternative CSRF mechanism.
The baseURL origin is automatically trusted. Also configurable via env: BETTER_AUTH_TRUSTED_ORIGINS=https://app.example.com,https://admin.example.com
Compute trusted origins based on the request:
Validates callbackURL, redirectTo, errorCallbackURL, newUserCallbackURL, and origin against trusted origins. Invalid URLs receive 403.
Cache session data in cookies to reduce database queries:
Strategies: "compact" (Base64url + HMAC, smallest), "jwt" (HS256, standard), "jwe" (encrypted, use when session has sensitive data).
Defaults: secure: true (HTTPS/production), sameSite: "lax", httpOnly: true, path: "/", prefix __Secure-.
Only enable if you need authentication sharing and trust all subdomains.
PKCE is automatic for all OAuth flows. State tokens are 32-char random strings expiring after 10 minutes.
Enable if storing OAuth tokens for API access on behalf of users. Use skipStateCookieCheck: true only for mobile apps that cannot maintain cookies.
Set ipv6Subnet (128, 64, 48, 32; default 64) to group IPv6 addresses. Enable trustedProxyHeaders: true only if behind a trusted reverse proxy.
Return false from a before hook to prevent an operation.
Ensures operations like sending emails don't affect response timing.
Built-in: consistent response messages, dummy operations on invalid requests, background email sending. Return generic error messages ("Invalid credentials") rather than specific ones ("User not found").
Before deploying to production:
baseURL uses HTTPSdisableCSRFCheck: false)encryptOAuthTokens: true if storing tokensdatabaseHooks or hooks