forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Summary
Adversarial review of cancel_task tool revealed issues in the underlying Session.cancelBackgroundTask() function.
Issues Found
CRITICAL: Missing Authorization Control
tryCancel()does NOT validate caller has permission to cancel a specific task- Any session can cancel ANY task in the system
CRITICAL: TOCTOU Race Condition
- Time-of-check-time-of-use between status check (line 562) and actual cancellation (line 569)
- Task can complete between check and cancel, leading to incorrect state
CRITICAL: Double-Modify State Corruption
cancelBackgroundTask()mutatesbackgroundTaskResultsafter task completion- Completed tasks can be incorrectly marked as "failed"
- Result data lost, audit trail corrupted
MEDIUM: Slot Release Race
release_slot()called before deleting from maps- Brief window for double-reservation
Location
/packages/opencode/src/session/index.ts
- Lines 499-548:
cancelBackgroundTask() - Lines 550-581:
tryCancel()
Impact
For current use case (PM cancelling own tasks), risk is low. But these should be fixed before:
- Multi-user scenarios
- Cross-session task management
- Production deployment
Recommended Fixes
- Add session ownership check before cancel
- Make status check + cancel atomic
- Never mutate already-completed task results
- Reorder slot release to after map deletion
Metadata
Metadata
Assignees
Labels
No labels