Skip to content

fix: command injection in runCommand (CVSS 7.8) - #167

Merged
thomaszang merged 1 commit into
mainfrom
fix/path-traversal-vulnerability
Nov 18, 2026
Merged

thomaszang merged 1 commit into
mainfrom
fix/path-traversal-vulnerability

Conversation

@thomaszang

Copy link
Copy Markdown
Member

No description provided.

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-100
@thomaszang
thomaszang force-pushed the fix/path-traversal-vulnerability branch from 04acc05 to 52f0ee6 Compare November 18, 2026 06:52
@thomaszang thomaszang changed the title Fix/path traversal vulnerability fix: command injection in runCommand (CVSS 7.8) Nov 18, 2026
@thomaszang
thomaszang merged commit 00bbce9 into main Nov 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants