better-auth-security-best-practices

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

Updated May 26, 2026
One-click install
npx skills add https://github.com/Albo-Club/albo-os --skill better-auth-security-best-practices-albo-club
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-security-best-practices
Source: https://github.com/Albo-Club/albo-os/tree/main/.agents/skills/better-auth-security-best-practices
Command: npx skills add https://github.com/Albo-Club/albo-os --skill better-auth-security-best-practices-albo-club

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth.

What problem does it solve? Hardening a Better Auth deployment requires coordinating many scattered security settings—secrets, rate limits, CSRF checks, cookies, OAuth token encryption, and audit logging—and missing 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 origins including wildcard and dynamic patterns. - OAuth & Audit Security: Encrypt stored OAuth tokens with AES-256-GCM, configure PKCE state strategies, track client IPs behind proxies, and implement audit logging via 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?

Enable rate limiting in the Better Auth config with a time window and max request count, choosing memory, database, or secondary-storage backends. Sensitive endpoints like sign-in default to 3 requests per 10 seconds, and you can override them with customRules per endpoint.

How to set trusted origins for Better Auth?

Pass a trustedOrigins array to the Better Auth config listing your frontend and admin domains, or set the BETTER_AUTH_TRUSTED_ORIGINS environment variable. Wildcard subdomains and dynamic async functions that compute origins per request are also supported.

Does Better Auth encrypt OAuth tokens?

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

What session cookie options does Better Auth support?

Better Auth defaults to secure, httpOnly, sameSite lax cookies with a __Secure- prefix. You can customize the prefix, attributes, cross-subdomain domain, and enable a cookie cache with compact, JWT, or JWE strategies to reduce database queries.

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.

How do I add audit logging to Better Auth?

Use databaseHooks to run callbacks after session creation, session deletion, user updates, and account linking. Inside each hook, record events like email changes or new sessions with IP and user agent details to your logging system.