Skip to content

Add Turnstile#7

Open
skyfallwastaken wants to merge 2 commits intoMostlime12195:mainfrom
skyfallwastaken:add-turnstile
Open

Add Turnstile#7
skyfallwastaken wants to merge 2 commits intoMostlime12195:mainfrom
skyfallwastaken:add-turnstile

Conversation

@skyfallwastaken
Copy link

@skyfallwastaken skyfallwastaken commented Mar 2, 2026

Add Cloudflare Turnstile integration for bot protection.

Configuration

Set the following environment variables:

Variable Description
NUXT_TURNSTILE_SECRET_KEY Cloudflare Turnstile secret key (server-side)
NUXT_PUBLIC_TURNSTILE_SITE_KEY Cloudflare Turnstile site key (client-side)
NUXT_SESSION_SECRET A random secret used to sign session tokens

You can get your Turnstile site key and secret key from the Cloudflare dashboard.

Copilot AI review requested due to automatic review settings March 2, 2026 21:32
@vercel
Copy link

vercel bot commented Mar 2, 2026

@skyfallwastaken is attempting to deploy a commit to the Karo Roghzai's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Cloudflare Turnstile-based bot protection by introducing a short-lived, HMAC-signed “session token” that must be presented to access protected AI endpoints.

Changes:

  • Added server-side session token signing/verification and a /api/session exchange endpoint backed by Turnstile siteverify.
  • Introduced server middleware to block bot user agents and require x-session-token for /api/ai and /api/embeddings.
  • Added client composables to solve Turnstile, cache/refresh the session token, and attach it to API requests.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
server/utils/session.js Implements HMAC-signed session tokens with expiry validation.
server/middleware/guard.js Enforces bot detection + session-token requirement on protected API routes.
server/api/session.post.js Verifies Turnstile token and issues short-lived signed session tokens.
nuxt.config.ts Adds runtime config entries for Turnstile keys and sessionSecret.
app/composables/useTurnstile.js Loads Turnstile script and solves an invisible widget to obtain a token.
app/composables/useSession.js Exchanges Turnstile token for session token; caches in memory/localStorage with refresh.
app/composables/storeConversations.js Adds x-session-token to background title-generation requests.
app/composables/message.js Adds x-session-token to /api/ai requests.
app/composables/memory.js Adds x-session-token to /api/embeddings requests.
package.json Bumps version and adds isbot dependency.
package-lock.json Adds isbot, but also includes metadata/peer-flag churn needing cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants