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

Đang mở Phù hợp với người mới
#129,229 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@sentry-junior đang làm issue này rồi.

Từ ngày 29/10/2026.

  • #129230 của @sentry-junior — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
django, python
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu tại src/sentry/integrations/api/endpoints/organization_integration_details.py, trong OrganizationIntegrationDetailsEndpoint.delete, và theo dõi phần kiểm tra trạng thái xung quanh lời gọi uninstall(). Trả về 204 cho các integration đã ở trạng thái PENDING_DELETION hoặc DELETION_IN_PROGRESS, đồng thời giữ nguyên thứ tự của DELETE đầu tiên. Thêm hoặc chạy một bài kiểm thử hồi quy gửi DELETE hai lần và xác nhận rằng yêu cầu thứ hai không gọi lại uninstall().

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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]

Ngôn ngữ chính
Python
Star
45.7k
Fork
5k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
655

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/sentry

Tất cả issue của getsentry/sentry

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.