Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 508e696

Browse files
fix: Disable GraphQL introspection in prod
1 parent 564cad4 commit 508e696

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

codecov/settings_base.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292

9393
WSGI_APPLICATION = "codecov.wsgi.application"
9494

95-
9695
# GraphQL
9796

9897
GRAPHQL_QUERY_COST_THRESHOLD = get_config(
@@ -105,6 +104,8 @@
105104

106105
GRAPHQL_RATE_LIMIT_RPM = get_config("setup", "graphql", "rate_limit_rpm", default=300)
107106

107+
GRAPHQL_INTROSPECTION_ENABLED = False
108+
108109
# Database
109110
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
110111

@@ -184,7 +185,6 @@
184185

185186
USE_TZ = True
186187

187-
188188
# Static files (CSS, JavaScript, Images)
189189
# https://docs.djangoproject.com/en/2.1/howto/static-files/
190190

@@ -308,7 +308,6 @@
308308
"gitlab", "bots", "tokenless", "key", default=GITLAB_BOT_KEY
309309
)
310310

311-
312311
GITLAB_ENTERPRISE_CLIENT_ID = get_config("gitlab_enterprise", "client_id")
313312
GITLAB_ENTERPRISE_CLIENT_SECRET = get_config("gitlab_enterprise", "client_secret")
314313
GITLAB_ENTERPRISE_REDIRECT_URI = get_config(
@@ -323,7 +322,6 @@
323322
GITLAB_ENTERPRISE_URL = get_config("gitlab_enterprise", "url")
324323
GITLAB_ENTERPRISE_API_URL = get_config("gitlab_enterprise", "api_url")
325324

326-
327325
CORS_ALLOW_HEADERS = (
328326
list(default_headers)
329327
+ ["token-type"]
@@ -344,7 +342,6 @@
344342
"setup", "http", "file_upload_max_memory_size", default=2621440
345343
)
346344

347-
348345
CORS_ALLOWED_ORIGIN_REGEXES = get_config(
349346
"setup", "api_cors_allowed_origin_regexes", default=[]
350347
)
@@ -362,7 +359,6 @@
362359

363360
HIDE_ALL_CODECOV_TOKENS = get_config("setup", "hide_all_codecov_tokens", default=False)
364361

365-
366362
SENTRY_JWT_SHARED_SECRET = get_config(
367363
"sentry", "jwt_shared_secret", default=None
368364
) or get_config("setup", "sentry", "jwt_shared_secret", default=None)

codecov/settings_dev.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@
5555
# SHELTER_SHARED_SECRET = "test-supertoken"
5656

5757
GUEST_ACCESS = True
58+
59+
GRAPHQL_INTROSPECTION_ENABLED = True

codecov/settings_staging.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@
7575
CSRF_TRUSTED_ORIGINS = [
7676
get_config("setup", "trusted_origin", default="https://*.codecov.dev")
7777
]
78+
79+
GRAPHQL_INTROSPECTION_ENABLED = True

codecov/settings_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
# Mock the Pub/Sub host for testing
1111
# this prevents the pubsub SDK from trying to load credentials
1212
os.environ["PUBSUB_EMULATOR_HOST"] = "localhost"
13+
14+
GRAPHQL_INTROSPECTION_ENABLED = True

graphql_api/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import TypedDict
2+
3+
from django.conf import settings
4+
5+
6+
# Possible options are defined here: https://ariadnegraphql.org/docs/0.4.0/django-integration#configuration-options
7+
class AriadneDjangoConfigOptions(TypedDict):
8+
introspection: bool
9+
10+
11+
graphql_config: AriadneDjangoConfigOptions = {
12+
"introspection": getattr(settings, "GRAPHQL_INTROSPECTION_ENABLED", False),
13+
}

graphql_api/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from services import ServiceException
2828
from services.redis_configuration import get_redis_connection
2929

30+
from .config import graphql_config
3031
from .schema import schema
3132

3233
log = logging.getLogger(__name__)
@@ -378,7 +379,7 @@ def get_client_ip(self, request):
378379
return ip
379380

380381

381-
BaseAriadneView = AsyncGraphqlView.as_view()
382+
BaseAriadneView = AsyncGraphqlView.as_view(**graphql_config)
382383

383384

384385
async def ariadne_view(request, service):

0 commit comments

Comments
 (0)