Skip to content

fix(server): forward the visitor's address to the submissions intake - #231

Merged
sydevs-bot merged 4 commits into
mainfrom
claude/fix-208-visitor-ip
Nov 17, 2026
Merged

sydevs-bot merged 4 commits into
mainfrom
claude/fix-208-visitor-ip

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Change outline

Behaviour — registerSubmissions

The forwarded header set gains one member, built from the Worker's own request rather than the browser's.

 POST /api/submissions                          server/api-routes.ts
   submissionSchema.safeParse(body) → 400 on failure
   read x-turnstile-token off the browser's request
+  read cf-connecting-ip off OUR request         # the edge wrote it; the browser cannot
   POST /user-submissions, depth 0
     headers:
       x-turnstile-token, when the browser sent one
+      x-client-ip, when we have an address      # omitted, never blanked
-      {} when it did not
     Origin / Referer                            # still withheld, both cases

Contract — what crosses the proxy

lib/submissions.ts gains the third name in the intake's wire contract. The first two are the browser's; this one is the proxy's own.

 SUBMISSION_PATH          '/api/submissions'     # browser → us
 TURNSTILE_TOKEN_HEADER   'x-turnstile-token'    # browser → us → SahajCloud
+CLIENT_IP_HEADER         'x-client-ip'          # us → SahajCloud, never from the browser

Upstream reads it only from an authenticated clients request, falls back to cf-connecting-ip, and requires it from nobody.

Preview

Both branch aliases exist now and answer 200. The earlier “no preview link” note is superseded: Workers Builds: wemeditate-web finished, and wemeditate-design recovered once #236 landed.

  • Contact Us — the page the proxied intake serves.
  • Ladle playground — untouched by this diff, linked because its build was the red check at 17:06.

Neither link exercises the change, for three separate reasons. Opening them proves the branch deploys, nothing more:

  • No form renders there. /contact-us answers 200, but its SahajCloud content carries no form block on this data, so there is nothing to submit.
  • The change leaves no visible mark. A submitted form looks identical with or without the header.
  • Confirming the forward end to end writes to production. This run treats production as read-only, so it was not attempted. See Manual verification.

Test results

  • Lean gate: ✓ .claude/skills/pr-prep/check.sh — lint, tsc --noEmit, vitest run (95 files, 953 tests)
  • Targeted specs: 33 passed (server/api-routes.test.ts, lib/submissions.test.ts)
  • Build: N/A — lean gate only; CI runs the full suite

The forward assertion was watched failing before the implementation went in, and the fixture spells CF-Connecting-IP as Cloudflare sends it rather than as the route reads it.

Manual verification

  1. Submit a real form wherever one is authored — not this PR's preview, whose /contact-us carries no form block — and confirm the row reaches SahajCloud. This is the one acceptance item automated tests cannot reach. It writes to production, so it needs a human.
  2. On that row, confirm the submission was not refused. Turnstile's verdict is the thing this PR changes the input to.

Notes for reviewer

Three review lenses disagreed about CLIENT_IP_HEADER, so the reasoning is worth your eye:

  • Kept the constant in lib/submissions.ts, as the ticket directs. One lens argued for moving it beside HTTP_METHOD_OVERRIDE_HEADER in the route (no browser consumer), another for deleting it in favour of a literal (one in-repo writer). Dismissed both: x-client-ip is a name this repo and SahajCloud must agree on, which is exactly what that module claims to own, and the bundle cost is nil — it is a named export no client import references, so Rollup drops it.
  • Accepted the defect underneath that argument. The forward assertion was built from the same constants the route forwards with, so renaming a constant's value kept the suite green while production lost the header. Both names are now literals in the test, matching how the same file already pins X-Payload-HTTP-Method-Override. That is the second commit.
  • Cut the constant's docblock to a pointer (80539f2), on the adversarial review's one finding. The same rationale stood in three places for a two-line change. What remains at the constant is the one fact a reader of the three exported names cannot re-derive: this one travels outward, from the proxy, while its two neighbours come from the browser.

