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

Closed
opened 2026-04-17 22:38:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5695
Author: @GautamBytes
Created: 10/31/2025
Status: Merged
Merged: 10/31/2025
Merged by: @Bekacru

Base: canaryHead: feat/captcha-auto-ip


📝 Commits (3)

  • ac58d95 Auto-detect IP in captcha plugin
  • f92addf fix linting error
  • ff81c9e Correct remoteip assertions in tests

📊 Changes

3 files changed (+31 additions, -10 deletions)

View changed files

📝 docs/content/docs/plugins/captcha.mdx (+4 -1)
📝 packages/better-auth/src/plugins/captcha/captcha.test.ts (+25 -7)
📝 packages/better-auth/src/plugins/captcha/index.ts (+2 -2)

📄 Description

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.


🔄 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/5695 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 10/31/2025 **Status:** ✅ Merged **Merged:** 10/31/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/captcha-auto-ip` --- ### 📝 Commits (3) - [`ac58d95`](https://github.com/better-auth/better-auth/commit/ac58d95dc403cf3f5ae8ebaed96e1b4e1c140997) Auto-detect IP in captcha plugin - [`f92addf`](https://github.com/better-auth/better-auth/commit/f92addfbf460f86f30f22566604ac38312a3e4a5) fix linting error - [`ff81c9e`](https://github.com/better-auth/better-auth/commit/ff81c9e1a1396f4cb8cbbb5ff1896f132b02851f) Correct remoteip assertions in tests ### 📊 Changes **3 files changed** (+31 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/captcha.mdx` (+4 -1) 📝 `packages/better-auth/src/plugins/captcha/captcha.test.ts` (+25 -7) 📝 `packages/better-auth/src/plugins/captcha/index.ts` (+2 -2) </details> ### 📄 Description 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. --> --- <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-17 22:38:57 -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#31764