diff options
| author | Drew Ritter <drew@primeradiant.com> | 2026-06-10 20:33:56 -0700 |
|---|---|---|
| committer | Drew Ritter <drew@primeradiant.com> | 2026-06-16 10:09:46 -0700 |
| commit | 1c80914052d7b180d722450765fc86be0839c34a (patch) | |
| tree | cec8a0ceaa05dd3ece454d56298c018e19a7d179 /skills/brainstorming/scripts | |
| parent | 2a8479b21d88e1b7c17f86290c531742092d1ae4 (diff) | |
Harden Windows browser launcher
Diffstat (limited to 'skills/brainstorming/scripts')
| -rw-r--r-- | skills/brainstorming/scripts/server.cjs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/skills/brainstorming/scripts/server.cjs b/skills/brainstorming/scripts/server.cjs index f1a3b1a..bce67e3 100644 --- a/skills/brainstorming/scripts/server.cjs +++ b/skills/brainstorming/scripts/server.cjs @@ -214,6 +214,20 @@ function companionUrl() { return 'http://' + urlHostForHttp(URL_HOST) + ':' + PORT + '/?key=' + TOKEN; } +function browserLauncherForPlatform(url, { + platform = process.platform, + osRelease = require('os').release(), + env = process.env +} = {}) { + const isWSL = platform === 'linux' && /microsoft/i.test(osRelease); + if (platform === 'darwin') return { bin: 'open', args: [url] }; + if (platform === 'win32' || isWSL) { + return { bin: 'rundll32.exe', args: ['url.dll,FileProtocolHandler', url] }; + } + if (env.DISPLAY || env.WAYLAND_DISPLAY) return { bin: 'xdg-open', args: [url] }; + return null; +} + function isRegularFileInsideContentDir(filePath) { let stat, realContentDir, realFilePath; try { @@ -455,13 +469,9 @@ function maybeOpenBrowser() { } // Platform launchers: pass the URL as an argv element via execFile (no shell), // so a url-host containing shell metacharacters can't inject a command. - const isWSL = process.platform === 'linux' && /microsoft/i.test(require('os').release()); - let bin, args; - if (process.platform === 'darwin') { bin = 'open'; args = [url]; } - else if (process.platform === 'win32' || isWSL) { bin = 'cmd.exe'; args = ['/c', 'start', '', url]; } - else if (process.env.DISPLAY || process.env.WAYLAND_DISPLAY) { bin = 'xdg-open'; args = [url]; } - else return; // headless: nothing to open - try { cp.execFile(bin, args, () => {}); } catch (e) { /* best effort */ } + const launcher = browserLauncherForPlatform(url); + if (!launcher) return; // headless: nothing to open + try { cp.execFile(launcher.bin, launcher.args, () => {}); } catch (e) { /* best effort */ } } // ========== Activity Tracking ========== @@ -627,4 +637,11 @@ if (require.main === module) { startServer(); } -module.exports = { computeAcceptKey, encodeFrame, decodeFrame, OPCODES, MAX_FRAME_PAYLOAD_BYTES }; +module.exports = { + computeAcceptKey, + encodeFrame, + decodeFrame, + browserLauncherForPlatform, + OPCODES, + MAX_FRAME_PAYLOAD_BYTES +}; |
