T09 · Insecure Skill Coding Practices
- Location
scripts/zhanfu_ops.mjs:199- Finding
Destructive cache deletion lacks executable confirmation enforcement
- Content
View full analysis
Vulnerability Details
File Location:
scripts/zhanfu_ops.mjs:199-231, 283-289
Vulnerability Type: Destructive operation without enforced confirmation
Risk Level: MediumComplete Code Snippet
js async function cmdClearCache(ns) { if (ns.all) { const blocked = needWin("ClearCacheFolder"); if (blocked != null) return blocked; const port = tryPreferredPort(); if (port == null) return emitZhanfuDown(); const data = await call("ClearCacheFolder", { args: "{}", timeout: 30, port }); const ro = data.returnObj || {}; if (typeof ro !== "object" || ro.success !== true) { const msg = typeof ro === "object" ? ro.msg : data; console.log(String(msg)); return emit({ ok: false, status: "failed", msg: String(msg) }, 1); } clearOpeningMalls(); clearOpenedMalls(); console.log("已清除全部店铺缓存。"); return emit({ ok: true, status: "cleared_all" }, 0); } const blocked = needWin("ClearCache"); if (blocked != null) return blocked; if (!ns.mallName) { console.log("单店清缓存需要 --mall-name,或使用 --all"); return emit({ ok: false, status: "missing_args" }, 1); } const port = tryPreferredPort(); if (port == null) return emitZhanfuDown(); let mallId = await resolveMallId(ns.mallName, { port }); let data = await call("ClearCache", { browserId: mallId, args: "", timeout: 30, port }); let ro = data.returnObj || {}; if (typeof ro !== "object" || ro.success !== true) { mallId = await resolveMallIdRefreshOnce(ns.mallName, port); data = await call("ClearCache", { browserId: mallId, args: "", timeout: 30, port }); ro = data.returnObj || {}; } if (typeof ro !== "object" || ro.success !== true) { const msg = typeof ro === "object" ? ro.msg : data; console.log(String(msg)); return emit({ ok: false, status: "failed", msg: String(msg) }, 1); } removeOpeningMall(ns.mallName); unmarkMallOpened(ns.mallName); console.log(`已清除店铺 ${ns.mallName} 缓存。mall_id=${mallId}`) ...[truncated 2437 chars]- Remediation
View remediation
Remediation Suggestions
- Require an explicit, non-default confirmation capability:
--confirm-clear-allfor global deletion.--confirm-mall TARGET_SHOPmatching the exact--mall-namevalue for single-shop deletion.
- Reject execution unless the appropriate confirmation value is present and valid.
- Add a dry-run mode that displays the exact shop or global scope without invoking
ClearCacheorClearCacheFolder. - For interactive use, show the affected scope and require a precise confirmation phrase rather than a generic yes/no response.
- Keep the confirmation requirement in
SKILL.md, but treat it as supplementary guidance rather than the security control. - Add automated tests verifying that both deletion paths fail closed when confirmation is absent, malformed, or refers to a different shop.
- Consider requiring a fresh confirmation nonce generated after displaying the deletion scope, preventing stale or accidentally reused command arguments.
- Require an explicit, non-default confirmation capability:
