T09 · Insecure Skill Coding Practices
- Location
scripts/workday-greeting.js:45- Finding
OS Command Injection Through the MUSIC_CMD Environment Variable
- Content
View full analysis
Vulnerability Details
File Location:
scripts/workday-greeting.js, lines 45–47
Vulnerability Type: OS command injection
Risk Level: HighVulnerable Code:
js const cmd = process.env.MUSIC_CMD || 'home-music'; try { execSync(`${cmd} ${slot}`, { stdio: 'inherit', timeout: 15000 });Technical Analysis
The application reads
MUSIC_CMDfrom the process environment or the project-level.envfile and interpolates it directly into a string passed tochild_process.execSync().execSync()executes its string argument through a command shell. Consequently, shell metacharacters and additional commands contained inMUSIC_CMDare interpreted by the shell rather than treated as part of a literal executable path. No allowlist, executable-path validation, or shell-character rejection is performed.This allows a party who can influence the runtime environment, deployment configuration, or project
.envfile to turn the documented music-scene operation into arbitrary command execution. The 15-second timeout limits execution duration but does not prevent commands from reading data, modifying files, starting detached processes, or making network connections.Attack Path
- An attacker gains the ability to modify the Skill's
.envfile or supply environment variables to its runtime, such as through an insecure deployment configuration or automation interface. - The attacker sets
MUSIC_CMDto a value containing the expected command followed by shell syntax and an additional operating-system command. - A user or scheduled job invokes
node scripts/workday-greeting.js. - Unless
--email-onlyor--dry-runis used,switchScene()constructs a shell command by concatenating the maliciousMUSIC_CMDvalue with the selected slot. execSync()passes the resulting string to a shell, which executes the injected command with the privileges of the Node.js process.
Impact Assessment
...[truncated 723 chars]
- An attacker gains the ability to modify the Skill's
- Remediation
View remediation
Remediation Suggestions
Replace shell-based execution with
execFileSync()orspawnSync()using separate arguments:js const { execFileSync } = require('child_process'); function switchScene(slot) { const allowedSlots = new Set([ 'morning', 'focus', 'working', 'chill', 'off', ]); if (!allowedSlots.has(slot)) { throw new Error(`Invalid music slot: ${slot}`); } const allowedCommands = new Map([ ['home-music', '/usr/local/bin/home-music'], ]); const configuredCommand = process.env.MUSIC_CMD || 'home-music'; const executable = allowedCommands.get(configuredCommand); if (!executable) { throw new Error('MUSIC_CMD is not an approved executable'); } execFileSync(executable, [slot], { stdio: 'inherit', timeout: 15000, shell: false, }); }Additional hardening measures:
- Restrict the executable to an explicit allowlist and preferably resolve it to a trusted absolute path.
- Never accept command-line flags, arguments, or shell fragments through
MUSIC_CMD. - Validate forced slot values against the known greeting and scene names before accessing or executing them.
- Protect
.envand scheduler configuration with restrictive file permissions and trusted ownership. - Run the automation under a dedicated least-privileged account without administrative permissions.
- Keep
shell: falseexplicit when using process-spawning APIs and pass every argument as a separate array element.
