Skip to content

Commit

Permalink
Add some initial CSP settings to test
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jan 15, 2024
1 parent 9841167 commit 8936412
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 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,24 @@ def check_session_engine(s):
"Remember to terminate lines with; when necessary."
),
],

# Content-Security-Protocol settings: https://django-csp.readthedocs.io/en/latest/configuration.html
# default-src 'none'; script-src 'self'; img-src 'self'; style-src 'self';base-uri 'self';form-action 'self'
"omero.web.csp_default_src": [
"CSP_DEFAULT_SRC", '["\'self\'"]', json.loads, "Set the CSP default-src directive",
],
"omero.web.csp_script_src": [
"CSP_SCRIPT_SRC", '["\'self\'"]', json.loads, "Set the CSP script-src directive",
],
"omero.web.csp_img_src": [
"CSP_IMG_SRC", '["\'self\'"]', json.loads, "Set the CSP img-src directive",
],
"omero.web.csp_style_src": [
"CSP_STYLE_SRC", '["\'self\'"]', 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

0 comments on commit 8936412

Please sign in to comment.