Skip to content

Commit e6157cb

Browse files
committed
utils.py: update CSP handling for django-csp version compatibility
1 parent 8cefd5f commit e6157cb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

djangosaml2/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import zlib
1919
from functools import lru_cache, wraps
2020
from typing import Optional
21+
import importlib.metadata
2122

2223
from django.conf import settings
2324
from django.core.exceptions import ImproperlyConfigured
@@ -254,4 +255,14 @@ def _django_csp_update_decorator():
254255
else:
255256
# autosubmit of forms uses nonce per default
256257
# form-action https: to send data to IdPs
257-
return csp_update(FORM_ACTION=["https:"])
258+
try:
259+
csp_version = importlib.metadata.version("django-csp")
260+
except importlib.metadata.PackageNotFoundError:
261+
csp_version = "0"
262+
263+
major_version = int(csp_version.split(".")[0])
264+
265+
if major_version >= 4:
266+
return csp_update({"form-action": ["https:"]})
267+
else:
268+
return csp_update(FORM_ACTION=["https:"])

0 commit comments

Comments
 (0)