better-auth-security-best-practices

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

14|5|Updated Mar 16, 2026
One-click install
npx skills add https://github.com/TheCardGoat/lorcana-simulator --skill better-auth-security-best-practices-thecardgoat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-security-best-practices
Source: https://github.com/TheCardGoat/lorcana-simulator/tree/main/.agents/skills/better-auth-security-best-practices
Command: npx skills add https://github.com/TheCardGoat/lorcana-simulator --skill better-auth-security-best-practices-thecardgoat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you prevent account takeover and session abuse by hardening a Better Auth deployment against brute force, CSRF, malicious redirects, insecure cookies, and weak token handling.

Core Features & Use Cases

  • Secure secret management: Use strong secrets via config or environment variables, reject placeholder secrets, and avoid committing secrets to version control.
  • Brute-force resistance with rate limiting: Enable production-safe rate limiting with configurable storage and per-endpoint custom rules for sensitive auth routes.
  • CSRF protection and origin hardening: Keep CSRF checks enabled and restrict requests using trusted origin validation, including support for wildcard and dynamic trusted origins.
  • Session and cookie security: Configure secure session lifetimes, choose safe cookie caching strategies, and enforce secure cookie attributes with optional cross-subdomain sharing.
  • OAuth/social provider security: Ensure safe state handling, optionally encrypt OAuth tokens, and apply best practices for mobile flows.
  • Attack visibility via auditing: Add database hooks to record security-relevant events like session creation/revocation and email changes.

Quick Start

Use the better-auth-security-best-practices skill to generate a complete Better Auth configuration that enables rate limiting, keeps CSRF protection on, sets trusted origins, hardens sessions/cookies, encrypts OAuth tokens, and adds audit logging.

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 to prevent brute force attacks?

Configure production rate limiting in Better Auth by defining storage options and custom per-endpoint rules for sensitive routes. This stops brute force attacks by throttling malicious repeated login attempts.

What is the best way to secure session cookies and enable OAuth token encryption in Better Auth?

Secure session cookies by enforcing safe cookie attributes and secure session lifetimes, optionally sharing across subdomains. Encrypt OAuth tokens by configuring safe state handling within your Better Auth deployment.

How does CSRF protection and trusted origin validation work in Better Auth?

CSRF protection in Better Auth works by keeping built-in checks enabled and restricting requests via trusted origin validation. You can configure trusted origins using wildcards or dynamic functions to prevent malicious redirects.

Can I use Better Auth security configurations for production setups requiring IP-aware controls?

Yes, Better Auth security configurations support production setups requiring IP-aware controls. You can configure IP tracking headers and optional database hooks to record security-relevant events for attack visibility and auditing.

Do I need to validate secrets from environment variables before deploying Better Auth?

Yes, you must validate secrets sourced from environment variables or config before deploying Better Auth. Secure secret management requires rejecting placeholder secrets and avoiding committing secrets to version control.