Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

610 B
Raw Blame
import { isIP } from "node:net";

/** Forwarded attribution requires an explicit proxy count and a firewalled origin. Never authorization. */
export function clientIp(req: Request): string {
  const trusted = Number(process.env.OS_TRUSTED_PROXY_HOPS ?? "0");
  const trail = req.headers.get("x-forwarded-for") ?? "";
  if (!Number.isInteger(trusted) || trusted < 1 || trusted > 16 || trail.length > 4096) return "unknown";
  const hops = trail.split(",").map(value => value.trim());
  const address = hops[hops.length - trusted];
  return hops.length <= 32 && address && isIP(address) ? address : "unknown";
}