Skip to content

Commit 1ae2905

Browse files
committed
Add warning and documentation iff django-csp can not be found
1 parent 0b33457 commit 1ae2905

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

djangosaml2/views.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
validate_referral_url,
7777
)
7878

79+
logger = logging.getLogger("djangosaml2")
80+
7981
# Update Content-Security-Policy headers for POST-Bindings
8082
try:
8183
from csp.decorators import csp_update
@@ -84,15 +86,18 @@
8486
# is not used
8587
def saml2_csp_update(view):
8688
return view
89+
90+
logger.warning("django-csp could not be found, not updating Content-Security-Policy. Please "
91+
"make sure CSP is configured at least by httpd or setup django-csp. See "
92+
"https://djangosaml2.readthedocs.io/contents/security.html#content-security-policy"
93+
" for more information")
8794
else:
8895
# script-src 'unsafe-inline' to autosubmit forms,
8996
# form-action https: to send data to IdPs
9097
saml2_csp_update = csp_update(
9198
SCRIPT_SRC=["'unsafe-inline'"], FORM_ACTION=["https:"]
9299
)
93100

94-
logger = logging.getLogger("djangosaml2")
95-
96101

97102
def _set_subject_id(session, subject_id):
98103
session["_saml2_subject_id"] = code(subject_id)

docs/source/contents/security.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Security considerations
2-
=======================
1+
Introduction
2+
============
33

44
Authentication and Authorization are quite security relevant topics on its own.
55
Make sure you understand SAML2 and its implications, specifically the
@@ -12,9 +12,24 @@ need for direct communication between SP and IdP. However, for security the use
1212
of cryptographic signatures (both while sending and receiving messages) must be
1313
examined and the private keys in use must be kept closely guarded.
1414

15+
Content Security Policy
16+
=======================
17+
1518
When using POST-Bindings, the Browser is presented with a small HTML-Form for
1619
every redirect (both Login and Logout), which is sent using JavaScript and
1720
sends the Data to the selected IdP. If your application uses technices such as
1821
Content Security Policy, this might affect the calls. Since Version 1.9.0
1922
djangosaml2 will detect if django-csp is installed and update the Content
2023
Security Policy accordingly.
24+
25+
[Content Security Policy](https://content-security-policy.com/) is an important
26+
HTTP-Extension to prevent User Input or other harmful sources from manipulating
27+
application data. Usage is strongly advised, see
28+
[OWASP Control](https://owasp.org/www-community/controls/Content_Security_Policy).
29+
30+
To enable CSP with [django-csp](https://django-csp.readthedocs.io/), simply
31+
follow their [installation](https://django-csp.readthedocs.io/en/latest/installation.html)
32+
and [configuration](https://django-csp.readthedocs.io/en/latest/configuration.html)
33+
guides: djangosaml2 will automatically blend in and update the headers for
34+
POST-bindings, so you must not include exceptions for djangosaml2 in your
35+
global configuration.

0 commit comments

Comments
 (0)