T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/5gc.js:171
- Finding
- Shell Command Injection Through Forwarded CLI Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/5gc.js:171-183` **Vulnerability Type**: OS command injection **Risk Level**: High ### Vulnerable Code ```js // Remove entity and action before passing arguments to the child script const childArgv = normalizeChildArgs(entity, action, argv.slice(2)); console.log(`\n▶ 5GC ${entity.toUpperCase()} ${action}`); console.log(' → node ' + scriptFile + ' ' + childArgv.join(' ') + '\n'); // Invoke the child script while preserving CLI argument isolation const child = spawn('node', [scriptPath, ...childArgv], { stdio: 'inherit', shell: true, cwd: SCRIPTS_DIR, }); child.on('exit', (code) => process.exit(code || 0)); child.on('error', (err) => { console.error('Launch failed:', err.message); process.exit(1); }); ``` ### Technical Analysis The dispatcher forwards user-controlled CLI option values to `child_process.spawn()` while enabling `shell: true`. Enabling a shell is unnecessary because Node.js can execute the selected JavaScript file directly. With shell execution enabled, argument values containing shell metacharacters may be interpreted by the platform shell rather than remaining opaque arguments. The entity and action are allowlisted, and the script path comes from a fixed map, but arbitrary option values are preserved by `normalizeChildArgs()` without a comprehensive character or type allowlist. ### Attack Path 1. An attacker obtains the ability to invoke the Skill or influence its CLI parameters. 2. The attacker places shell syntax in a forwarded option value, such as a project name or entity name. 3. `normalizeChildArgs()` preserves the malicious value in `childArgv`. 4. `spawn()` invokes the command through a shell because `shell: true` is configured. 5. The shell interprets the injected syntax and executes an additional local command. 6. The injected command runs with the same operating-system privileges as the Agent or user running the Skill. ### Impact Assessment Successful expl ...[truncated 322 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove `shell: true` and execute Node.js directly: ```js const child = spawn(process.execPath, [scriptPath, ...childArgv], { stdio: 'inherit', shell: false, cwd: SCRIPTS_DIR, }); ``` - Validate every supported option using strict schemas. - Apply length limits and type validation to names, IDs, IP addresses, ports, counts, and policy values. - Reject control characters and unexpected metacharacters. - Do not construct shell command strings from user-controlled data. - Add regression tests using shell metacharacters to verify that arguments are passed literally. ]]>
