In short
- Better Auth is a library, not a hosted service. Its own docs put it this way: your auth lives in your codebase. So do its patches, its secret and its configuration.
- Set
BETTER_AUTH_SECRETto a random value. The docs list a known default secret used when none is set, and say production throws an error without one. - Rate limiting is on in production and off in development. It counts in memory by default, which the docs say may not suit serverless hosts, and it trusts
X-Forwarded-Forunless you configure it. - Two critical advisories were published in autumn 2026: GHSA-965c-763c-88jm (fixed in 1.7.7) and GHSA-4wq4-2ppv-q3hg in the Expo plugin (fixed in 1.7.16). Both let a stranger sign in as another user under specific configurations.
- Never set
disableCSRFCheckordisableOriginCheckto make an error go away, and keeplocalhostout oftrustedOriginsin production.
On this page
- What Better Auth is
- The secret: one value signs everything
- Trusted origins and the two switches to leave alone
- Rate limiting: on in production, with two catches
- Published advisories, and the versions that fix them
- How to check your own app
- After sign-in: Better Auth does not write your authorization
- Better Auth security checklist
- What Keybrum tests on a Better Auth app, and what it does not
- Questions
- Sources
What Better Auth is
Better Auth describes itself as a framework-agnostic, universal authentication and authorization framework for TypeScript. It is open source under the MIT licence. You install it from npm, mount its handler on a route of your app, usually /api/auth, and it stores users, sessions and accounts in your own database. Features such as two-factor, organizations, SSO or passkeys come as plugins.
The project moves fast. Version 1.0 was published on npm in November 2024. On 13 November 2026 the latest stable release was 1.7.23, a 1.8 beta was in progress, and the GitHub repository had about 30,700 stars.
That popularity is why Better Auth security deserves ten minutes of your time. With a hosted provider such as Clerk or Supabase Auth, the vendor patches the sign-in server for you. With a library, the sign-in server is your app. A fix exists only once you upgrade and deploy. For the trade-offs of the hosted route, see Clerk vs Supabase Auth.
| Area | What Better Auth does by default | What stays yours |
|---|---|---|
| Passwords | Hashes with scrypt, minimum length 8 | Email verification, password policy beyond length |
| Sessions | Stored in your database, expire after 7 days, extended as they are used | Revoking sessions, choosing shorter lifetimes |
| Cookies | HttpOnly, SameSite=Lax, Secure when the base URL is HTTPS | Serving the app over HTTPS, cross-subdomain settings |
| Cross-site requests | Checks the Origin header against trusted origins | The trustedOrigins list, and your own custom routes |
| Brute force | Rate limiting in production, stricter on sign-in | Storage for the counters, the IP header your proxy sets |
| Signing | Signs and encrypts with one application secret | Generating, storing and rotating that secret |
| Patches | Publishes advisories and fixed versions | Upgrading, for the core and every plugin |
The secret: one value signs everything
Better Auth reads its secret from BETTER_AUTH_SECRET, then AUTH_SECRET. The options reference says that when neither is set, it falls back to a default value printed in the docs, and that in production it throws an error. A preview or staging deploy that does not run in production mode can therefore run on a secret everyone knows. Set a real one in every environment that the internet can reach.
# Generate a secret (the command from Better Auth's docs)
openssl rand -base64 32
# Then set it on your host, never in the repository
BETTER_AUTH_SECRET=...
BETTER_AUTH_URL=https://app.example.comThe secret must never reach the browser. No NEXT_PUBLIC_ or VITE_ prefix, no commit. If it leaks, anyone can produce values your server will accept as signed. Better Auth supports rotating it without a database migration through versioned secrets, so rotation is practical. Our guide on what to do with a leaked key gives the order to follow.
Trusted origins and the two switches to leave alone
By default Better Auth trusts the base URL of your app and rejects state-changing requests whose Origin is not trusted. You add more origins with trustedOrigins, as exact values or wildcard patterns. Three details from the security reference matter:
- Localhost in production. The docs say not to leave the localhost origin in the trusted origins list of a production auth instance.
- Wildcards are wide.
https://*.example.comtrusts every HTTPS subdomain, including one that a forgotten DNS record hands to someone else. A pattern with no protocol accepts any protocol. - Your own routes are not covered. Calls made directly through
auth.apiskip these checks. If you write a route that changes state for a browser session, check the origin yourself.
Rate limiting: on in production, with two catches
Better Auth's rate limiter is enabled in production and disabled in development. The default is 100 requests per 10-second window, with stricter rules on sensitive paths: /sign-in/email allows 3 requests per 10 seconds. That is a sound default. Two things can quietly weaken it.
- Memory storage on serverless. Counters are kept in memory by default. The docs say this may not be suitable for many use cases, particularly in serverless environments, where each instance has its own memory. Use the database or secondary storage option on Vercel, Netlify and similar hosts.
- A header the client can forge. The client address is read from
X-Forwarded-Forby default. Per-client limits only work if your proxy overwrites that header, or if you list your proxies intrustedProxies. - Server-side calls are not limited. The limiter applies to requests from clients. A route of yours that calls
auth.apion the server needs its own limit.
import { betterAuth } from "better-auth";
export const auth = betterAuth({
secret: process.env.BETTER_AUTH_SECRET,
baseURL: process.env.BETTER_AUTH_URL,
// Exact origins. No localhost, no broad wildcard.
trustedOrigins: ["https://app.example.com"],
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
},
advanced: {
ipAddress: {
// Only a header your proxy sets on every request
ipAddressHeaders: ["x-forwarded-for"],
},
},
// rateLimit: choose database or secondary storage on serverless hosts
});Published advisories, and the versions that fix them
Better Auth publishes its vulnerabilities as GitHub security advisories, with affected versions, fixes and credit to the reporters. That is the right practice, and it gives you a list to check. On 13 November 2026 the list ran to five pages, with a large batch published on 3 November 2026. Many concern optional plugins, so read the titles against the plugins you use. Two are rated critical, both with a CVSS score of 9.1.
| Advisory | What it allowed | Who was affected | Fixed in |
|---|---|---|---|
| GHSA-4wq4-2ppv-q3hg, critical, 3 November 2026 | A public endpoint of the Expo plugin signed a value taken from the request with the application secret, and could redirect to external sites. An attacker who knew a user's email address could sign in as that user | Servers that register the expo() plugin from @better-auth/expo | 1.7.16 (upgrade better-auth and @better-auth/expo together) |
| GHSA-965c-763c-88jm (CVE-2026-114607), critical, 30 September 2026 | An OAuth sign-in state value was accepted as a Magic Link token, so an attacker who knew a user's email could get a session without reading that mailbox | Apps with the Magic Link plugin, at least one social or generic OAuth provider, and OAuth state stored in the database | 1.7.7 |
Other advisories rated high in the same period concern the SSO plugin, the OAuth Proxy plugin and the Electron integration. The full list is on the repository's security advisories page.
How to check your own app
- 1
Read the installed versions
Run the first command below in your project. Compare with the fixed versions above, and keep the core and every
@better-auth/*package on the same release. - 2
Search your auth config for the risky options
Look for
disableCSRFCheck,disableOriginCheck,localhostand*in the file where you callbetterAuth. Each hit needs a reason. - 3
Check the secret in every environment
On your host, confirm
BETTER_AUTH_SECRETis set for production and for previews, with different values, and that neither is the default from the docs. - 4
Test the limiter on your own sign-in
Send five wrong sign-ins for an address that does not exist, as in the last command. With the default rule, the later answers should be 429. If all five are refused with the same code, the limiter is not counting on your host.
# 1. Installed versions, from the lockfile
npm ls better-auth @better-auth/expo
# 2. Risky options in your code
grep -rnE "disableCSRFCheck|disableOriginCheck|trustedOrigins" src/ lib/ app/ 2>/dev/null
# 3. Your own sign-in, five wrong attempts for a made-up address
for i in 1 2 3 4 5; do
curl -s -o /dev/null -w "%{http_code}\n" -X POST \
"https://YOUR_APP/api/auth/sign-in/email" \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"wrong-password-1"}'
done/api/auth.After sign-in: Better Auth does not write your authorization
A correct Better Auth setup proves who the user is. It does not decide which records that user may open. In the generated apps we look at, the common leak sits one step later: an API route that checks for a session and then returns whatever id the client asked for, or a route with no session check at all. That is an IDOR, and no auth library prevents it.
On Next.js, do not rely on middleware alone to protect pages either. CVE-2025-29927 showed how a middleware check can be skipped on self-hosted apps. Check the session next to the data, in each route handler and server action. The Next.js security guide covers the pattern.
Better Auth security checklist
better-authand every@better-auth/*plugin on the latest release of your line, at least 1.7.16BETTER_AUTH_SECRETrandom, set in every reachable environment, never in the repository or the browser bundleBETTER_AUTH_URLset explicitlytrustedOriginslists exact production origins: no localhost, no broad wildcarddisableCSRFCheckanddisableOriginCheckabsent- Rate limit storage moved out of memory on serverless hosts, and the IP header set by your proxy
- Email verification required before a session, if accounts give access to anything private
- Only the plugins you use are registered, and the advisories for each one are read
- Every API route and server action checks the session and the record's owner
- The repository's security advisories watched on GitHub
What Keybrum tests on a Better Auth app, and what it does not
Keybrum is the automated pentest we build for apps made with AI. It has one attack written for Better Auth, and it is the Expo proxy flaw above.
On an app whose owner has proved ownership, it sends one request to the Expo authorization proxy under the usual base paths (/api/auth, /auth and /api/v1/auth), with a placeholder address and a random value it generated itself. A redirect to the placeholder proves the open redirect. A cookie with the shape of a Better Auth signature indicates that the endpoint signs what it is given. No real account is touched, and the cookie value is masked and never stored. The report states that the signing proof is a heuristic and asks you to confirm the @better-auth/expo version and rotate the secret.
It does not test the other advisories, the strength of your secret, your trusted origins or your plugin configuration. The rest of its library is not specific to Better Auth: it attacks what sits behind the login, such as API routes called with no session and records read across two accounts. A one-time report on one app is €49, and plans start at €29 a month excluding VAT.
Questions
Is Better Auth safe to use in production?
Its defaults are careful: scrypt hashing, HttpOnly cookies, origin checks and rate limiting in production. It has also had critical advisories in 2026, each published openly with a fixed version. It is a reasonable choice if you keep it updated, set a real secret and review the plugins you enable.
What is GHSA-4wq4-2ppv-q3hg?
A critical advisory (CVSS 9.1) published on 3 November 2026 for the @better-auth/expo plugin. A public endpoint signed a caller-supplied value with the application secret and could redirect to external sites, which let an attacker who knew a user's email sign in as that user. It is fixed in 1.7.16, and the advisory tells affected apps to rotate the secret.
Is Better Auth free and open source?
Yes. The code is on GitHub under the MIT licence and the package is on npm. You run it in your own app with your own database, so there is no per-user fee for the library itself.
Does Better Auth have rate limiting?
Yes, built in. It is enabled in production and disabled in development, with a default of 100 requests per 10 seconds and 3 per 10 seconds on email sign-in. Counters are in memory by default, so configure database or secondary storage on serverless hosts.
What happens if I do not set BETTER_AUTH_SECRET?
The options reference says Better Auth falls back to a default secret that is printed in its documentation, and throws an error in production. Any environment running on the default is signing with a public value. Generate one with openssl rand -base64 32.
Better Auth, Clerk or Supabase Auth?
Better Auth gives you the code and the user table, and the duty to patch. Clerk and Supabase Auth run the sign-in service for you. Whichever you choose, the checks on who may read which record are yours to write and to test.
Sources
- 1.Introduction, Better Auth Docs
- 2.Security, Better Auth Docs
- 3.Options, Better Auth Docs
- 4.Rate Limit, Better Auth Docs
- 5.Security advisories, GitHub, better-auth/better-auth
- 6.@better-auth/expo: Authorization proxy can sign values it did not issue (GHSA-4wq4-2ppv-q3hg), GitHub, better-auth/better-auth
- 7.better-auth: OAuth state can be used as a Magic Link to sign in as another user (GHSA-965c-763c-88jm), GitHub, better-auth/better-auth
- 8.better-auth, npm