[PR #5695] feat: implement automatic server-side IP detection #14410

Closed
opened 2026-04-13 09:27:39 -05:00 by GiteaMirror · 0 comments
Owner

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

State: closed
Merged: Yes


Closes #5616

This PR updates the captcha plugin to automatically detect the user's IP address from server-side request headers. This fixes a security flaw and removes the need for a complex, insecure client-side workaround.

Before
Previously, the plugin required developers to manually pass the x-captcha-user-remote-ip header. This forced developers to create a separate API endpoint (e.g., /api/get-ip) to get the user's IP on the client, which could be easily spoofed and was inconsistent with the rate-limiting plugin.

After
The plugin now uses the existing getIp utility (the same one used by the rate-limiting plugin) to securely determine the IP from trusted headers (x-forwarded-for, etc.) based on the user's advanced.ipAddress configuration.


Summary by cubic

Automatically detect the user's IP on the server in the captcha plugin and forward it to providers. This removes the client-side IP header and closes a spoofing risk.

  • New Features

    • Use getIp to read trusted headers and send remoteip to the captcha provider.
    • Aligns IP detection with the rate-limiting plugin.
    • Update docs to reflect removal of x-captcha-user-remote-ip.
    • Add tests for Turnstile, hCaptcha, and CaptchaFox to verify remoteip is included.
  • Migration

    • Remove x-captcha-user-remote-ip from client requests; no separate IP endpoint needed.

Written for commit ff81c9e. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5695 **State:** closed **Merged:** Yes --- Closes #5616 This PR updates the captcha plugin to automatically detect the user's IP address from server-side request headers. This fixes a security flaw and removes the need for a complex, insecure client-side workaround. **Before** Previously, the plugin required developers to manually pass the x-captcha-user-remote-ip header. This forced developers to create a separate API endpoint (e.g., /api/get-ip) to get the user's IP on the client, which could be easily spoofed and was inconsistent with the rate-limiting plugin. **After** The plugin now uses the existing getIp utility (the same one used by the rate-limiting plugin) to securely determine the IP from trusted headers (x-forwarded-for, etc.) based on the user's advanced.ipAddress configuration. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Automatically detect the user's IP on the server in the captcha plugin and forward it to providers. This removes the client-side IP header and closes a spoofing risk. - **New Features** - Use getIp to read trusted headers and send remoteip to the captcha provider. - Aligns IP detection with the rate-limiting plugin. - Update docs to reflect removal of x-captcha-user-remote-ip. - Add tests for Turnstile, hCaptcha, and CaptchaFox to verify remoteip is included. - **Migration** - Remove x-captcha-user-remote-ip from client requests; no separate IP endpoint needed. <sup>Written for commit ff81c9e. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:27:39 -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#14410