Skip to content

Fix: Add compatibility for django-csp 4.x in CSP update decorator #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion djangosaml2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import zlib
from functools import lru_cache, wraps
from typing import Optional
import importlib.metadata

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -254,4 +255,14 @@ def _django_csp_update_decorator():
else:
# autosubmit of forms uses nonce per default
# form-action https: to send data to IdPs
return csp_update(FORM_ACTION=["https:"])
try:
csp_version = importlib.metadata.version("django-csp")
except importlib.metadata.PackageNotFoundError:
csp_version = "0"

major_version = int(csp_version.split(".")[0])

if major_version >= 4:
return csp_update({"form-action": ["https:"]})
else:
return csp_update(FORM_ACTION=["https:"])
Loading