Skip to content

fix(api): Turnstile sees the proxying client's visitor, not its egress IP - #1048

Merged
Ardnived merged 2 commits into
mainfrom
claude/fix-808-turnstile-client-ip
Oct 30, 2026
Merged

Ardnived merged 2 commits into
mainfrom
claude/fix-808-turnstile-client-ip

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • A clients request may name the visitor in x-client-ip; verifyTurnstileOrFail sends it as siteverify's remoteip, falling back to cf-connecting-ip. Any other caller's header is ignored, and an absent one never refuses a submission.
  • credentialRejection stays on cf-connecting-ip, and its comment now says why (a rejected credential is no authenticated client).
  • docs/rules/api-clients.md states the header a proxying consumer sends, that any key holder (the published Atlas key included) can set it, and that Cloudflare's verdict on a mismatched remoteip is unverified.

Closes #808. Unblocks sydevs/WeMeditateWeb#208.

Change outline

 verifyTurnstileOrFail(req, token)                 src/lib/antiSpam/antiSpamGuard.ts
-  remoteIp = cf-connecting-ip
+  forwardedIp = req.user?.collection === 'clients' ? x-client-ip : null
+  remoteIp    = forwardedIp || cf-connecting-ip    # '' falls back too

Tests

  • tests/unit/anti-spam-guard.spec.ts — forwarded, fallback, and ignored for a manager and an anonymous caller. Watched red with the collection gate removed (2 cases) and with the fallback-only read (1 case).
  • tests/int/user-submissions-create.int.spec.ts — a proxied create through the real write guard, with and without the header. The forwarded case watched red against the old read.
  • Lean gate green.

Review

Adversarial review run locally (the bot is out of usage). No blockers; adopted its two doc findings — the trust wording and a stale @param.

Notes for reviewer

  • Still owed (ticket step 4): a direct Atlas widget registration against the Railway preview. Unchanged path, but unchecked here.
  • The x-client-ip vs. x-forwarded-for choice and the credentialRejection carve-out are the ticket's recorded decisions.

🤖 Generated with Claude Code

Ardnived and others added 2 commits October 29, 2026 15:01
…s IP

`verifyTurnstileOrFail` sent `cf-connecting-ip` as siteverify's `remoteip`,
which for a consumer that proxies the create server-side is the proxy's own
address. An authenticated `clients` request may now name the visitor in
`x-client-ip`; any other caller's header is ignored, and an absent one falls
back to `cf-connecting-ip` and never refuses a submission.

`credentialRejection` stays on `cf-connecting-ip`, and its comment now says
why. `docs/rules/api-clients.md` states the header a proxying consumer sends,
and that Cloudflare's verdict on a mismatched `remoteip` is unverified.

Closes #808

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From review: the published Atlas key means an authenticated client is no
trust signal, so the comment and the rule say what the header is worth.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1048 October 29, 2026 22:14 Destroyed
@railway-app

railway-app Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-1048 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Oct 29, 2026 at 10:21 pm UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 29, 2026
@sydevs-bot

sydevs-bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 00:04Z review-pr · attempt 2 · session · done
  • 00:04Z review-pr · attempt 2 · session
  • 22:29Z review-pr · attempt 1 · session · timed out
  • 22:29Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Oct 29, 2026
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 2026
@Ardnived
Ardnived merged commit 815529b into main Oct 30, 2026
16 checks passed
@Ardnived
Ardnived deleted the claude/fix-808-turnstile-client-ip branch October 30, 2026 01:09
@sydevs-bot sydevs-bot moved this from Working to Done in SYDevelopers Technical Roadmap Oct 30, 2026
@Ardnived Ardnived removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 27, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-1048 — 002a3651 Deployed Oct 29, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(api): Turnstile sees the proxying client's IP, not the visitor's

2 participants