diff options
Diffstat (limited to 'lib/app.ts')
| -rw-r--r-- | lib/app.ts | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -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"]; }); |
