Missing state event for pre-closed imports in desk allows the push worker to reopen a reporter's closed GitHub issue
Report
CVSS: 5.3 (AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N)
Summary
The desk log is the audit trail for a ticket's GitHub state, and the invariant "latest github.state event == API github_state" holds on the full population — except by construction on the creation path. upsert_issue creates a ticket for a GitHub issue with NewTicket(..., github_state=state) (desk/services/sync.py, creation branch; tsvc.create bakes it in at desk/services/tickets.py:258) and appends only ticket.created — no github.state event, and no github.closed_externally event either. The refresh path for an existing ticket (sync.py:154-161) appends both. So a ticket imported from an issue that was already closed on GitHub carries github_state="closed" with zero trace in the log, and the "closed before the desk ruled, mirror as stale" handling is skipped entirely.
Downstream, once the ticket leaves status new it enters tickets_needing_push (sync.py:864-870, status != new, public, github) and push_state (sync.py:749-770) computes want = "open" (status not closed/paid) != github_state ("closed"), so it calls client.set_state(repo, n, "open") — reopening the author's deliberately closed issue on GitHub — and records only a github.state_pushed event. writes_to_issue (sync.py:717-723: source github + repo + public) passes for such a ticket.
The reopen is conditional on triage + the GitHub token being restored (the token is currently dead per XE-4992/XE-11211, so it cannot fire live today); the log gap is live now and permanent — no code path ever appends a retroactive github.state event (contrast github.labels, whose creation-path gap self-heals at first push_labels, which appends the full list).
Steps to reproduce
- On GitHub, open an issue on
xeprotocol/xe, then close it. - Trigger a desk import of that issue (poll, webhook, or CLI import — all go through
upsert_issue). GET /v1/tickets/<id>→github_state: "closed",status: "new".GET /v1/tickets/<id>/log→ onlyticket.created(+ first-touch note); nogithub.state, nogithub.closed_externally.GET /v1/log?kind=github.statehas no event for the ticket.- Once the ticket is triaged (status leaves
new) and the GitHub client is enabled, the push pass runspush_state: want"open"!="closed"→set_state(..., "open")reopens the GitHub issue.
Live instance: XE-13253
Public, bounty, github xeprotocol/xe#383, status new, created 2026-11-14T20:42:03Z, source_created_at 2026-11-11T12:43:36Z. Live GitHub issue #383: state closed, closed_at 2026-11-11T14:34:45Z — closed by its author ~2h after creation, ~3 days before the desk imported it. Single-ticket API (fetched twice): github_state: "closed", github_labels: None. Per-ticket log (fetched twice, limit=500): exactly 2 events (ticket.created, note.added), zero github.* events. Global log: github.state population still 3 events, none for XE-13253. Full-population compare (2,272 tickets): exactly 1 API-closed-no-event ticket in 2,272; all other legs 0 violations (shapes, alternation, closed_externally pairing 3/3, reverse, pushed 71/71, latest-vs-API on the 74 event tickets).
Impact
Integrity: the signed audit log silently omits a material state fact for an imported ticket, and the desk's own push worker is then primed to undo the reporter's deliberate action on GitHub (reopen a closed issue) once the ticket is triaged and the GitHub token is restored. Any GitHub user can trigger it by opening and closing an issue before import; no desk privilege needed; deterministic code path.
Mitigation
In the upsert_issue creation branch, after tsvc.create, mirror the refresh path: if state != "open", append github.state {ticket, state}; and if state == "closed" and the ticket status is open/editable, append github.closed_externally {ticket, status}. (Alternative: create with github_state="open" and let the refresh path record the transition — same event trail, no new branch.) No retroactive repair is possible for the event hash chain — XE-13253's missing event cannot be backfilled without breaking log verification; the fix prevents new instances.
Dup-check
Live queries 2026-11-15: q=github.state → XE-0768, XE-0273, XE-12802; q=github_state → + XE-6996, XE-13131, XE-13133; q=already closed → XE-3910, XE-0989, XE-13382; q=import closed → 0; q=closed issue → XE-0228, XE-0004, XE-6996; q=state event → XE-3548. All 11 checked by title + single-ticket fetch — none is this finding. Closest prior XE-0273 is the refresh-path title/body rewrite (different field, different path, no cross-system write-back). /v1/tickets/XE-13253/similar → XE-12189 (same campaign, different ticket), XE-0668 (unrelated lease finding). Code check at desk HEAD ab9df7f: no path appends a retroactive github.state event.
Thread
Thanks for the report. It has been read against the current code and is being handled. The assessment and any award follow the fix.