Merge pull request #115 from anurag008w/codex/fix-bugs-in-start.sh,-health-server.js,-env-builder.js,-env-y8p5pn
Browse filesFiles changed (3)
21 unmodified lines222324252627282930313233218 unmodified lines252253254255256257258259260407 unmodified lines6686696706716726736745 unmodified lines68068168268368468568621 unmodified linesconst JUPYTER_BASE = normalizeBase(process.env.JUPYTER_BASE, "/terminal");const GATEWAY_TOKEN = (process.env.GATEWAY_TOKEN || "").trim();const DEV_MODE_ENABLED = isTrue(process.env.DEV_MODE);// Default true. Only false when DEV_MODE=false or HUGGINGCLAW_JUPYTER_ENABLED=false is explicitly set.// HUGGINGCLAW_JUPYTER_ENABLED=true is the explicit user override and always wins.const JUPYTER_ENABLED =/^(true|1|yes|on)$/i.test(String(process.env.HUGGINGCLAW_JUPYTER_ENABLED || "").trim()) ||(!/^(false|0|no|off)$/i.test(String(process.env.DEV_MODE || "").trim()) &&!/^(false|0|no|off)$/i.test(String(process.env.HUGGINGCLAW_JUPYTER_ENABLED || "").trim()));const startTime = Date.now();218 unmodified lines// Constant-time comparison β prevent timing attacks on token checkfunction safeEqual(a, b) {if (typeof a !== "string" || typeof b !== "string" || a.length !== b.length) return false;let d = 0;for (let i = 0; i < a.length; i++) d |= a.charCodeAt(i) ^ b.charCodeAt(i);return d === 0;}407 unmodified linesconst body = await readBody(req);const token = decodeURIComponent((body.match(/(?:^|&)token=([^&]*)/) || [])[1] || "").replace(/\+/g, " ");if (safeEqual(token, GATEWAY_TOKEN)) {const cookie = `hc_env_auth=${encodeURIComponent(GATEWAY_TOKEN)}; Path=/; HttpOnly; SameSite=Strict; Max-Age=86400`;res.writeHead(302, { Location: "/env-builder", "Set-Cookie": cookie, "Cache-Control": "no-store" });return res.end();}5 unmodified lines}if (pathname === "/env-builder/logout") {res.writeHead(302, { Location: "/env-builder", "Set-Cookie": "hc_env_auth=; Path=/; HttpOnly; Max-Age=0", "Cache-Control": "no-store" });return res.end();}21 unmodified lines22232425262728293031323334218 unmodified lines253254255256257258259260261262263264265266407 unmodified lines6746756766776786796805 unmodified lines68668768868969069169221 unmodified linesconst JUPYTER_BASE = normalizeBase(process.env.JUPYTER_BASE, "/terminal");const GATEWAY_TOKEN = (process.env.GATEWAY_TOKEN || "").trim();const DEV_MODE_ENABLED = isTrue(process.env.DEV_MODE);// Explicit HUGGINGCLAW_JUPYTER_ENABLED=true enables Jupyter.// Otherwise DEV_MODE=true enables it unless HUGGINGCLAW_JUPYTER_ENABLED is explicitly false.// HUGGINGCLAW_JUPYTER_ENABLED=true is the explicit user override and always wins.const JUPYTER_ENABLED =/^(true|1|yes|on)$/i.test(String(process.env.HUGGINGCLAW_JUPYTER_ENABLED || "").trim()) ||(isTrue(process.env.DEV_MODE) &&!/^(false|0|no|off)$/i.test(String(process.env.HUGGINGCLAW_JUPYTER_ENABLED || "").trim()));const startTime = Date.now();218 unmodified lines// Constant-time comparison β prevent timing attacks on token checkfunction safeEqual(a, b) {if (typeof a !== "string" || typeof b !== "string") return false;// Pad both to the same length so the loop always takes constant time,// preventing token length from being leaked via early-return timing.const len = Math.max(a.length, b.length, 1);const pa = a.padEnd(len, "\0");const pb = b.padEnd(len, "\0");let d = a.length === b.length ? 0 : 1; // length mismatch β always failfor (let i = 0; i < len; i++) d |= pa.charCodeAt(i) ^ pb.charCodeAt(i);return d === 0;}407 unmodified linesconst body = await readBody(req);const token = decodeURIComponent((body.match(/(?:^|&)token=([^&]*)/) || [])[1] || "").replace(/\+/g, " ");if (safeEqual(token, GATEWAY_TOKEN)) {const cookie = `hc_env_auth=${encodeURIComponent(GATEWAY_TOKEN)}; Path=/; HttpOnly; SameSite=None; Secure; Max-Age=86400`;res.writeHead(302, { Location: "/env-builder", "Set-Cookie": cookie, "Cache-Control": "no-store" });return res.end();}5 unmodified lines}if (pathname === "/env-builder/logout") {res.writeHead(302, { Location: "/env-builder", "Set-Cookie": "hc_env_auth=; Path=/; HttpOnly; SameSite=None; Secure; Max-Age=0", "Cache-Control": "no-store" });return res.end();}
85 unmodified lines86878889909185 unmodified linesenvPlural: 'ZAI_API_KEYS',envSingular:'ZAI_API_KEY',},{name: 'moonshot',hostname: /(?:^|\.)api\.moonshot\.cn$/i,85 unmodified lines8687888990919293949596979885 unmodified linesenvPlural: 'ZAI_API_KEYS',envSingular:'ZAI_API_KEY',},{name: 'kimi-coding',// kimi-coding routes through api.moonshot.cn; dedicated entry so KIMI_API_KEYS pool is usedhostname: /(?:^|\.)api\.moonshot\.cn$/i,envPlural: 'KIMI_API_KEYS',envSingular:'KIMI_API_KEY',},{name: 'moonshot',hostname: /(?:^|\.)api\.moonshot\.cn$/i,
202 unmodified lines2032042052062072082091562 unmodified lines1772177317741775177617771778177917801781178217831784178517861787202 unmodified linesbyteplus|byteplus-plan) export BYTEPLUS_API_KEY="$LLM_API_KEY" ;;qianfan) export QIANFAN_API_KEY="$LLM_API_KEY" ;;# ββ Western Providers ββmistral|mistralai) export MISTRAL_API_KEY="$LLM_API_KEY" ;;xai|x-ai) export XAI_API_KEY="$LLM_API_KEY" ;;nvidia) export NVIDIA_API_KEY="$LLM_API_KEY" ;;cohere) export COHERE_API_KEY="$LLM_API_KEY" ;;1562 unmodified lines# 11. Start WhatsApp Guardian after the gateway is accepting connectionsstart_guardian_once# ββ Silence D-Bus errors for headless Chromium ββif [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ]; thenif command -v dbus-launch >/dev/null 2>&1; theneval "$(dbus-launch --sh-syntax 2>/dev/null)" || trueexport DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-disabled:}"elseexport DBUS_SESSION_BUS_ADDRESS="disabled:"fifi# 11.5 Warm up the managed browser so first browser actions have a live tabwarmup_browser202 unmodified lines2032042052062072082091562 unmodified lines177217731774177517761777202 unmodified linesbyteplus|byteplus-plan) export BYTEPLUS_API_KEY="$LLM_API_KEY" ;;qianfan) export QIANFAN_API_KEY="$LLM_API_KEY" ;;# ββ Western Providers ββmistral) export MISTRAL_API_KEY="$LLM_API_KEY" ;;xai|x-ai) export XAI_API_KEY="$LLM_API_KEY" ;;nvidia) export NVIDIA_API_KEY="$LLM_API_KEY" ;;cohere) export COHERE_API_KEY="$LLM_API_KEY" ;;1562 unmodified lines# 11. Start WhatsApp Guardian after the gateway is accepting connectionsstart_guardian_once# 11.5 Warm up the managed browser so first browser actions have a live tabwarmup_browser
health-server.js+13-7
multi-provider-key-rotator.cjs+7
start.sh+1-11