Skip to content

Commit 39ed9f2

Browse files
authored
fix(integrations): fix CORS issue on GitHub-initiated GitHub installation (#59137)
Fixes this CORS issue when trying to install GitHub integration from GitHub side: > Access to fetch at 'https://sentry.io/extensions/github/installation/xxxxxxxx/' from origin 'https://sentry.sentry.io' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. Follow-up fix of #59000
1 parent e3cf39f commit 39ed9f2

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/sentry/integrations/github/installation.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import time
55

66
from django.http import HttpResponse
7-
from django.views.generic import View
7+
from rest_framework.permissions import IsAuthenticated
88
from rest_framework.request import Request
99

10+
from sentry.api.api_owners import ApiOwner
11+
from sentry.api.api_publish_status import ApiPublishStatus
12+
from sentry.api.base import Endpoint, control_silo_endpoint
1013
from sentry.constants import ObjectStatus
1114
from sentry.models.integrations.integration import Integration
1215
from sentry.models.integrations.organization_integration import OrganizationIntegration
@@ -17,7 +20,15 @@
1720
INSTALLATION_EXPOSURE_MAX_TIME = 10 * 60
1821

1922

20-
class GitHubIntegrationsInstallationEndpoint(View):
23+
@control_silo_endpoint
24+
class GitHubIntegrationsInstallationEndpoint(Endpoint):
25+
publish_status = {
26+
"GET": ApiPublishStatus.PRIVATE,
27+
}
28+
owner = ApiOwner.ENTERPRISE
29+
30+
permission_classes = (IsAuthenticated,)
31+
2132
def get(self, request: Request, installation_id):
2233
try:
2334
integration = Integration.objects.get(

static/app/data/controlsiloUrlPatterns.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const patterns: RegExp[] = [
44
new RegExp('^remote/github/marketplace/purchase/$'),
55
new RegExp('^docs/api/user/$'),
66
new RegExp('^_experiment/log_exposure/$'),
7+
new RegExp('^api/0/signup/$'),
78
new RegExp('^api/0/audit-logs/$'),
89
new RegExp('^api/0/_admin/options/$'),
910
new RegExp('^api/0/billingadmins/$'),
@@ -141,6 +142,7 @@ const patterns: RegExp[] = [
141142
new RegExp('^extensions/slack/link-identity/[^/]+/$'),
142143
new RegExp('^extensions/slack/unlink-identity/[^/]+/$'),
143144
new RegExp('^extensions/github/webhook/$'),
145+
new RegExp('^extensions/github/installation/[^/]+/$'),
144146
new RegExp('^extensions/github/search/[^/]+/[^/]+/$'),
145147
new RegExp('^extensions/gitlab/search/[^/]+/[^/]+/$'),
146148
new RegExp('^extensions/vsts/search/[^/]+/[^/]+/$'),

tests/sentry/integrations/github/test_installation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class InstallationEndpointTest(APITestCase):
1717
base_url = "https://api.github.com"
1818

1919
def setUp(self):
20+
self.login_as(self.user)
2021
self.url = "/extensions/github/webhook/"
2122
self.secret = "b3002c3e321d4b7880360d397db2ccfd"
2223
options.set("github-app.webhook-secret", self.secret)

0 commit comments

Comments
 (0)