Skip to content

fix(auth): Better Auth 1.7 compatibility, auth hardening, dependency security updates - #15

Merged
TahubCS merged 3 commits into
mainfrom
claude/dazzling-hypatia-9kvwhh
Oct 17, 2026
Merged

TahubCS merged 3 commits into
mainfrom
claude/dazzling-hypatia-9kvwhh

Conversation

@TahubCS

@TahubCS TahubCS commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

The Better Auth 1.7.10 upgrade turned CI red on main and also breaks auth at runtime. This PR fixes both, hardens the auth configuration, and patches vulnerable dependencies. It has three commits, and each one passes lint, typecheck and tests on its own.

Deploy note: run bun run db:migrate on production. Better Auth 1.7 refuses every auth request while invitation.created_at is missing (migration 0029).

1. Make the 1.7 upgrade build and run

  • @better-auth/infra 0.2.14 → 0.4.20. 0.2.x pinned @better-auth/utils 0.4 and pulled in @better-auth/sso 1.6, which installed three copies of @better-auth/core. dashClient stopped matching BetterAuthClientPlugin, and authClient.organization disappeared from the client type.
  • experimental.joins moves to advanced.database.joins, its 1.7 location.
  • sendResetPasswordEmail → sendResetPassword. The old key was never a Better Auth option, so every password reset request failed with RESET_PASSWORD_DISABLED.
  • Migration 0029 adds invitation.created_at. Better Auth 1.7's organization plugin requires it, and the runtime schema check rejects auth requests without it. The migration is hand-written like 0012–0028 because the drizzle-kit snapshots stop at 0011.

2. Harden the auth configuration

  • https://*.vercel.app is no longer trusted in Better Auth or proxy.ts. Anyone can deploy there. With the old config, callbackURL on /sign-in/social and /send-verification-email accepted any *.vercel.app site. With password reset working again, redirectTo would also have sent reset tokens to such a site.
    • Trusted origins now come from one module, src/lib/trusted-origins.ts: exact origins only, this deployment's own VERCEL_* URLs, and an optional BETTER_AUTH_TRUSTED_ORIGINS list.
    • Loopback origins are dropped in production.
  • Better Auth's rate-limit counters are stored in Upstash Redis through an atomic consume, instead of per-instance memory. If Redis is unreachable it fails open, the same policy as the proxy.
  • Auth emails are sent after the response (advanced.backgroundTasks with Next's after), so response timing no longer reveals whether an email is registered.
  • Password reset revokes other sessions. Password length bounds are now explicit (8–128), and secure cookies are set explicitly in production.
  • Verification links last 24 hours, as the email says. The default was 1 hour.
  • OAuth errors redirect to /sign-in, which shows a fixed message. The error_description query value is not shown.
  • Removed the unused rateLimitUnavailable helper (the CI lint warning) and corrected SECURITY.md, which said rate limiting fails closed.

3. Dependency security updates

bun audit goes from 112 findings (6 critical) to 4 (none critical).

  • next 16.1.5 → 16.3.8, with eslint-config-next to match. This also brings patched sharp and postcss.
  • undici 6.21.3 → 6.28.1.
  • vitest 3.2.4 → 4.1.12. This fixes the critical UI-server advisory, removes tinypool, and fixes the @vitest/mocker advisory.
  • ai and @ai-sdk/google within their ranges, plus in-range updates of transitive packages.

The 4 remaining findings have no patched release and don't reach production code:

  • braces and esbuild only run in dev and build tooling.
  • sprintf-js is used for argparse help text via mammoth.
  • uuid is only used for v4 in svix.

Testing

  • Ran the CI checks job locally: lint (0 warnings), typecheck, SDK typecheck, unit tests and next build all pass.
  • Ran the CI migrations job on a fresh pgvector Postgres: migrations apply, the re-run is a no-op, and all 194 tests pass (including the DB integration tests).
  • End-to-end against the real auth.handler and proxy (NODE_ENV=production, real Postgres, real Redis behind the Upstash REST API):
    • Sign-up works.
    • Short passwords are rejected.
    • Password reset issues a token.
    • A *.vercel.app redirectTo or callbackURL gets a 403. The old config accepted it.
    • The proxy rejects a *.vercel.app origin. The old config let it through.
    • Sign-in is rate limited after 3 attempts per IP, with X-Retry-After.
    • With Redis down, sign-in still answers normally.
  • New unit tests in src/lib/__tests__/trusted-origins.test.ts.

Before deploying

  1. Run bun run db:migrate against production.
  2. Make sure UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN are set.
  3. If users reach the app from any *.vercel.app URL other than this deployment's own, add it to BETTER_AUTH_TRUSTED_ORIGINS.

The 1.7.10 bump turned CI red and breaks auth at runtime.

- Bump @better-auth/infra to 0.4.20. 0.2.x pinned @better-auth/utils
  0.4 and pulled @better-auth/sso 1.6, so three copies of
  @better-auth/core were installed and dashClient no longer matched
  BetterAuthClientPlugin. That also dropped authClient.organization.
- Move `experimental.joins` to `advanced.database.joins` (1.7 location).
- Rename `sendResetPasswordEmail` to `sendResetPassword`. The old key
  was never a Better Auth option, so every password reset request
  failed with RESET_PASSWORD_DISABLED.
- Add invitation.created_at (migration 0029). Better Auth 1.7 checks the
  schema before each auth request and rejects every request while the
  organization plugin's column is missing.
- Stop trusting https://*.vercel.app in Better Auth and the proxy.
  Anyone can deploy there, so it allowed redirects after OAuth sign-in
  and email verification to any Vercel site. With password reset
  working again, it would also have leaked reset tokens through
  `redirectTo`. Trusted origins now come from one module: exact
  origins only, this deployment's own Vercel URLs, and an optional
  BETTER_AUTH_TRUSTED_ORIGINS list. Loopback origins are dropped in
  production.
- Keep Better Auth's built-in rate-limit counters in Upstash Redis
  through an atomic `consume`. The default in-memory storage counts per
  serverless instance. A Redis outage fails open, like the proxy.
- Send auth emails through `advanced.backgroundTasks` and Next's
  `after`, so response timing does not reveal registered emails.
- Revoke other sessions on password reset. Set explicit password
  bounds and secure cookies in production.
- Make verification links last 24 hours, as the email promises. The
  default was 1 hour.
- Send OAuth errors to /sign-in and show a fixed message there.
- Remove the unused rateLimitUnavailable helper and correct SECURITY.md,
  which said rate limiting fails closed.
bun audit drops from 112 findings (6 critical) to 4 (none critical).

- next 16.1.5 -> 16.3.8 (also brings patched sharp and postcss), with
  eslint-config-next to match
- undici 6.21.3 -> 6.28.1
- vitest 3.2.4 -> 4.1.12 (critical UI-server file read; drops the
  vulnerable tinypool and fixes the @vitest/mocker path traversal)
- ai and @ai-sdk/google within range (@ai-sdk/provider-utils)
- in-range updates of ws, @xmldom/xmldom and other transitive packages

The 4 remaining findings have no patched release and only run in
tooling or unreachable paths: braces and esbuild (dev/build),
sprintf-js (argparse help text via mammoth) and uuid (v4 only in svix).
@vercel

vercel Bot commented Oct 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
supo Ready Ready Preview Oct 17, 2026 7:36pm UTC

Request Review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-17T19:36:56.432505Z 4533b4c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 42a560eb-dc08-4979-8fa3-635f1c77dfc5
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@TahubCS
TahubCS merged commit cbcb720 into main Oct 17, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
Preview — 4533b4c7 Deployed Oct 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant