Skip to content

Commit e323919

Browse files
authored
Fix command injection in claude-supermemory openBrowser() (#19)
## Summary This PR fixes a command injection vulnerability in `openBrowser()` by replacing `exec()` with `execFile()` and passing arguments as an array. ## Details The previous implementation used string concatenation when invoking external commands, allowing shell metacharacters in a crafted URL to execute arbitrary commands. Using `execFile()` avoids shell interpolation and eliminates this attack vector. ## Related Issue Closes #868
1 parent 7ed7cc2 commit e323919

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/lib/auth.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const http = require('node:http');
22
const fs = require('node:fs');
33
const path = require('node:path');
44
const os = require('node:os');
5-
const { exec } = require('node:child_process');
5+
const { execFile } = require('node:child_process');
66

77
const authSuccessHtml = require('../templates/auth-success.html');
88
const authErrorHtml = require('../templates/auth-error.html');
@@ -50,13 +50,16 @@ function clearCredentials() {
5050
}
5151

5252
function openBrowser(url) {
53-
const cmd =
54-
process.platform === 'darwin'
55-
? 'open'
56-
: process.platform === 'win32'
57-
? 'start'
58-
: 'xdg-open';
59-
exec(`${cmd} "${url}"`);
53+
const onError = (err) => {
54+
if (err) console.warn('Failed to open browser:', err.message);
55+
};
56+
if (process.platform === 'win32') {
57+
execFile('explorer.exe', [url], onError);
58+
} else if (process.platform === 'darwin') {
59+
execFile('open', [url], onError);
60+
} else {
61+
execFile('xdg-open', [url], onError);
62+
}
6063
}
6164

6265
function startAuthFlow() {

0 commit comments

Comments
 (0)