Skip to content

Commit

Permalink
feat: disable introspection via validation rules property
Browse files Browse the repository at this point in the history
Introduce a new setting to disable introspection. Introspection remains
enabled in dev/test environments, but disabled in production.
  • Loading branch information
derrabauke authored and winged committed Jan 30, 2024
1 parent d04282b commit 18a313b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions caluma/caluma_user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.http.response import HttpResponse
from django.utils.encoding import force_bytes, smart_str
from django.utils.module_loading import import_string
from graphene.validation import DisableIntrospection
from graphene_django.views import GraphQLView, HttpError
from rest_framework.authentication import get_authorization_header

Expand All @@ -19,6 +20,9 @@ class HttpResponseUnauthorized(HttpResponse):


class AuthenticationGraphQLView(GraphQLView):
if settings.DISABLE_INTROSPECTION: # pragma: no cover
validation_rules = (DisableIntrospection,)

def get_bearer_token(self, request):
auth = get_authorization_header(request).split()
header_prefix = "Bearer"
Expand Down
6 changes: 6 additions & 0 deletions caluma/settings/caluma.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):
"RELAY_CONNECTION_MAX_LIMIT": None,
}

# If you set DISABLE_INTROSPECTION to True, any GQL client will not be able to
# query the types and connections, making crafting queries much harder (but not
# impossible, and this is an Open Source product, so they can still go check
# the source).
DISABLE_INTROSPECTION = env.bool("DISABLE_INTROSPECTION", default=default(False, True))

# OpenID connect

OIDC_USERINFO_ENDPOINT = env.str("OIDC_USERINFO_ENDPOINT", default=None)
Expand Down

0 comments on commit 18a313b

Please sign in to comment.