Skip to content

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

fix(windows): only hand explorer.exe URLs it can actually deliver (#1932)

Joshua532a3cf77b0c
diff --git a/src/helpers/externalUrlOpener.js b/src/helpers/externalUrlOpener.js
index c3e4f424c..0d3ea206a 100644
--- a/src/helpers/externalUrlOpener.js
+++ b/src/helpers/externalUrlOpener.js
@@ -13,9 +13,26 @@ const debugLogger = require("./debugLogger");
// outside our process tree. The protocol gate is load-bearing: explorer.exe
// EXECUTES non-URL arguments such as file paths. The absolute path is too:
// a bare "explorer.exe" resolves from the CWD first (binary planting).
+// explorer.exe cannot deliver every URL: its command-line parser treats "="
+// and "," as field separators, so query strings (?callbackURL=… — which broke
+// every desktop OAuth sign-in, microsoft/WSL#3832), fragments (neovim#23401),
+// and a bare "=" or "," in a path (rauschma/openurl#2) open a File Explorer
+// window or an error dialog instead of the browser — silently, because the
+// spawn itself succeeds. Those URLs go through shell.openExternal: losing the
+// loopback exclusion for one open beats a link that never opens. Gate on the
+// serialized href (the argv token explorer receives) — URL.search reports ""
+// for a bare trailing "?". Serialization percent-encodes spaces, quotes and
+// non-ASCII, so explorer always gets one ASCII token; "%" itself stays
+// eligible because this shell-less spawn never expands %VAR%-style sequences.
+const EXPLORER_BREAKING_CHARS = /[?#=,]/;
+
async function openExternalUrl(url) {
const { protocol, href } = new URL(url);
- if (process.platform === "win32" && (protocol === "http:" || protocol === "https:")) {
+ if (
+ process.platform === "win32" &&
+ (protocol === "http:" || protocol === "https:") &&
+ !EXPLORER_BREAKING_CHARS.test(href)
+ ) {
const explorerPath = path.win32.join(process.env.SystemRoot || "C:\\Windows", "explorer.exe");
try {
await new Promise((resolve, reject) => {
diff --git a/test/helpers/externalUrlOpener.test.js b/test/helpers/externalUrlOpener.test.js
index e2fe523a4..6a296a338 100644
--- a/test/helpers/externalUrlOpener.test.js
+++ b/test/helpers/externalUrlOpener.test.js
@@ -119,9 +119,59 @@ test("explorer.exe receives a single percent-encoded argv token", async () => {
const { openExternalUrl, spawnCalls } = loadOpener();
setPlatform("win32");
- await openExternalUrl('https://example.com/join?name=a b"c');
+ await openExternalUrl('https://example.com/join room "4"');
- assert.deepEqual(spawnCalls[0].args, ["https://example.com/join?name=a%20b%22c"]);
+ assert.deepEqual(spawnCalls[0].args, ["https://example.com/join%20room%20%224%22"]);
+});
+
+test("win32 query-string URLs go to shell.openExternal — explorer.exe opens File Explorer instead of the browser for them", async () => {
+ const { openExternalUrl, spawnCalls, openExternalCalls } = loadOpener();
+ setPlatform("win32");
+
+ const oauthUrl =
+ "https://auth.openwhispr.com/api/desktop-signin/google?callbackURL=openwhispr%3A%2F%2Fauth";
+ await openExternalUrl(oauthUrl);
+
+ assert.equal(spawnCalls.length, 0);
+ assert.deepEqual(openExternalCalls, [oauthUrl]);
+});
+
+test("a bare trailing ? still counts as a query string for the explorer.exe gate", async () => {
+ const { openExternalUrl, spawnCalls, openExternalCalls } = loadOpener();
+ setPlatform("win32");
+
+ // URL.search reports "" here, but the serialized href explorer.exe receives
+ // keeps the "?" — the gate must judge the delivered token, not the parse.
+ await openExternalUrl("https://example.com/checkout?");
+
+ assert.equal(spawnCalls.length, 0);
+ assert.deepEqual(openExternalCalls, ["https://example.com/checkout?"]);
+});
+
+test("win32 fragment URLs go to shell.openExternal — explorer.exe mishandles them too", async () => {
+ const { openExternalUrl, spawnCalls, openExternalCalls } = loadOpener();
+ setPlatform("win32");
+
+ await openExternalUrl("https://docs.openwhispr.com/changelog#windows");
+
+ assert.equal(spawnCalls.length, 0);
+ assert.deepEqual(openExternalCalls, ["https://docs.openwhispr.com/changelog#windows"]);
+});
+
+test("win32 URLs with explorer's = or , argv separators go to shell.openExternal", async () => {
+ const { openExternalUrl, spawnCalls, openExternalCalls } = loadOpener();
+ setPlatform("win32");
+
+ // Neither URL has a query string or fragment — the separator alone breaks
+ // explorer.exe's argument parsing (rauschma/openurl#2, superuser 1552619).
+ await openExternalUrl("https://example.com/products/id=42");
+ await openExternalUrl("https://example.com/maps/@37.77,-122.41");
+
+ assert.equal(spawnCalls.length, 0);
+ assert.deepEqual(openExternalCalls, [
+ "https://example.com/products/id=42",
+ "https://example.com/maps/@37.77,-122.41",
+ ]);
});
test("win32 mailto URLs fall through to shell.openExternal untouched", async () => {