Repeated integration DELETE runs uninstall() again and can remove a shared install from another org

Aperta Adatta ai principianti
#129,229 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@sentry-junior ci sta già lavorando.

Dal 29/10/2026.

  • #129230 di @sentry-junior — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
django, python
Ambito
api, backend

Direzione di ricerca

Inizia in src/sentry/integrations/api/endpoints/organization_integration_details.py, in OrganizationIntegrationDetailsEndpoint.delete, e segui il controllo dello stato intorno alla chiamata a uninstall(). Restituisci 204 per le integrazioni già in stato PENDING_DELETION o DELETION_IN_PROGRESS, mantenendo l’ordine della prima DELETE. Aggiungi o esegui un test di regressione che invii DELETE due volte e confermi che la seconda richiesta non chiami di nuovo uninstall().

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug

Problem

OrganizationIntegrationDetailsEndpoint.delete (src/sentry/integrations/api/endpoints/organization_integration_details.py) calls the provider's uninstall() hook on every request, even when the OrganizationIntegration is already PENDING_DELETION:

  1. The org integration lookup doesn't filter on status, so a second DELETE finds the pending row.
  2. integration.get_installation(...).uninstall() runs unconditionally.
  3. Only after that, the status__in=[ACTIVE, DISABLED] guard prevents a second ScheduledDeletion and audit entry.
  4. The endpoint returns 204 either way.

The guard covers the database side effects, but not the external one.

Impact

Discord's and Cursor Origin's uninstall() only remove the external install when they think the current org is the last one using it, and they skip rows that are PENDING_DELETION / DELETION_IN_PROGRESS when counting.

With orgs A and B sharing one Discord server:

  • First DELETE from A: A's row is still active, the hook counts A and B, sees 2 installs and does nothing. A's row becomes pending.
  • Second DELETE from A (client retry, double click, replayed request): the hook now counts only B, sees 1 install, and calls leave_guild. The Sentry bot leaves the server that org B still uses.

Cursor Origin has the same pattern and would call delete_installation on an installation another org still uses to mint tokens.

Reproduced locally with a regression test on master: the second DELETE triggers one leave_guild call.

Fix

Return 204 before calling uninstall() when the org integration is already PENDING_DELETION or DELETION_IN_PROGRESS. The first DELETE keeps its current ordering (uninstall runs while the row is still active, so the hooks count it).

Notes

  • Concurrent first DELETEs can still both pass the check before either commits the status change. That window is narrow; closing it would mean holding a row lock across the external uninstall call, which this fix doesn't do.
  • Found during the endpoint idempotency audit in #128927.

via @BYK.

--

View Junior Session [Sentry]

Lingua principale
Python
Stelle
45.7k
Fork
5k
Merge medio
1g 5h
PR unite (30g)
596

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/sentry

Tutte le issue di getsentry/sentry

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.