T09 · Insecure Skill Coding Practices
Error
- Location
- src/config.js:108
- Finding
- Plaintext storage of TikTok and Feishu credentials in an insufficiently protected configuration file<![CDATA[ ## Vulnerability Details **File Location**: `src/config.js:108-116`, with credential sources in `commands/init.js:113-145` and `commands/account.js:18-24` **Vulnerability Type**: Plaintext sensitive credential storage **Risk Level**: High ### Vulnerable Code `src/config.js:108-116`: ```js export function saveConfig(config) { initConfigDir(); try { fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8'); console.log(`✓ 配置已保存:${CONFIG_FILE}`); return true; } catch (error) { ``` `commands/init.js:113-119`: ```js config.feishu.appToken = feishuAnswers.appToken; config.feishu.tableId = feishuAnswers.tableId; config.feishu.webhookUrl = feishuAnswers.webhookUrl; } ``` `commands/init.js:143-145`: ```js config.tiktok.apiKey = apiAnswers.apiKey; config.tiktok.apiSecret = apiAnswers.apiSecret; config.tiktok.shopId = apiAnswers.shopId; ``` `commands/account.js:18-24`: ```js addAccountConfig({ username: options.username, region: options.region, cookie: options.cookie, addedAt: new Date().toISOString() }); ``` ### Technical Analysis The initialization and account-management paths place the following sensitive values directly in the general configuration object: - TikTok API key and API secret - TikTok session cookies - Feishu webhook URL - Feishu application token and table identifier The complete object is serialized as plaintext to: ```text ~/.clawhub/tiktok-shop/config.json ``` `saveConfig()` does not specify a restrictive creation mode and does not call `chmod()` after writing. Consequently, the resulting permissions depend on the process umask and operating-system defaults. On a multi-user system, permissive defaults may allow other local users or processes to read the file. The project contains a separate `saveCredentials()` function that applies mode `0600` on non-Windows systems, but the initialization and account commands do not use that protected ...[truncated 1719 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove API secrets, session cookies, and webhook URLs from the general configuration object. 2. Store secrets in an operating-system credential vault, such as Keychain, Credential Manager, Secret Service, or a managed secret store. 3. If file storage is unavoidable: - Create `~/.clawhub/tiktok-shop` with mode `0700`. - Create credential files atomically with mode `0600`. - Verify ownership and permissions every time credentials are loaded. - Reject credential files that are symlinks or are owned by another user. 4. Change `init` and `add-account` to call a dedicated credential-storage interface rather than `saveConfig()`. 5. Ensure `exportConfig()` excludes or redacts all secrets. 6. Avoid accepting session cookies directly on the command line because shell history and process listings may expose them. Use a masked prompt, standard input, or a credential-store reference. 7. Rotate any credentials that may already have been stored in permissively accessible configuration files. 8. Update documentation so security claims accurately describe the implemented protection. ]]>
