Skip to content

Conversation

@mbifulco
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings November 13, 2025 14:48
@vercel
Copy link

vercel bot commented Nov 13, 2025

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

Project Deployment Preview Comments Updated (UTC)
mikebifulco-com-bnbu Error Error Nov 13, 2025 3:17pm

Copy link
Contributor

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

This PR adds bot detection and protection to the application using the botid package (v1.5.10). The integration aims to protect API endpoints and routes from automated bot traffic.

  • Integrates botid library at both the Next.js config level and individual API routes
  • Adds bot detection check to the Resend webhook handler
  • Includes client-side instrumentation for route protection

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
package.json Adds botid dependency (^1.5.10)
pnpm-lock.yaml Updates lock file with botid package resolution and dependencies
next.config.mjs Wraps config with withBotId HOC; adds picsum.photos to image domains (unrelated); duplicate images.unsplash.com entry
src/pages/api/inbound_webhooks/resend.ts Adds bot detection check before processing webhook requests
src/utils/resend.test.ts Refactors Resend mock from arrow function to regular function for proper context binding
instrumentation-client.ts New file configuring client-side bot protection for various routes
next-env.d.ts Auto-generated Next.js type definition update
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

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

Comment on lines +7 to +9
// Example: Protect webhook endpoints
{ path: '/api/inbound_webhooks/resend', method: 'POST' },

Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

Protecting the webhook endpoint /api/inbound_webhooks/resend from the client-side doesn't make sense because:

  1. Webhooks are server-to-server communications initiated by Resend, not by browsers
  2. Client-side bot protection cannot intercept or validate server-to-server requests
  3. The actual bot protection is already implemented on the server side (in the API route handler)

This route should be removed from the client-side protection list. Client-side protection should only be used for routes that browsers directly access.

Suggested change
// Example: Protect webhook endpoints
{ path: '/api/inbound_webhooks/resend', method: 'POST' },

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +69
// Verify this request is not from a bot
const verification = await checkBotId();
if (verification.isBot) {
console.warn('Bot detected attempting to access webhook');
return res.status(403).json({ error: 'Access denied' });
}
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The bot detection check is performed before webhook signature verification. This creates a security concern because:

  1. Attackers can bypass signature verification by being flagged as a bot
  2. The webhook signature verification (line 77) validates that the request actually came from Resend

Consider moving the bot check after the signature verification to ensure all requests are authenticated first. The order should be:

  1. Verify webhook signature
  2. Check for bot traffic
  3. Process the webhook

Copilot uses AI. Check for mistakes.
}

// Verify this request is not from a bot
const verification = await checkBotId();
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The checkBotId() function is called without passing any request context. Depending on the botid library's API, this function may need the request object or headers to properly detect bots based on user-agent, IP address, or other request metadata.

Please verify that checkBotId() can access request context through Next.js internals, or update the call to pass the necessary request information: checkBotId(req) or similar.

Suggested change
const verification = await checkBotId();
const verification = await checkBotId(req);

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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