Skip to content

Fix/path injection cf yo - #168

Merged
thomaszang merged 2 commits into
mainfrom
fix/path-injection-cf-yo
Nov 18, 2026
Merged

thomaszang merged 2 commits into
mainfrom
fix/path-injection-cf-yo

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
- Add resolveCFBinary() to validate cf binary is in trusted system directories
- Update isCFLoggedIn() and refreshCFToken() to use validated cf path
- Add trusted location validation for yo binary PATH resolution
- Only accept binaries from system directories (/usr/, /opt/, Program Files)
  or node_modules/.bin to prevent malicious PATH entries
- Resolve symlinks with fs.realpathSync() for consistent validation

CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H
PSS Violations: SEC-243, SEC-100
@thomaszang
thomaszang merged commit be3f0c6 into main Nov 18, 2026
4 checks passed
@thomaszang
thomaszang deleted the fix/path-injection-cf-yo branch November 18, 2026 07:09
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