aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-12-03 21:27:00 -0700
committerAdam Soltys <[email protected]>2026-12-03 21:27:00 -0700
commitca538f2ab033560d7fcbc488cb3b16a56cd6f06b (patch)
treee0f4cfbea7b124369268ea9d2853892d3573746e /lib
parent27e054deed4d7e897af7426e14eb1212c8de8644 (diff)
downloadcoinos-server-ca538f2ab033560d7fcbc488cb3b16a56cd6f06b.tar.gz
coinos-server-ca538f2ab033560d7fcbc488cb3b16a56cd6f06b.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SSfVopM1ZzXKZmLYU
Diffstat (limited to 'lib')
-rw-r--r--lib/app.ts16
1 files changed, 14 insertions, 2 deletions
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"];
});