T09 · Insecure Skill Coding Practices
- Location
src/utils/log.js:5- Finding
Automatic Persistence of User Queries and Complete API Results
- Content
View full analysis
|]/g, "_") .replace(/\.\.+/g, "_") .replace(/^\.+|\.+$/g, ""); if (safeFilename.length > 200) { safeFilename = safeFilename.slice(0, 200); } if (!safeFilename) { safeFilename = `log_${Date.now()}`; } const outputFilename = path.join( path.dirname(__filename), "..", "..", "logs", safeFilename, ); try { await fs.promises.mkdir(path.dirname(outputFilename), { recursive: true }); await fs.promises.writeFile(outputFilename, content); utils.printSuccess(` → 已保存到 ${outputFilename}`); } catch (error) { utils.printError(`日志写入失败: ${error.message}`); } } ``` Successful search operations persist the complete request and response. The raw search keyword is included in the JSON content, while the normalized keyword is also included in the filename: ```js const finalOutput = { status: "success", error_code: "OK", message: "搜索任务完成", timestamp: new Date().toLocaleString(), request: { command: "search", keyword_raw: keywordRaw, keyword: keyword, sort: sort, time: time, duration: duration, content: content, limit: limit, }, ...[truncated 4744 chars]- Remediation
View remediation
`, or `--retention-enabled`. 2. **Correct the Agent-facing documentation** - Update `SKILL.md` to state clearly that successful requests may be retained locally. - Describe the storage directory, retained fields, access implications, and cleanup procedure. - Remove the inaccurate statement that the Skill performs no write operations. 3. **Remove sensitive values from filenames** - Do not include raw or normalized search keywords, account identifiers, or video identifiers in filenames. - Use a random identifier or one-way hash, for example: ```js const filename = `${Date.now()}_${crypto.randomUUID()}.json`; ``` 4. **Apply restrictive permissions** - Create the log directory with mode `0o700`. - Create output files with mode `0o600`, subject to platform support: ```js await fs.promises.mkdir(logDirectory, { recursive: true, mode: 0o700, }); await fs.promises.writeFile(outputFilename, content, { encoding: "utf8", mode: 0o600, flag: "wx", }); ``` 5. **Minimize retained data** - Store only fields required for the user's stated purpose. - Exclude raw input, unnecessary metadata, and complete API responses unless explicitly requested. - Provide configurable redaction for account identifiers, URLs, and comment author information. 6. **Implement retention and cleanup controls** - Add a documented expiration period. - Automatically remove expired records. - Provide a command to list and securely delete retained output. - Ensure cleanup also covers failed or interrupted operations if temporary files are introduced. 7. **Provide explicit consent and destination reporting** - Before writing, communicate what will be stored and ...[truncated 113 chars]
