T09 · Insecure Skill Coding Practices
- Location
scripts/podcast-upload-batch.js:123- Finding
Overbroad Playlist Cleanup Can Remove Legitimate YouTube Playlist Entries
- Content
View full analysis
- Remediation
View remediation
ep.oldVideoId).filter(Boolean) ); for (const it of r.body.items || []) { const videoId = it.snippet.resourceId.videoId; if (!removableVideoIds.has(videoId)) continue; const d = await api( "DELETE", `https://www.googleapis.com/youtube/v3/playlistItems?id=${encodeURIComponent(it.id)}`, access ); if (d.status !== 204) { console.error(`[playlist] remove failed: ${errDetail(d)}`); return false; } } ``` 2. **Separate broad cleanup from normal publication.** If stale-item cleanup is genuinely required, place it behind an explicit option such as `--remove-stale` rather than running it in the default pipeline. 3. **Require confirmation for destructive operations.** Print the playlist item ID, video ID, and title of every proposed removal. Require interactive confirmation unless a clearly named noninteractive approval flag is supplied. 4. **Validate state completeness.** Before any deletion, verify that all expected metadata episodes have corresponding upload records and that those video IDs exist on YouTube. Abort cleanup if state is incomplete or inconsistent. 5. **Preserve an audit and recovery record.** Save the removed playlist item ID, video ID, title, playlist ID, timestamp, and reason before issuing each deletion request. This assists reconstruction after an accidental removal. 6. **Add ownership and intent checks.** Confirm that the configured playlist is the expected playlist and that each removal candidate corresponds to a known replacement relationship. 7. **Improve naming and state semantics.** Replace the ambiguous `removedOldItem` Boolean with per-video records, such as `removedPlaylistItems[oldVideoId]`, ...[truncated 83 chars]
