Repository navigation
Commit 52f0ee6
committed
fix: command injection in runCommand (CVSS 7.8)
Fixes a HIGH severity command injection vulnerability where validated
arguments differed from executed command, allowing shell metacharacter
injection via newlines and quote manipulation.
Security improvements:
- Replace execSync with execFileSync for proper argv array execution
- Add pre-tokenization check for \r\n in raw command string
- Execute validated argv array instead of raw command string
- Add \r to injection character validation regex
- Enforce allowedArgs allowlists (previously dead code)
- Minimize shell usage (only Windows .cmd/yo when required)
Changes:
- src/utils.ts:
- runCommand: Changed from execSync(command) to execFileSync(baseCommand, args)
- Added /[\r\n]/ check on raw command before tokenization
- validateCommandArgs: Added \r to denylist, implemented allowedArgs enforcement
- Only enables shell for Windows .cmd/yo files via shell:true option
Attack scenario prevented:
Before: command="yo\nmalicious" → tokenized as ["yo", "malicious"] →
validation passed → execSync executed "yo\nmalicious" with shell
After: command="yo\nmalicious" → rejected at raw string check →
error thrown before execution
Impact: Prevents arbitrary command execution via newline/CR injection
and quote manipulation in any attacker-influenced command segment.
Testing: All 117 tests passing (0 failures)
CVSS: 7.8 HIGH - CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
PSS Violations: SEC-1001 parent 8089b92 commit 52f0ee6
1 file changed
Lines changed: 58 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
320 | | - | |
| 319 | + | |
| 320 | + | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
326 | 354 | | |
327 | 355 | | |
328 | 356 | | |
| |||
341 | 369 | | |
342 | 370 | | |
343 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
344 | 380 | | |
345 | 381 | | |
346 | 382 | | |
| |||
353 | 389 | | |
354 | 390 | | |
355 | 391 | | |
356 | | - | |
| 392 | + | |
357 | 393 | | |
358 | 394 | | |
359 | 395 | | |
| |||
385 | 421 | | |
386 | 422 | | |
387 | 423 | | |
388 | | - | |
389 | 424 | | |
390 | 425 | | |
391 | 426 | | |
392 | 427 | | |
393 | 428 | | |
394 | 429 | | |
395 | 430 | | |
396 | | - | |
| 431 | + | |
397 | 432 | | |
398 | 433 | | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
404 | 451 | | |
405 | 452 | | |
406 | | - | |
407 | 453 | | |
408 | 454 | | |
409 | 455 | | |
| |||
0 commit comments