|
75 | 75 | validate_referral_url,
|
76 | 76 | )
|
77 | 77 |
|
| 78 | +# Update Content-Security-Policy headers for POST-Bindings |
| 79 | +try: |
| 80 | + from csp.decorators import csp_update |
| 81 | +except ModuleNotFoundError: |
| 82 | + # If csp is not installed, do not update fields as Content-Security-Policy |
| 83 | + # is not used |
| 84 | + def saml2_csp_update(view): |
| 85 | + return view |
| 86 | +else: |
| 87 | + # script-src 'unsafe-inline' to autosubmit forms, |
| 88 | + # form-action https: to send data to IdPs |
| 89 | + saml2_csp_update = csp_update( |
| 90 | + SCRIPT_SRC=["'unsafe-inline'"], FORM_ACTION=["https:"] |
| 91 | + ) |
| 92 | + |
78 | 93 | logger = logging.getLogger("djangosaml2")
|
79 | 94 |
|
80 | 95 |
|
@@ -109,6 +124,7 @@ def get_state_client(self, request: HttpRequest):
|
109 | 124 | return state, client
|
110 | 125 |
|
111 | 126 |
|
| 127 | +@method_decorator(saml2_csp_update, name='dispatch') |
112 | 128 | class LoginView(SPConfigMixin, View):
|
113 | 129 | """SAML Authorization Request initiator.
|
114 | 130 |
|
@@ -636,6 +652,7 @@ def get(self, request, *args, **kwargs):
|
636 | 652 | )
|
637 | 653 |
|
638 | 654 |
|
| 655 | +@method_decorator(saml2_csp_update, name='dispatch') |
639 | 656 | class LogoutInitView(LoginRequiredMixin, SPConfigMixin, View):
|
640 | 657 | """SAML Logout Request initiator
|
641 | 658 |
|
@@ -714,7 +731,7 @@ def handle_unsupported_slo_exception(self, request, exception, *args, **kwargs):
|
714 | 731 | return HttpResponseRedirect(getattr(settings, "LOGOUT_REDIRECT_URL", "/"))
|
715 | 732 |
|
716 | 733 |
|
717 |
| -@method_decorator(csrf_exempt, name="dispatch") |
| 734 | +@method_decorator([saml2_csp_update, csrf_exempt], name="dispatch") |
718 | 735 | class LogoutView(SPConfigMixin, View):
|
719 | 736 | """SAML Logout Response endpoint
|
720 | 737 |
|
|
0 commit comments