Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(security): require IPv4 literals for private HTTP endpoints (#1318)
Henry Su2657a7c49309
diff --git a/probe.mjs b/probe.mjsnew file mode 100644index 000000000..2a7fd2952--- /dev/null+++ b/probe.mjs@@ -0,0 +1,49 @@+import { isSecureEndpoint } from "./src/utils/urlUtils.ts";+const cases = [+ // must be REJECTED (public hosts that used to sneak through)+ ["http://127.example.com/v1", false],+ ["http://10.example.com/v1", false],+ ["http://192.168.example.com/v1", false],+ ["http://172.16.example.com/v1", false],+ ["http://100.64.example.com/v1", false],+ ["http://169.254.example.com/v1", false],+ ["http://127.0.0.1.nip.io/v1", false],+ ["http://0.0.0.0.evil.com/v1", false],+ // must stay ALLOWED+ ["http://127.0.0.1:5000", true],+ ["http://localhost:8080", true],+ ["http://0.0.0.0:1234", true],+ ["http://10.0.0.5:8080", true],+ ["http://192.168.1.10:1234", true],+ ["http://172.16.0.1:1234", true],+ ["http://172.31.255.255:1234", true],+ ["http://100.64.0.1:8080", true],+ ["http://169.254.1.1:80", true],+ ["http://myhost.local:1234", true],+ ["http://[::1]:8080", true],+ ["http://[fd00::1]:8080", true],+ ["http://[fe80::1]:8080", true],+ ["https://api.openai.com/v1", true],+ // boundary: NOT private, must require https+ ["http://172.15.0.1:1234", false],+ ["http://172.32.0.1:1234", false],+ ["http://100.63.0.1:1234", false],+ ["http://100.128.0.1:1234", false],+ ["http://11.0.0.1:1234", false],+ ["http://126.0.0.1:1234", false],+ ["http://128.0.0.1:1234", false],+ // abbreviated / alternate literals WHATWG normalises+ ["http://127.1", true],+ ["http://2130706433", true],+ ["http://0x7f000001", true],+ ["http://010.0.0.1", true],+];+let bad = 0;+for (const [url, want] of cases) {+ let got;+ try { got = isSecureEndpoint(url); } catch (e) { got = "THREW " + e.message; }+ const ok = got === want;+ if (!ok) bad++;+ console.log(`${ok ? "ok " : "FAIL"} ${String(got).padEnd(5)} (want ${want}) ${url}`);+}+console.log(bad ? `\n${bad} MISMATCHES` : "\nall as expected");diff --git a/probe2.mjs b/probe2.mjsnew file mode 100644index 000000000..f96e9d4fa--- /dev/null+++ b/probe2.mjs@@ -0,0 +1,13 @@+// After /^(0|[1-9]\d{0,2})$/, can Number(part) ever be a non-integer or negative?+const re = /^(0|[1-9]\d{0,2})$/;+let nonInt = 0, neg = 0, over = 0, n = 0;+for (let i = 0; i < 1000; i++) {+ const s = String(i);+ if (!re.test(s)) continue;+ n++;+ const v = Number(s);+ if (!Number.isInteger(v)) nonInt++;+ if (v < 0) neg++;+ if (v > 255) over++;+}+console.log({ matched: n, nonInteger: nonInt, negative: neg, over255: over });diff --git a/src/utils/urlUtils.ts b/src/utils/urlUtils.tsindex 1524a1244..599c9155b 100644--- a/src/utils/urlUtils.ts+++ b/src/utils/urlUtils.ts@@ -1,15 +1,39 @@+// Require a real dotted-quad before applying IPv4 private-range checks so+// public DNS names like "127.example.com" / "10.example.com" cannot bypass+// the HTTPS requirement via string-prefix matching.+function parseIPv4Literal(hostname: string): number[] | null {+ const parts = hostname.split(".");+ if (parts.length !== 4) return null;++ const octets: number[] = [];+ for (const part of parts) {+ // Reject empty labels, leading zeros ("01"), and non-decimal forms.+ if (!/^(0|[1-9]\d{0,2})$/.test(part)) return null;+ const value = Number(part);+ if (value > 255) return null;+ octets.push(value);+ }++ return octets;+}+function isPrivateHost(hostname: string): boolean {const h = hostname.toLowerCase().replace(/^\[|\]$/g, "");- if (h === "localhost" || h === "0.0.0.0" || h.startsWith("127.")) return true;+ if (h === "localhost" || h === "0.0.0.0") return true;if (h === "::1") return true;- if (h.startsWith("10.") || h.startsWith("192.168.")) return true;- if (h.startsWith("172.")) {- const octet = parseInt(h.split(".")[1], 10);- if (octet >= 16 && octet <= 31) return true;++ const ipv4 = parseIPv4Literal(h);+ if (ipv4) {+ const [a, b] = ipv4;+ if (a === 127) return true;+ if (a === 10) return true;+ if (a === 192 && b === 168) return true;+ if (a === 172 && b >= 16 && b <= 31) return true;+ // RFC 6598 CGNAT (Tailscale): 100.64.0.0/10+ if (a === 100 && b >= 64 && b <= 127) return true;+ if (a === 169 && b === 254) return true;}- if (/^100\.(6[4-9]|[7-9]\d|1[0-1]\d|12[0-7])\./.test(h)) return true;- if (h.startsWith("169.254.")) return true;const isIPv6 = h.includes(":");if (isIPv6 && (h.startsWith("fe80") || h.startsWith("fc") || h.startsWith("fd"))) return true;diff --git a/test/helpers/secureEndpoint.test.js b/test/helpers/secureEndpoint.test.jsindex c9a8a7427..8b0f712c8 100644--- a/test/helpers/secureEndpoint.test.js+++ b/test/helpers/secureEndpoint.test.js@@ -23,6 +23,28 @@ test("loopback hosts are allowed over http", async () => {assert.equal(isSecureEndpoint("http://[::1]:8080"), true);});+test("public DNS names that resemble private IP prefixes still require https", async () => {+ const { isSecureEndpoint } = await load();++ assert.equal(isSecureEndpoint("http://127.example.com/v1"), false);+ assert.equal(isSecureEndpoint("http://10.example.com/v1"), false);+ assert.equal(isSecureEndpoint("http://192.168.example.com/v1"), false);+ assert.equal(isSecureEndpoint("http://172.16.example.com/v1"), false);+ assert.equal(isSecureEndpoint("http://100.64.example.com/v1"), false);+ assert.equal(isSecureEndpoint("http://169.254.example.com/v1"), false);+ assert.equal(isSecureEndpoint("http://127.0.0.1.nip.io/v1"), false);++ assert.equal(isSecureEndpoint("https://127.example.com/v1"), true);+});++test("URL-parser abbreviations of loopback IPv4 remain allowed over http", async () => {+ const { isSecureEndpoint } = await load();++ // WHATWG URL expands forms like 127.1 → 127.0.0.1 before our host check.+ assert.equal(isSecureEndpoint("http://127.1/v1"), true);+ assert.equal(isSecureEndpoint("http://127.0.1/v1"), true);+});+test("RFC 1918 private ranges are allowed over http — self-hosted LLM servers live there", async () => {const { isSecureEndpoint } = await load();