From ca538f2ab033560d7fcbc488cb3b16a56cd6f06b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 3 Dec 2026 21:27:00 -0700 Subject: app: recognise onion pages relayed by the UI without a client IP Onion requests never pass Cloudflare, so the UI has no cf-connecting-ip to forward when it relays them server-side, and they stopped being marked as Tor. Password logins from the onion site then failed the captcha check. Treat a request from the ui peer whose forwarded Host is an onion address as Tor, and key it on the Tor gateway's address. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SSfVopM1ZzXKZmLYU --- lib/app.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/app.ts b/lib/app.ts index b4595fc9..b653476f 100644 --- a/lib/app.ts +++ b/lib/app.ts @@ -115,12 +115,24 @@ app.addHook("onRequest", async (req) => { ?.trim() .replace(/^::ffff:/, ""); // SSR forwards the client IP in cf-connecting-ip without x-forwarded-for. + // Onion pages never pass Cloudflare, so the UI has no client IP to forward + // for them; it does forward the page's Host as x-forwarded-host. Only the + // ui peer is believed on that, and clearnet pages always reach ui with a + // coinos.io Host. const forwarded = req.headers["cf-connecting-ip"]; - const viaUi = uiPeers.has(peer) && typeof forwarded === "string" && untrusted.has(forwarded); + const fwdHost = String(req.headers["x-forwarded-host"] || ""); + const viaUi = + uiPeers.has(peer) && + ((typeof forwarded === "string" && untrusted.has(forwarded)) || + fwdHost.endsWith(".onion")); const viaTor = untrusted.has(peer) || (hop && untrusted.has(hop)) || viaUi; if (!viaTor) return; req.isTor = true; - req.headers["cf-connecting-ip"] = untrusted.has(peer) ? peer : viaUi ? forwarded : hop; + req.headers["cf-connecting-ip"] = untrusted.has(peer) + ? peer + : hop && untrusted.has(hop) + ? hop + : [...untrusted][0]; delete req.headers["x-forwarded-for"]; delete req.headers["rate-limit-by"]; }); -- cgit v1.2.3