Skip to content

Commit ea3bc00

Browse files
committed
changes from security audit 2024 November
1 parent 7c6d9d4 commit ea3bc00

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

openIMIS/openIMIS/settings.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def SITE_URL():
224224
"django.middleware.csrf.CsrfViewMiddleware",
225225
"django.contrib.auth.middleware.AuthenticationMiddleware",
226226
"core.middleware.SecurityHeadersMiddleware",
227+
"csp.middleware.CSPMiddleware",
227228
]
228229

229230
MODE = os.environ.get("MODE")
@@ -334,10 +335,6 @@ def SITE_URL():
334335
"JWT_COOKIE_SAMESITE": "Lax",
335336
})
336337

337-
CSRF_COOKIE_SECURE = True
338-
CSRF_COOKIE_HTTPONLY = True
339-
CSRF_COOKIE_SAMESITE = 'Lax'
340-
341338
SECURE_BROWSER_XSS_FILTER = True
342339
SECURE_CONTENT_TYPE_NOSNIFF = True
343340
SECURE_HSTS_SECONDS = 63072000
@@ -659,3 +656,29 @@ def SITE_URL():
659656
PASSWORD_SYMBOLS = int(os.getenv('PASSWORD_SYMBOLS', 1))
660657

661658
IS_UNIT_TEST_ENV = 'test' in sys.argv
659+
660+
# CSRF settings
661+
CSRF_COOKIE_SECURE = True
662+
SESSION_COOKIE_SECURE = True
663+
# session cookie validity = 8 hours
664+
SESSION_COOKIE_AGE = 28800
665+
SESSION_COOKIE_NAME = "openimis_session"
666+
667+
# CORS settings
668+
CORS_ALLOW_CREDENTIALS = True
669+
670+
# Cookie settings
671+
CSRF_COOKIE_NAME = 'csrftoken'
672+
CSRF_USE_SESSIONS = True
673+
SESSION_COOKIE_SAMESITE = 'Lax' # or 'None' if cross-site
674+
CSRF_COOKIE_SAMESITE = 'Lax' # or 'None' if cross-site
675+
CSRF_COOKIE_HTTPONLY = False # False if you need to access it from JavaScript
676+
677+
USER_AGENT_CSRF_BYPASS = []
678+
679+
CSP_DEFAULT_SRC = ["'self'"]
680+
CSP_SCRIPT_SRC = ["'self'"]
681+
CSP_STYLE_SRC = ["'self'"]
682+
CSP_IMG_SRC = ["'self'", "data:"] # Allows images from the same origin and base64 encoded images
683+
CSP_FRAME_ANCESTORS = ["'self'"]
684+

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ waitress
3232
wheel
3333
whitenoise
3434
django-health-check
35-
requests~=2.32.0
35+
requests~=2.32.0
3636
apscheduler==3.10.1
3737
# As from v0.4, Django-apscheduler has a migration that is incompatible with SQL Server
3838
# (autoincrement int => bigint) so we are using our own fork with a squashed migration
@@ -57,3 +57,4 @@ django-opensearch-dsl==0.5.1
5757
zxcvbn~=4.4.28
5858
password-validator==1.0
5959
django-axes==6.4.0
60+
django-csp

0 commit comments

Comments
 (0)