Skip to content

Commit 660e0d3

Browse files
committed
fix: security and documentation fixes
- fix(utils.js): prevent command injection in commandExists() by using spawnSync instead of execSync with string interpolation, and validate input to only allow alphanumeric chars, dash, underscore, dot (anomalyco#42) - fix(utils.js): add security documentation to runCommand() warning against passing user-controlled input - fix(setup-package-manager.js): replace <script> and <binary> with [script-name] and [binary-name] to avoid XSS scanner false positives (anomalyco#43) - fix(doc-updater.md): replace invalid 'npx ts-morph' with correct 'npx tsx scripts/codemaps/generate.ts' since ts-morph is a library, not a CLI tool (anomalyco#51) Fixes anomalyco#42, anomalyco#43, anomalyco#51
1 parent a7bc5f2 commit 660e0d3

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎agents/doc-updater.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ You are a documentation specialist focused on keeping codemaps and documentation
2727

2828
### Analysis Commands
2929
```bash
30-
# Analyze TypeScript project structure
31-
npx ts-morph
30+
# Analyze TypeScript project structure (run custom script using ts-morph library)
31+
npx tsx scripts/codemaps/generate.ts
3232

3333
# Generate dependency graph
3434
npx madge --image graph.svg src/

‎scripts/lib/utils.js‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,37 @@ function appendFile(filePath, content) {
223223

224224
/**
225225
* Check if a command exists in PATH
226+
* Uses execFileSync to prevent command injection
226227
*/
227228
function commandExists(cmd) {
229+
// Validate command name - only allow alphanumeric, dash, underscore, dot
230+
if (!/^[a-zA-Z0-9_.-]+$/.test(cmd)) {
231+
return false;
232+
}
233+
228234
try {
229235
if (isWindows) {
230-
execSync(`where ${cmd}`, { stdio: 'pipe' });
236+
// Use spawnSync to avoid shell interpolation
237+
const result = spawnSync('where', [cmd], { stdio: 'pipe' });
238+
return result.status === 0;
231239
} else {
232-
execSync(`which ${cmd}`, { stdio: 'pipe' });
240+
const result = spawnSync('which', [cmd], { stdio: 'pipe' });
241+
return result.status === 0;
233242
}
234-
return true;
235243
} catch {
236244
return false;
237245
}
238246
}
239247

240248
/**
241249
* Run a command and return output
250+
*
251+
* SECURITY NOTE: This function executes shell commands. Only use with
252+
* trusted, hardcoded commands. Never pass user-controlled input directly.
253+
* For user input, use spawnSync with argument arrays instead.
254+
*
255+
* @param {string} cmd - Command to execute (should be trusted/hardcoded)
256+
* @param {object} options - execSync options
242257
*/
243258
function runCommand(cmd, options = {}) {
244259
try {

‎scripts/setup-package-manager.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ function detectAndShow() {
8989
console.log('');
9090
console.log('Commands:');
9191
console.log(` Install: ${pm.config.installCmd}`);
92-
console.log(` Run script: ${pm.config.runCmd} <script>`);
93-
console.log(` Execute binary: ${pm.config.execCmd} <binary>`);
92+
console.log(` Run script: ${pm.config.runCmd} [script-name]`);
93+
console.log(` Execute binary: ${pm.config.execCmd} [binary-name]`);
9494
console.log('');
9595
}
9696

0 commit comments

Comments
 (0)