Exposures, named rather than guarded against — the calls are yours:

  • remoteip does not become trustworthy. Upstream's own docs/rules/api-clients.md notes any key holder can set x-client-ip. It is a scoring hint; nothing should later be built on it (rate limiting, abuse attribution, geo) without a real binding.
  • This could in principle fail closed. If Cloudflare does validate remoteip against the address that solved the challenge — both repos record this as unverified — a visitor whose edge-seen address changes between solve and submit (IPv4/IPv6 switch, mobile handoff) would newly see captcha_failed. Previously the mismatch was uniform and tolerated; now it is per-visitor. Rollback is reverting the first commit; nothing else depends on the header.
  • The rate-limit bucket is unchanged. The edge still keys on the address SahajCloud sees, i.e. ours. Stated in the AGENTS.md block.
  • Sentry needs no change. CREDENTIAL_HEADER_SNIPPETS scrubs the inbound headers Sentry records; cf-connecting-ip already arrived before this change, and x-client-ip is outbound only.
Detail

One discrepancy with the ticket, recorded rather than acted on. The ticket reasons that the header must be omitted because "SahajCloud falls back on absence, and an empty string is not absence." Upstream actually reads forwardedIp || req.headers.get('cf-connecting-ip'), so an empty string is falsy and does fall back. The ticket's conclusion is still the one implemented — omitting is correct regardless, and a blank value is a claim about the visitor we cannot make — but the stated mechanism is not what the upstream code does.

No new layer was added. The route reads 'cf-connecting-ip' inline: it is the only place in the repo that knows Cloudflare's inbound spelling, and at one reader a visitorIp(c) helper would be machinery for its own sake. A second proxied public write is the trigger to extract one.

Why not lower in the stack. Putting the forward in payload-client.ts or a Hono middleware would ship a visitor IP on every SSR read, which uses it for nothing — a data-minimisation regression, and a cache-shape hazard against the 600s edge cache in front of SahajCloud. The membership rule is narrow: a call whose upstream handler scores a human challenge must name the human. It has one member.

Efficiency, checked and clear. Hono's header() is a direct Headers.get; the read sits after the schema's early return, so a rejected body never pays for it. No new import module, so the Worker graph is unchanged.

Closes #208

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjVH1P2NYntW3TLRC8L

The proxy sent SahajCloud exactly one browser header, the captcha token,
so SahajCloud read cf-connecting-ip off its own request and handed
Turnstile's remoteip this Worker's egress address — one nobody who
solved the challenge ever had.

It now forwards its own incoming cf-connecting-ip as x-client-ip, the
header sydevs/SahajCloud#808 added to receive it. The header is omitted,
not blanked, when our own request carries none: upstream falls back to
the address it sees, and a blank value is a claim about the visitor we
cannot make. Origin and Referer still do not cross over.

server/AGENTS.md's warning described the gap as open and asserted that
Cloudflare validates remoteip against the address that solved the
challenge. #808 settled that as unverified and built so nothing depends
on it, so the block now says what the Worker sends and names the two
limits that remain.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVH1P2NYntW3TLRC8L
The forward assertion was built from the same constants the route forwards
with, so renaming a constant's value kept the suite green while every
submission lost the header upstream. Both names are now spelled out, which
is how api-routes.test.ts already pins X-Payload-HTTP-Method-Override and
entry.test.ts pins x-turnstile-token.

Also trims three comments to the why they carry: the route docblock no
longer names the constant declared two lines below it, and no longer says
the edge sets cf-connecting-ip — true on Cloudflare, not under `pnpm dev`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVH1P2NYntW3TLRC8L
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 13, 2026
@sydevs-bot

sydevs-bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running
CI fix 1

recent dispatches
  • 19:38Z address-review · attempt 1 · session · done
  • 19:38Z address-review · attempt 1 · session
  • 19:32Z review-pr · attempt 1 · session · done
  • 19:32Z review-pr · attempt 1 · session
  • 17:06Z fix-ci · attempt 1 · session · done

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

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Smoke (ladle) is red for a cause outside this diff, so nothing was pushed.

