Skip to content

Gate the Discord /assign command on the invoker - #325

Open
joei4cm wants to merge 2 commits into
CopilotKit:mainfrom
joei4cm:fix/275-assign-invoker-gate
Open

joei4cm wants to merge 2 commits into
CopilotKit:mainfrom
joei4cm:fix/275-assign-invoker-gate

Conversation

@joei4cm

@joei4cm joei4cm commented Dec 3, 2026 •

Copy link
Copy Markdown

Closes #275.

/assign resolved a ticket from the display id the invoker typed and reassigned it, with no check on who was asking or whether the ticket belonged to the invoking context. Display ids are public by design — they are pasted into community threads — and the web routes and the email reply path both check the session or the sender before touching a ticket; this command did not.

Two gates, using the shape the codebase already has:

  • Who may reassign: only team members, via isTeamMember() in apps/discord-bot/src/lib/tickets.ts — a helper that existed for exactly this check and had no callers until now. It counts only TeamMember rows with status === 'ACTIVE': a DISABLED member keeps their Discord link and email, and an INVITED one has not accepted yet, so neither may act.
  • Which ticket: an explicit ticket id must resolve to a Discord ticket whose thread lives in the invoking guild (client.channels.fetch(sourceId) → guildId). Tickets from other sources, threads in another guild, deleted threads and null fetch results all get the same "No ticket found" reply as a bad id, so the answer never reveals that the ticket exists elsewhere. Only Discord's unknown-channel/unknown-guild codes (10003/10004) map to "unreachable" — a rate limit or API outage surfaces as an error rather than a false "no ticket found".

The thread-context path (no ticket option) is unchanged apart from the team-member gate — findTicketByThreadId already scopes it to the current thread.

/close, /escalate and /priority have the same missing invoker check but are scoped to the current thread's ticket; this PR stays on the issue's /assign scope. Worth a follow-up if the team wants the same gate everywhere.

Tests:

  • apps/discord-bot suite — 76/76 passed. New tests cover the non-team-member rejection, non-Discord and cross-guild tickets, a deleted thread, a null fetch result, a transient API failure rethrowing, and DISABLED/INVITED membership rejection; they fail on the previous implementation.
  • discord-bot typecheck, tsc build, ESLint (0 errors), Prettier, git diff --check passed
  • Built-in medium code-review fallback was launched per the repo's pre-push rule but did not return within ~17 minutes; proceeded with a manual self-review of the diff instead (same fallback as Factory reset accepts reseed: true but cannot re-seed #205). When it later returned, its findings were applied in a follow-up commit (ACTIVE-status requirement, transient-error distinction).

🤖 Generated with Claude Code

joei4cm and others added 2 commits December 3, 2026 18:56
/assign resolved a ticket from the display id the invoker typed and
reassigned it without checking who was asking or whether the ticket was
reachable from the invoking guild. Display ids are public — they are pasted
into community threads — so the id alone is not evidence of belonging.

Only team members may reassign now, via the isTeamMember helper that already
existed for exactly this check. A ticket named by id must also be a Discord
ticket whose thread lives in this guild; anything else gets the same reply
as a bad id, so the answer never reveals that the ticket exists elsewhere.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…sign

isTeamMember now only counts TeamMember rows with status ACTIVE — a
DISABLED or INVITED member keeps their Discord link and email but must
not be able to reassign tickets. The ticket-reachability check also
stops swallowing every channels.fetch failure: only Discord's 'unknown
channel'/'unknown guild' codes mean the ticket is unreachable, so a
rate limit or API outage now surfaces as an error instead of a false
'no ticket found'.

Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gate the Discord /assign command on the invoker, not just the ticket id

1 participant