Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(security): block IPv6 private and metadata enterprise endpoints (#1440)

Henry Su7f4c3a66445f
diff --git a/src/helpers/enterpriseProviderErrors.js b/src/helpers/enterpriseProviderErrors.js
index 5b12c7d89..7be5690cd 100644
--- a/src/helpers/enterpriseProviderErrors.js
+++ b/src/helpers/enterpriseProviderErrors.js
@@ -211,6 +211,14 @@ function isPrivateIPv4(hostname) {
function isPrivateIPv6(hostname) {
if (hostname === "::1") return true;
if (/^(fe80|fc[0-9a-f]{2}|fd[0-9a-f]{2}):/i.test(hostname)) return true;
+ // The URL parser rewrites an IPv4-mapped address to its hex form, so
+ // "::ffff:169.254.169.254" reaches us as "::ffff:a9fe:a9fe".
+ const mappedHex = hostname.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
+ if (mappedHex) {
+ const hi = parseInt(mappedHex[1], 16);
+ const lo = parseInt(mappedHex[2], 16);
+ return isPrivateIPv4(`${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`);
+ }
const mapped = hostname.match(/^::ffff:(.+)$/i);
return mapped ? isPrivateIPv4(mapped[1]) : false;
}
@@ -226,7 +234,9 @@ function validateEnterpriseEndpoint(endpoint) {
if (url.protocol !== "https:") {
throw new Error("Endpoint must use HTTPS.");
}
- const hostname = url.hostname.toLowerCase();
+ // URL.hostname keeps the brackets around an IPv6 literal ("[::1]"), which no
+ // isPrivateIPv6 branch can match — strip them or the whole IPv6 arm is dead.
+ const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
if (
BLOCKED_HOSTS.has(hostname) ||
BLOCKED_SUFFIXES.some((suffix) => hostname.endsWith(suffix)) ||
diff --git a/test/helpers/enterpriseEndpointGuard.test.js b/test/helpers/enterpriseEndpointGuard.test.js
new file mode 100644
index 000000000..2f0bff642
--- /dev/null
+++ b/test/helpers/enterpriseEndpointGuard.test.js
@@ -0,0 +1,71 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const Module = require("node:module");
+
+const originalLoad = Module._load;
+Module._load = function loadWithElectronStub(request, parent, isMain) {
+ if (request === "electron") {
+ return { app: { isReady: () => false, getPath: () => "", getAppPath: () => process.cwd() } };
+ }
+ return originalLoad.call(this, request, parent, isMain);
+};
+
+const { validateEnterpriseEndpoint } = require("../../src/helpers/enterpriseProviderErrors");
+
+const rejects = (endpoint) => {
+ assert.throws(
+ () => validateEnterpriseEndpoint(endpoint),
+ /Private\/metadata endpoints are not allowed\./,
+ `expected ${endpoint} to be rejected`
+ );
+};
+
+const accepts = (endpoint) => {
+ assert.doesNotThrow(() => validateEnterpriseEndpoint(endpoint), `expected ${endpoint} to pass`);
+};
+
+test("IPv6 loopback and unique-local literals are rejected", () => {
+ rejects("https://[::1]/openai");
+ rejects("https://[fd00::1]/openai");
+ rejects("https://[fc00::1]/openai");
+ rejects("https://[fe80::1]/openai");
+});
+
+test("IPv4-mapped IPv6 literals are rejected after URL normalization", () => {
+ // WHATWG URL rewrites [::ffff:169.254.169.254] to [::ffff:a9fe:a9fe].
+ rejects("https://[::ffff:169.254.169.254]/openai");
+ rejects("https://[::ffff:127.0.0.1]/openai");
+ rejects("https://[::ffff:10.0.0.1]/openai");
+});
+
+test("public IPv6 endpoints are still accepted", () => {
+ accepts("https://[2606:4700:4700::1111]/openai");
+ accepts("https://[::ffff:8.8.8.8]/openai");
+});
+
+test("existing IPv4, metadata and suffix rules still hold", () => {
+ rejects("https://169.254.169.254/openai");
+ rejects("https://127.0.0.1/openai");
+ rejects("https://10.0.0.1/openai");
+ rejects("https://192.168.1.1/openai");
+ rejects("https://172.16.0.1/openai");
+ rejects("https://localhost/openai");
+ rejects("https://metadata.google.internal/openai");
+ rejects("https://foo.internal/openai");
+ // WHATWG URL expands the decimal form to 127.0.0.1.
+ rejects("https://2130706433/openai");
+});
+
+test("public https endpoints and empty input are accepted", () => {
+ accepts("https://myresource.openai.azure.com/");
+ accepts("https://8.8.8.8/openai");
+ accepts("");
+ accepts(undefined);
+});
+
+test("non-https endpoints are rejected", () => {
+ assert.throws(
+ () => validateEnterpriseEndpoint("http://myresource.openai.azure.com/"),
+ /Endpoint must use HTTPS\./
+ );
+});