T09 · Insecure Skill Coding Practices
- Location
SKILL.md:172- Finding
Global IMAP EXPUNGE Can Permanently Delete Unapproved Messages
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 172–186
Vulnerability Type: Unsafe IMAP deletion semantics
Risk Level: HighVulnerable Code Snippet:
markdown ### What It Does 1. Shows classified email counts by category 2. User reviews and approves DELETE_DOMAINS list and KEEP_DOMAINS list 3. **Safety net**: Copies target emails to a staging folder (e.g., "广告邮件") BEFORE deleting from INBOX 4. Deletes from INBOX via `UID STORE +FLAGS \Deleted` + `EXPUNGE` 5. Random-sample verification (10 emails spot-checked) ### The Safe Deletion FlowINBOX emails ──UID COPY──> 广告邮件夹 (staging copy) │ └── UID STORE \Deleted + EXPUNGE (remove from INBOX)
User verifies in web client...
text ### Technical Analysis Although `UID STORE` marks only the approved messages with the IMAP `\Deleted` flag, the subsequent standard `EXPUNGE` command is mailbox-wide. It permanently removes every message already marked `\Deleted` in the selected mailbox, not only the UIDs selected by this cleanup workflow. Consequently, messages previously marked for deletion by another mail client, another session, or an interrupted operation may be expunged without being included in the reviewed target set. The staging-copy safeguard applies only to messages selected by this skill and therefore does not protect unrelated messages carrying a pre-existing `\Deleted` flag. This behavior also contradicts the skill's stated safety guarantee that messages are not permanently deleted without user approval. ### Attack Path 1. A separate IMAP or webmail client marks an unrelated message as `\Deleted` but does not expunge it. 2. The user approves a different set of messages for cleanup. 3. The skill copies only its approved target messages to the staging folder. 4. The skill applies `\Deleted` to the approved UIDs using `UID STORE`. 5. The skill executes the mailbox-wide `EXPUNGE` command. 6. The server perma ...[truncated 692 chars]- Remediation
View remediation
Remediation Suggestions
- Use
UID EXPUNGE <approved-uids>when the server advertises support for UIDPLUS, so permanent deletion is restricted to the reviewed UID set. - Prefer moving approved messages to the server's Trash folder without immediately expunging them. Let retention policy or a separate, explicitly confirmed purge remove them permanently.
- Before deletion, query and record all pre-existing
\Deletedmessages. Abort if unrelated deleted flags are present, or temporarily clear and later restore those flags when server behavior permits. - Serialize the cleanup operation and warn the user to close or pause other mailbox clients to reduce concurrent state changes.
- Verify that every approved UID was copied successfully before marking any original message as deleted. A successful IMAP response alone should not substitute for destination verification.
- Re-fetch and display the exact UID set immediately before permanent deletion, then require explicit confirmation.
- Maintain a durable transaction log containing source mailbox, source UID, destination mailbox, destination UID or Message-ID, copy status, and deletion status.
- Treat random sampling as supplemental verification only; destructive processing should verify every targeted message.
- Use
