better-auth-security-best-practices

Configure Better Auth secrets, rate limiting, CSRF, sessions, and OAuth token encryption.

Updated May 14, 2026
One-click install
npx skills add https://github.com/chroniicallydiistracted/LorcanaChamp --skill better-auth-security-best-practices-chroniicallydiistracted
Or copy as Structured Prompt for Agentβ–Ό
Please help me install this Agent Skill.
Skill: better-auth-security-best-practices
Source: https://github.com/chroniicallydiistracted/LorcanaChamp/tree/main/references/lorcana-simulator/.agents/skills/better-auth-security-best-practices
Command: npx skills add https://github.com/chroniicallydiistracted/LorcanaChamp --skill better-auth-security-best-practices-chroniicallydiistracted

SYSTEM DOCUMENTATION & REQUIREMENTS

πŸ’‘ This Skill includes references (resource) components.

What problem does it solve?

Better Auth deployments are vulnerable when secrets, session handling, CSRF protections, and request throttling are misconfigured, leading to brute-force login attempts, token/session exposure, and hard-to-audit security incidents.

Core Features & Use Cases

  • Secret Management: Configure strong Better Auth secrets via config or environment variables, and enforce requirements like minimum length and entropy to reduce guessing risk.
  • Rate Limiting: Enable protection against high-rate abuse globally and tailor stricter limits for sensitive auth endpoints such as sign-in and password/email changes.
  • CSRF and Origin Hardening: Keep CSRF checks enabled and define trusted origins (including wildcard patterns and dynamic validation) to prevent cross-site request forgery and unauthorized redirects.
  • Session and Cookie Security: Set safe session expiration/update policies and use secure cookie defaults (HTTPS-only, httpOnly, sameSite, and prefixing) to limit session theft and misuse.
  • OAuth Token Protection and Auditing: Encrypt OAuth tokens, implement database hooks for audit logging, and use generic error messaging to reduce account enumeration.
  • Operational Safety: Configure background task handling for serverless platforms and optionally track IPs for rate limiting when behind proxies.

Quick Start

Update your Better Auth configuration to use an environment-provided secret, enable rate limiting, keep CSRF checks on, and set trustedOrigins to your frontend/admin origins.

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 secure Better Auth against brute force login attempts?β–Ό

Secure Better Auth against brute force by enabling rateLimit with appropriate storage and configuring stricter per-endpoint rules for sensitive operations like sign-in and password changes to throttle high-rate abuse.

What is the best way to configure session cookies in Better Auth to prevent session theft?β–Ό

Configuring session cookies in Better Auth requires setting safe expiration and update policies alongside secure defaults like HTTPS-only, httpOnly, sameSite, and prefixing to limit session theft and misuse.

Does Better Auth support CSRF protection and trusted origins for production deployments?β–Ό

Better Auth supports CSRF protection by keeping validation enabled and defining trustedOrigins using exact matches, wildcard patterns, or dynamic validation to prevent cross-site request forgery and unauthorized redirects.

How do I encrypt OAuth tokens and set up audit logging in Better Auth?β–Ό

Encrypt OAuth tokens and implement audit logging in Better Auth by using databaseHooks to track security events, applying generic error messaging to reduce account enumeration during sign-in and sign-up flows.

Can I use Better Auth security hardening in serverless environments?β–Ό

Better Auth security hardening works in serverless environments by configuring background task handling appropriately and optionally tracking IPs for rate limiting when deployed behind proxies.

Why do I need to configure a strong secret for Better Auth authentication?β–Ό

A strong Better Auth secret configured via environment variables reduces guessing risk by enforcing minimum length and entropy requirements, preventing unauthorized access and token leakage.