T09 · Insecure Skill Coding Practices
- Location
index.js:186- Finding
Shell Command Injection Through Unvalidated Skill Names and Configuration
- Content
View full analysis
{ const match = line.match(/^(GITHUB_USERNAME|CATCH_INTERVAL)=(.+)$/); if (match) { if (match[1] === 'GITHUB_USERNAME') config.githubUsername = match[2].trim(); if (match[1] === 'CATCH_INTERVAL') config.interval = parseInt(match[2].trim()); } }); } return config; } ``` ```js function addSkill(name) { const local = getLocalSkills(); if (local.skills.find(s => s.name === name)) { log(`${name} 已在列表中`, 'yellow'); return; } local.skills.push({ name, version: 'unknown' }); fs.writeFileSync(path.join(DATA_DIR, 'local.json'), JSON.stringify({ skills: local.skills, updated: new Date().toISOString() }, null, 2)); log(`✅ 已添加 ${name}`, 'green'); } ``` ```js const config = loadConfig(); const repoUrl = `https://github.com/${config.githubUsername}/${name}`; try { execSync(`cd ~/.openclaw/workspace/skills && git clone ${repoUrl} 2>/dev/null`, { timeout: 30000 }); log(`✅ 已从 GitHub 更新`, 'green'); } catch { execSync(`clawhub install ${name}`, { timeout: 30000 }); log(`✅ 已从 ClawHub 更新`, 'green'); } ``` ### Technical Analysis The Skill constructs shell command strings using two untrusted values: 1. The skill name supplied through the command line and persisted by `addSkill()`. 2. The GitHub username read from `~/.openclaw/.backup.env`. Neither value is validated, escaped, or passed as an isolated process argument. Node.js `execSync()` executes string commands through a shell, so shell metacharacters embedded in either value are ...[truncated 1732 chars]- Remediation
View remediation
/dev/null`. Use the process API's `cwd`, `stdio`, and absolute paths instead. 4. Validate values when they enter the application and again immediately before security-sensitive process execution. 5. Store structured metadata rather than executable command fragments, and reject malformed entries already present in `data/local.json`. 6. Add tests covering semicolons, command substitutions, pipes, redirections, whitespace, newlines, and other shell metacharacters. ]]>
