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

Enable content security policy in report-only mode #6642

Merged
merged 1 commit into from Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions readthedocs/settings/base.py
Expand Up @@ -77,6 +77,18 @@ class CommunityBaseSettings(Settings):
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = 'DENY'

# Content Security Policy
# https://django-csp.readthedocs.io/
CSP_BLOCK_ALL_MIXED_CONTENT = True
CSP_DEFAULT_SRC = None # This could be improved
CSP_FRAME_ANCESTORS = ("'none'",)
CSP_OBJECT_SRC = ("'none'",)
CSP_REPORT_URI = None
CSP_REPORT_ONLY = True # Set to false to enable CSP in blocking mode
CSP_EXCLUDE_URL_PREFIXES = (
"/admin/",
)

# Read the Docs
READ_THE_DOCS_EXTENSIONS = ext
RTD_LATEST = 'latest'
Expand Down Expand Up @@ -180,6 +192,7 @@ def USE_PROMOS(self): # noqa
'readthedocs.core.middleware.SubdomainMiddleware',
'readthedocs.core.middleware.SingleVersionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'csp.middleware.CSPMiddleware',
)

AUTHENTICATION_BACKENDS = (
Expand Down
10 changes: 9 additions & 1 deletion readthedocs/settings/proxito.py
Expand Up @@ -29,7 +29,15 @@ def MIDDLEWARE(self): # noqa
'readthedocs.core.middleware.SubdomainMiddleware'
)
classes[index] = 'readthedocs.proxito.middleware.ProxitoMiddleware'
classes.remove('readthedocs.core.middleware.SingleVersionMiddleware')

middleware_to_remove = (
'readthedocs.core.middleware.SingleVersionMiddleware',
'csp.middleware.CSPMiddleware',
)
for mw in middleware_to_remove:
if mw in classes:
classes.remove(mw)

return classes


Expand Down
3 changes: 3 additions & 0 deletions requirements/pip.txt
Expand Up @@ -113,3 +113,6 @@ azure-storage-common==1.4.2

# Required only in development and linting
django-debug-toolbar==2.0

# For enabling content-security-policy
django-csp==3.6