T09 · Insecure Skill Coding Practices
- Location
scripts/upgrade-plugin.sh:104- Finding
JavaScript Code Injection Through Unvalidated Plugin Identifier
- Content
View full analysis
/dev/null || true)" ``` ```bash HAS_PLUGIN_CHANNEL="$(node -e " try { const cfg = JSON.parse(require('fs').readFileSync('$CONFIG_FILE','utf8')); if (cfg.channels && (cfg.channels['$PLUGIN_ID'] || cfg.channels['$PLUGIN_CHANNEL_KEY'])) process.stdout.write('true'); } catch {} " 2>/dev/null || true)" ``` ```bash HAS_INSTALL_RECORD="$(node -e " try { const cfg=JSON.parse(require('fs').readFileSync('$CONFIG_FILE','utf8')); const inst=cfg.plugins&&cfg.plugins.installs&&cfg.plugins.installs['$PLUGIN_ID']; if(inst) process.stdout.write('yes'); } catch {} " 2>/dev/null || true)" ``` ### Technical Analysis The script reads `PLUGIN_ID` directly from its second positional argument without applying format validation: ```bash PLUGIN_ID="${2:-}" ``` It subsequently interpolates that value into JavaScript source passed to `node -e`. Shell quoting does not make the value safe as JavaScript syntax. An identifier containing a single quote and additional JavaScript tokens can terminate one of the generated string literals and inject attacker-controlled JavaScript. The same unsafe pattern is used for filesystem paths such as `OLD_PKG` and configuration paths. Values that can contain quote characters may therefore alter the program supplied to Node.js instead of being treated solely as data. Because Node.js is launched with the privileges of the agent or user running the Skill, injected JavaScript can use modules such as `child_process`, `fs`, or netw ...[truncated 1405 chars]- Remediation
View remediation
/dev/null || true )" ``` 2. Pass `PLUGIN_ID`, `PLUGIN_CHANNEL_KEY`, and configuration paths through `process.argv` in every `node -e` invocation. 3. Strictly validate plugin identifiers before any use. If plugin directory names are expected to contain only common package identifier characters, enforce an allowlist such as: ```bash if [[ ! "$PLUGIN_ID" =~ ^[A-Za-z0-9._-]+$ ]]; then echo "Invalid plugin identifier" >&2 exit 1 fi ``` 4. Validate npm package names and versions separately according to the supported npm naming grammar. 5. Add regression tests using identifiers containing quotes, backslashes, newlines, traversal segments, and JavaScript syntax to ensure that they remain inert data. ]]>
