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

Closed
opened 2026-04-15 22:40:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8597
Author: @himself65
Created: 3/13/2026
Status: Merged
Merged: 3/13/2026
Merged by: @himself65

Base: canaryHead: fix/docs-ai-chat-improvements


📝 Commits (1)

  • 350ea15 fix(docs): improve AI chat security and cleanup leftover Inkeep dependency

📊 Changes

7 files changed (+55 additions, -3564 deletions)

View changed files

📝 .cspell/custom-words.txt (+1 -1)
📝 .cspell/tech-terms.txt (+1 -1)
📝 landing/lib/ai-chat/rate-limit.ts (+20 -14)
📝 landing/lib/ai-chat/route.ts (+16 -1)
📝 landing/package.json (+0 -1)
📝 pnpm-lock.yaml (+10 -3545)
📝 turbo.json (+7 -1)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8597 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/13/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/docs-ai-chat-improvements` --- ### 📝 Commits (1) - [`350ea15`](https://github.com/better-auth/better-auth/commit/350ea15c204a393f439c938192be928835a48193) fix(docs): improve AI chat security and cleanup leftover Inkeep dependency ### 📊 Changes **7 files changed** (+55 additions, -3564 deletions) <details> <summary>View changed files</summary> 📝 `.cspell/custom-words.txt` (+1 -1) 📝 `.cspell/tech-terms.txt` (+1 -1) 📝 `landing/lib/ai-chat/rate-limit.ts` (+20 -14) 📝 `landing/lib/ai-chat/route.ts` (+16 -1) 📝 `landing/package.json` (+0 -1) 📝 `pnpm-lock.yaml` (+10 -3545) 📝 `turbo.json` (+7 -1) </details> ### 📄 Description ## 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:40:23 -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#24986