Skip to content

Commit 3f1e820

Browse files
authored
Merge pull request #329 from openimis/feauture/OS-90
OS-90: validating GraphQL Content-Type
2 parents 8dacc37 + 1c0fbcf commit 3f1e820

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

openIMIS/openIMIS/settings/prod.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@
3131
USE_X_FORWARDED_HOST = BEHIND_PROXY
3232
SECURE_SSL_REDIRECT = not BEHIND_PROXY # Only redirect if not behind a proxy
3333

34-
# CSRF settings
35-
CSRF_COOKIE_SECURE = True
36-
SESSION_COOKIE_SECURE = True
37-
38-
# CORS settings
39-
CORS_ALLOW_CREDENTIALS = True
40-
41-
# Cookie settings
42-
SESSION_COOKIE_SAMESITE = 'Lax' # or 'None' if cross-site
43-
CSRF_COOKIE_SAMESITE = 'Lax' # or 'None' if cross-site
44-
CSRF_COOKIE_HTTPONLY = False # False if you need to access it from JavaScript
45-
4634
# HSTS settings (if using HTTPS)
4735
if 'https' in protos:
4836
SECURE_HSTS_SECONDS = 31536000 # 1 year

openIMIS/openIMIS/settings/security.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,19 @@
8989
RATELIMIT_GROUP = os.getenv('RATELIMIT_GROUP', 'graphql')
9090
RATELIMIT_SKIP_TIMEOUT = os.getenv('RATELIMIT_SKIP_TIMEOUT', 'False')
9191

92-
93-
92+
# CSRF settings
93+
CSRF_COOKIE_SECURE = True
94+
SESSION_COOKIE_SECURE = True
95+
# session cookie validity = 8 hours
96+
SESSION_COOKIE_AGE = 28800
97+
98+
# CORS settings
99+
CORS_ALLOW_CREDENTIALS = True
100+
101+
# Cookie settings
102+
SESSION_COOKIE_SAMESITE = 'Lax' # or 'None' if cross-site
103+
CSRF_COOKIE_SAMESITE = 'Lax' # or 'None' if cross-site
104+
CSRF_COOKIE_HTTPONLY = False # False if you need to access it from JavaScript
94105

95106
# Adjust other settings as needed for your specific application
96107
# ...

openIMIS/openIMIS/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.db import connection, transaction
2-
from django.http import HttpResponseNotAllowed
2+
from django.http import HttpResponseNotAllowed, HttpResponse
33
from django.http.response import HttpResponseBadRequest
44
from .dataloaders import get_dataloaders
55
from . import tracer
@@ -86,6 +86,11 @@ def parse_body(self, request):
8686
def execute_graphql_request(
8787
self, request, data, query, variables, operation_name, show_graphiql=False
8888
):
89+
if not request or getattr(request, "content_type", "") != "application/json":
90+
raise HttpError(HttpResponse(
91+
"Unsupported Media Type: The server only accepts application/json requests.",
92+
status=415,
93+
))
8994
if not query:
9095
if show_graphiql:
9196
return None

0 commit comments

Comments
 (0)