Cloudflare's wemeditate-design build failed at 16:53:40 UTC, two seconds after the push. Discovery then found no preview, and the check reddened at 17:06:13.

The same build failed on #232 at 16:59:46 — another branch, another diff. Workers Builds: wemeditate-web succeeded on both heads, and the gate job ran pnpm ladle:build and pnpm check:wrangler green on a7bbc7c, so the playground builds from the repository.

Filed as #233. The build log sits on the Cloudflare dashboard, which this run holds no credential to read.

This branch is one commit behind main (916bf30). The merge was left unpushed: a merge ships only with work.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 13, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 13, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web 80539f2 Commit Preview URL

Branch Preview URL
Nov 15 2026, 07:43 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-design 80539f2 Commit Preview URL

Branch Preview URL
Nov 15 2026, 07:42 PM

@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 15, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 15, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 15, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧐 Adversarial review

The diff is the ticket, no larger: one header read, one spread, and the doc the ticket named. Three of the four acceptance criteria are pinned by a test that spells both wire names as literals, so a rename of either constant cannot keep it green. The consumer side agrees — x-client-ip is read only from a clients caller and falls back to cf-connecting-ip (SahajCloud main, src/lib/antiSpam/antiSpamGuard.ts:71), matrix at tests/int/user-submissions-create.int.spec.ts:1088. CLIENT_IP_HEADER has one in-repo consumer, which is usually folded in here; held, because the name is a two-repo agreement and that is what lib/submissions.ts owns.

One call is yours, and is not a finding. If Cloudflare does check remoteip against whoever solved the challenge — both repos record this as unverified — a visitor whose edge address changes between solve and submit newly sees captcha_failed. The mismatch used to be uniform and tolerated. Nothing automated can settle it, so the body's manual step is the only proof this ships correct.

Findings

  • consider — one rationale written out three times, for a two-line change (lib/submissions.ts:39).

What was checked

  • Ticket #208 against the diff: all four criteria met, Origin/Referer still absent in both forwarded cases.
  • Ladder on the two new pieces: CLIENT_IP_HEADER (above) and the local clientIp. c.req.header is Hono's own case-insensitive read, so nothing was hand-rolled. No new module, import or dependency.
  • server/api-routes.ts whole: cf-connecting-ip has exactly one reader in the repo, and the sibling proxy (/api/live-preview/populate) is not captcha-guarded, so it is correctly outside.
  • Branch preview answers 200. The change leaves no visible mark, so nothing further was read there.
  • Reviewer profile read.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread lib/submissions.ts Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 15, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 15, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 15, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 15, 2026
The same reasoning stood in three places for a two-line change: the route
docblock a reader of the forward hits, `server/AGENTS.md`, and this
constant. The constant keeps only what a reader at the three exported
names cannot re-derive — that this one travels outward, from the proxy,
while its two neighbours come from the browser.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXsTrPq17TZUDmyqxf
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the adversarial review's one finding, and refreshed the body.

Adopted — one rationale written out three times (lib/submissions.ts:39). Cut to a pointer in 80539f2. The route docblock and server/AGENTS.md keep the full why; the constant keeps only that this name travels outward, from the proxy.

Body refreshed, on two things that had gone false. Both branch previews now answer 200, so the "no preview link" note is replaced by the two aliases — neither exercises the change, and the body says why. And Manual verification step 1 sent a human to submit the contact form on this preview: /contact-us there carries no form block, so that step now says a real form is needed elsewhere.

Lean gate green — 95 files, 953 tests. No security review: this push touches lib/ only, off this repo's trigger paths. Docs checked, nothing stale.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 15, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review November 15, 2026 19:45
@sydevs-bot
sydevs-bot requested a review from Ardnived November 15, 2026 19:45
@sydevs-bot
sydevs-bot enabled auto-merge November 15, 2026 19:45
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 15, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 17, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 18d739b Nov 17, 2026
42 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-208-visitor-ip branch November 17, 2026 23:25
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 17, 2026
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(server): the submissions proxy sends SahajCloud its own IP, not the visitor's

3 participants