Skip to content
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

Add some initial CSP settings to test #527

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
42 changes: 41 additions & 1 deletion omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ def check_session_engine(s):
'{"index": 5, '
'"class": "django.contrib.messages.middleware.MessageMiddleware"},'
'{"index": 6, '
'"class": "django.middleware.clickjacking.XFrameOptionsMiddleware"}'
'"class": "django.middleware.clickjacking.XFrameOptionsMiddleware"},'
'{"index": 7, '
'"class": "csp.middleware.CSPMiddleware"}'
"]"
),
json.loads,
Expand Down Expand Up @@ -1169,6 +1171,44 @@ def check_session_engine(s):
"Remember to terminate lines with; when necessary."
),
],
# Content-Security-Protocol settings:
# see https://django-csp.readthedocs.io/en/latest/configuration.html
"omero.web.csp_default_src": [
"CSP_DEFAULT_SRC",
"[\"'self'\"]",
json.loads,
"Set the CSP default-src directive",
],
"omero.web.csp_worker_src": [
"CSP_WORKER_SRC",
'["\'self\'", "blob:"]',
json.loads,
"Set the CSP worker-src directive",
],
"omero.web.csp_script_src": [
"CSP_SCRIPT_SRC",
"[\"'self'\", \"'unsafe-inline'\", \"'unsafe-eval'\"]",
json.loads,
"Set the CSP script-src directive",
],
"omero.web.csp_img_src": [
"CSP_IMG_SRC",
'["\'self\'", "data:"]',
json.loads,
"Set the CSP img-src directive",
],
"omero.web.csp_style_src": [
"CSP_STYLE_SRC",
"[\"'self'\", \"'unsafe-inline'\"]",
json.loads,
"Set the CSP style-src directive",
],
"omero.web.csp_base_uri": [
"CSP_BASE_URI",
"[\"'self'\"]",
json.loads,
"Set the CSP base-uri directive",
],
}

DEPRECATED_SETTINGS_MAPPINGS = {
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def read(fname):
"Django>=4.2.3,<4.3",
"django-pipeline==2.1.0",
"django-cors-headers==3.7.0",
"django-csp",
"whitenoise>=5.3.0",
"gunicorn>=19.3",
"omero-marshal>=0.7.0",
Expand Down
Loading