[PR #8597] fix(docs): improve AI chat security and cleanup #16332

Closed
opened 2026-04-13 10:29:45 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8597

State: closed
Merged: Yes


Summary

Follow-up improvements to #8523 (custom AI chat):

  • Validate request body: Messages must be a non-empty array (max 100) to prevent abuse
  • Lazy-init Redis/Ratelimit: Avoids module-level crashes when Upstash env vars are missing (e.g. local dev, build time)
  • Prefer x-real-ip over x-forwarded-for: Vercel sets x-real-ip and it cannot be spoofed by clients, making rate limiting more robust
  • Remove @inkeep/ai-sdk-provider: Leftover dependency no longer used after the Inkeep → OpenRouter migration
  • Add env vars to turbo.json: OPENROUTER_API_KEY, UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN added to passThroughEnv for the docs build
  • Fix trailing newlines: .cspell/custom-words.txt and .cspell/tech-terms.txt were missing final newlines

Test plan

  • Verify pnpm install succeeds with updated lockfile
  • Verify docs AI chat works in dev mode (rate limiter skipped, no Redis needed)
  • Verify rate limiting works in production with Upstash credentials
  • Verify malformed POST requests to /api/docs/chat return 400
**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8597 **State:** closed **Merged:** Yes --- ## Summary Follow-up improvements to #8523 (custom AI chat): - **Validate request body**: Messages must be a non-empty array (max 100) to prevent abuse - **Lazy-init Redis/Ratelimit**: Avoids module-level crashes when Upstash env vars are missing (e.g. local dev, build time) - **Prefer `x-real-ip` over `x-forwarded-for`**: Vercel sets `x-real-ip` and it cannot be spoofed by clients, making rate limiting more robust - **Remove `@inkeep/ai-sdk-provider`**: Leftover dependency no longer used after the Inkeep → OpenRouter migration - **Add env vars to `turbo.json`**: `OPENROUTER_API_KEY`, `UPSTASH_REDIS_REST_URL`, `UPSTASH_REDIS_REST_TOKEN` added to `passThroughEnv` for the docs build - **Fix trailing newlines**: `.cspell/custom-words.txt` and `.cspell/tech-terms.txt` were missing final newlines ## Test plan - [x] Verify `pnpm install` succeeds with updated lockfile - [x] Verify docs AI chat works in dev mode (rate limiter skipped, no Redis needed) - [x] Verify rate limiting works in production with Upstash credentials - [x] Verify malformed POST requests to `/api/docs/chat` return 400
GiteaMirror added the pull-request label 2026-04-13 10:29:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16332