better-auth-security-best-practices

SkillCloud & infra

This skill gives your AI security best practices for Better Auth, so it can review your authentication setup and help you harden it. It covers rate limits, secrets, CSRF protection, trusted origins, cookies, sessions, OAuth tokens, and audit logging. It is most useful when you want a security check on login protection, token handling, or deployment safety.

Available today. Use it from your connected AI after setup.

Add the skill, then ask your AI to review your Better Auth configuration for security issues. Mention the area you care about, such as login rate limits or session handling.

Then ask your AI: use the better-auth-security-best-practices skill

What your AI can do with it

  • Review your Better Auth security settings and flag weak spots
  • Set up rate limits to protect against brute-force login attempts
  • Harden cookie and session settings
  • Check that secrets and OAuth tokens are handled safely
  • Configure CSRF protection and trusted origins
  • Set up audit logging

What this skill tells your AI

The instructions your AI receives, as published by epicenterhq/epicenter in .agents/skills/better-auth-security-best-practices/SKILL.md and read by ahel’s review.

Reference Repositories

  • Better Auth — TypeScript authentication framework with plugins

Upstream Grounding

When Better Auth rate limiting, CSRF and origin checks, cookie settings, secret handling, token encryption, audit behavior, or deployment security defaults affect correctness, ask DeepWiki a narrow question against better-auth/better-auth before relying on memory. Use it to orient, then verify decisive details against local installed types, source, or official docs before changing code.

Read references/configuration.md when configuring or auditing an option: secrets, rate limiting, CSRF, trusted-origin syntax, sessions, cookies, OAuth token encryption, IP resolution, audit hooks, and a full worked configuration. Those are upstream defaults that move between versions, so confirm decisive ones against installed types before relying on them.

The two sections below are not upstream defaults. They are decisions this repository made, and getting either wrong is an account-takeover or open-redirect surface rather than a misconfiguration.

Do Not Trust Localhost In Production

trustedOrigins gates redirect/callback URLs, not only cookie CSRF, so a permanent localhost entry in a production list widens the open-redirect surface (and Better Auth's docs warn against it). Derive the dev-vs-prod fork from the deployment's own origin (its baked baseURL / resolved env origin), never from the request, and reuse the same fork as the cookie config:

// localhost dev origins are trusted ONLY on a local deployment.
function buildTrustedOrigins(baseURL: string): string[] {
  const prod = [...productionOrigins];
  return isLocalDeployment(baseURL) ? [...prod, ...devOrigins] : prod;
}

Account Linking and Provider Trust

Implicit account linking is an account-takeover surface. When a social sign-in matches an existing user by email, the link gate is (better-auth 1.5.6 oauth2/link-account):

block linking if: (!isTrustedProvider && !userInfo.emailVerified)
                  || accountLinking.enabled === false
                  || accountLinking.disableImplicitLinking === true

A provider in account.accountLinking.trustedProviders bypasses the incoming emailVerified check. So the rule is:

  • trustedProviders may contain ONLY identity providers that always assert a verified email. Google does. GitHub does NOT (it can return an unverified primary email), so never add github to trustedProviders; an untrusted GitHub identity still links when GitHub reports the email verified, which is the safe behavior.
  • Never list email-password in trustedProviders, and do not enable emailAndPassword without emailVerification.sendVerificationEmail + requireEmailVerification. On better-auth versions before the unconditional requireLocalEmailVerified gate (e.g. 1.5.6 has no such option), an attacker can pre-register an unverified local account at a victim's email and have the victim's later trusted-provider sign-in link into it.
  • If you have no email sender, prefer social-IdP-only sign-in over local credentials. That is what closes the takeover at the root.

Signals

GitHub stars
5k
Forks
378
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
better-auth-security-best-practices
Source
github.com/epicenterhq/epicenter