{"id":"XE-1734","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":451,"title":"Pending proposal counts leak to write:patch-refs-only agent tokens via GET /v1/tickets","area":"other","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-09T01:43:44.406080+00:00","updated_at":"2026-11-14T22:57:04.296924+00:00","source_created_at":null,"told_at":"2026-11-10T14:00:35.264727+00:00","status_changed_at":"2026-11-10T14:00:33.596343+00:00","url":"https://bounty.xe.network/XE-1734","body":"## Summary\r\n\r\n`GET /v1/tickets` attaches a per-ticket `pending_proposals` count — how many agent proposals are still pending on that ticket — to **any** agent token, including a token scoped only to `write:patch-refs`. That count is part of the working layer (notes, proposals, the assessment as it changes) that the authorization matrix deliberately withholds from a patch-linking-only token (XE-0696): `read:notes` is granted to every agent scope *except* `write:patch-refs`. The HTML ticket list gets this right (team-only); the public JSON list does not. The leak is count-only — 0 vs 1+ pending proposals per ticket — never proposal contents.\r\n\r\n## Impact\r\n\r\n- **A least-privilege agent token learns which tickets have live assessment activity.** A `write:patch-refs`-only token exists to link PRs; with one `GET /v1/tickets` call it can enumerate every listed ticket and see which ones currently have pending proposals (i.e. an agent's recommendation is sitting undecided) and which do not. That is triage-state information the desk's own scoping rule says this token should not see.\r\n- **Count-only, so the damage is bounded.** No proposal text, field, value, or author leaks through this route: the single-ticket endpoint still gates proposals behind `can(p, \"read:notes\", t)`. What leaks is a per-ticket 0/1+ signal, visible in bulk across the whole list.\r\n- **Requires a valid agent token.** Tokens are issued by a team member and bound to them, so the reader is an agent the team onboarded — not an anonymous stranger. The finding is a scope-boundary violation for an already-trusted-but-narrowly-scoped token, not an unauthenticated leak.\r\n\r\n## Severity reasoning\r\n\r\n- **Low, not Medium:** only a count leaks (0 vs ≥1), never contents; the reader must hold a team-issued agent token; and the signal (a ticket has pending proposals) is a coarse triage hint, not an award, payout, or private-ticket disclosure.\r\n- **Low, not informational:** the matrix states the rule explicitly and the HTML route enforces it — the JSON route is an inconsistent enforcement of a deliberate scoping decision (XE-0696), so it is a real defect, not a design question.\r\n\r\n## Root cause\r\n\r\nTwo facts combine:\r\n\r\n1. **The JSON list hands pending counts to any agent.** `desk/api/public.py:135`:\r\n\r\n   ```python\r\n   pend = await tsvc.pending_counts(db, ids) if who.principal.is_team or who.principal.is_agent else {}\r\n   ```\r\n\r\n   and `desk/api/public.py:141` attaches it to every row:\r\n\r\n   ```python\r\n   d[\"pending_proposals\"] = pend.get(t.id, 0)\r\n   ```\r\n\r\n   `pending_counts` (`desk/services/tickets.py:535-543`) counts rows in the proposals table with `state == \"pending\"`, grouped by ticket — the live assessment queue, per ticket.\r\n\r\n2. **The matrix says a patch-linking-only token must not see the working layer.** `desk/authz.py:27-28`:\r\n\r\n   ```python\r\n   # the working layer (notes, proposals, the assessment as it changes) is for tokens that read or take\r\n   # part in it; a token that only links patches does not see it (XE-0696)\r\n   \"read:notes\": ((\"*\",), (\"read:public\", \"read:private\", \"write:notes\", \"write:proposals\")),\r\n   ```\r\n\r\n   `write:patch-refs` is absent from the `read:notes` scope list, and it is the only agent scope absent: `AGENT_SCOPES` (`desk/models.py:96`) is exactly five scopes — `read:public`, `read:private`, `write:notes`, `write:proposals`, `write:patch-refs` — and the first four all grant `read:notes`.\r\n\r\n   The HTML route enforces the same boundary correctly: `desk/ui.py:248` computes pending counts `if p.is_team else {}` — team-only. The JSON route's `or who.principal.is_agent` is the inconsistency.\r\n\r\n   The same file's single-ticket endpoint gets it right too: `desk/api/public.py:166-168` (in `get_ticket`) only includes `notes` and `proposals` `if can(p, \"read:notes\", t)`. Only the list endpoint leaks the count.\r\n\r\n## The narrowing, stated plainly\r\n\r\nThe naive reading — \"any agent token leaks pending counts\" — overstates the finding, and the correction matters:\r\n\r\n- **A `read:public`-only token does NOT leak.** The matrix grants `read:notes` to `read:public` (see `desk/authz.py:27-28` above), so a public-read token is *entitled* to see the working layer; giving it the count is consistent, not a leak.\r\n- **With `AGENT_SCOPES` fixed to five scopes, the ONLY token without `read:notes` is `write:patch-refs`-only.** Every other agent scope carries `read:notes` by the matrix. The leak is therefore exactly one token shape: a token whose sole scope is `write:patch-refs`.\r\n- **Count-only.** The leaked value is an integer per ticket (0 when there are no pending proposals, otherwise the count). No proposal field, value, reason, or author is exposed by this route.\r\n\r\n## Reproduction\r\n\r\n### A. Code trace (primary evidence — no live desk run)\r\n\r\nVerified by code trace. **No live desk instance was run** (no Postgres/docker on the verification VM), so the reproduction below is a trace of the exact code that executes, not a live end-to-end run:\r\n\r\n1. A team member issues an agent token with scopes `[\"write:patch-refs\"]` only (a valid subset of `AGENT_SCOPES`, `desk/models.py:96`).\r\n2. The token calls `GET /v1/tickets`. `who.principal.is_agent` is true, so `desk/api/public.py:135` computes `pending_counts` for every ticket id in the page, and `:141` adds `\"pending_proposals\": <count>` to each ticket dict in the response.\r\n3. The same token calling `GET /v1/tickets/{tid}` gets **no** `proposals` key (`desk/api/public.py:165-167`, gated on `read:notes`) — the count in the list response is the only place the working layer shows through.\r\n4. The same list rendered as HTML (`desk/ui.py:248`) shows no pending counts to anyone but the team — the JSON route is the outlier.\r\n\r\n### B. Contrast that confirms the boundary is deliberate\r\n\r\nThe pending *filter* is team-only: `desk/services/tickets.py:314-322` raises 403 (`\"gate, has_internal, pending, reporter and queued are team filters\"`) when a non-team caller passes `pending=`. The desk already treats \"has pending proposals\" as team information for filtering — the list endpoint then hands the same signal to any agent token as a count.\r\n\r\n## Dedup note\r\n\r\nClosest known work, by code reference — the live report list was not re-checked during this drafting pass, and the submitter should confirm against it before filing:\r\n\r\n- **XE-0696** — the scoping rule itself: a token that only links patches does not see the working layer. This report is about the one route that violates that rule (the JSON ticket list), not about the rule.\r\n- No other in-code reference gates pending counts by scope; the HTML route (`desk/ui.py:248`) and the single-ticket endpoint (`desk/api/public.py:165-167`) both enforce the boundary this route misses.\r\n\r\n## Suggested fix direction\r\n\r\n- Mirror the HTML route in the JSON list: compute `pending_counts` only `if who.principal.is_team`, or — more precisely — only when `can(who.principal, \"read:notes\")` holds, so the count follows the same permission the single-ticket endpoint already uses for proposal contents.\r\n- Alternatively, keep the count but gate it per ticket the way `get_ticket` gates proposals; the team-only form is simpler and matches `desk/ui.py:248`.\r\n\r\n## Payout address\r\n\r\n052e33e0ed9c43e2bdf07faff9a90d25642b51d53d96f49f5d45b81f6584b3da\r\n\r\n## References (file:line; desk @ 186af22)\r\n\r\n| Location | What it shows |\r\n|---|---|\r\n| `desk/api/public.py:135` | `pending_counts` computed for team **or any agent** |\r\n| `desk/api/public.py:141` | `pending_proposals` count attached to every listed ticket |\r\n| `desk/api/public.py:166-168` | Single-ticket endpoint gates `notes`/`proposals` on `read:notes` — the count route does not |\r\n| `desk/services/tickets.py:535-543` | `pending_counts`: counts `Proposal.state == \"pending\"` per ticket |\r\n| `desk/services/tickets.py:314-322` | `pending` filter is team-only (403 for others) — the signal is treated as team information |\r\n| `desk/authz.py:27-28` | `read:notes` granted to every agent scope **except** `write:patch-refs` (XE-0696) |\r\n| `desk/models.py:96` | `AGENT_SCOPES`: exactly five scopes, so `write:patch-refs`-only is the only token without `read:notes` |\r\n| `desk/ui.py:248` | HTML list gates pending counts on team-only — the correct enforcement the JSON route lacks |","patch_refs":[],"thread":[{"id":2143,"source":"desk","source_ref":"reply:1510","author":"Joseph Denne","team":true,"body":"Thank you for this report. We have read it against the code and it is being handled. The assessment and any award follow the fix. https://bounty.xe.network/XE-1734","created_at":"2026-11-10T14:00:19.792775+00:00"}]}