T09 · Insecure Skill Coding Practices
- Location
- scripts/setup.js:176
- Finding
- Shell Command Injection Through X Authentication Cookies<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup.js:176-184`; `monitor.js:72-76` **Vulnerability Type**: Shell command injection through untrusted credential interpolation **Risk Level**: Critical ### Vulnerable Code ```js // scripts/setup.js async function testCredentials(authToken, ct0) { printHeader('🧪 Testing Credentials'); print('Verifying your credentials with X...', yellow); try { // Test with bird whoami const cmd = `AUTH_TOKEN="${authToken}" CT0="${ct0}" bird whoami --json 2>&1`; const result = execSync(cmd, { encoding: 'utf8', timeout: 15000 }); ``` ```js // monitor.js function fetchBookmarks() { console.log(`[${new Date().toISOString()}] Fetching bookmarks...`); try { // Use environment variables for credentials (safer than command line args) const cmd = `AUTH_TOKEN="${credentials.auth_token}" CT0="${credentials.ct0}" bird bookmarks -n ${config.bookmarkCount} --json`; const output = execSync(cmd, { encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 }); ``` ### Technical Analysis Both authentication cookie values are placed inside command strings passed to `execSync()`. By default, `execSync()` invokes a system shell. Double quotation marks do not make this construction safe because a malicious value can contain a closing quotation mark followed by shell metacharacters or command substitutions. The setup wizard accepts these values directly from terminal input. The monitor later reads them from `.env` or inherited environment variables. Therefore, compromise of either input channel can produce shell execution. The comment that environment variables are safer than command-line arguments is misleading in this implementation: the variables are assigned through shell syntax rather than through the child-process `env` option. ### Attack Path 1. An attacker persuades a user to paste a crafted cookie value, or modifies the local `.env` file. 2. The value contains syntax that terminates the quoted s ...[truncated 801 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Replace shell command strings with `execFileSync()` or `spawnSync()` and explicit argument arrays. - Supply cookies through the child process environment without invoking a shell: ```js const result = execFileSync( 'bird', ['whoami', '--json'], { encoding: 'utf8', timeout: 15000, env: { ...process.env, AUTH_TOKEN: authToken, CT0: ct0 } } ); ``` - Apply the same change to `monitor.js`. - Validate `bookmarkCount` as a bounded integer before passing it to the child process. - Do not log full command strings, credentials, or child-process environments. - Treat `.env` modification as a security-sensitive event and preserve owner-only permissions. ]]>
