19 lines
754 B
Python
19 lines
754 B
Python
from django.utils.cache import patch_cache_control
|
|
|
|
|
|
class PrivatePageMiddleware:
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request):
|
|
response = self.get_response(request)
|
|
if not request.path.startswith("/static/"):
|
|
patch_cache_control(response, private=True, no_store=True, max_age=0)
|
|
if not request.path.startswith("/admin/"):
|
|
response["Content-Security-Policy"] = (
|
|
"default-src 'self'; script-src 'self'; style-src 'self'; "
|
|
"img-src 'self' data:; object-src 'none'; base-uri 'self'; "
|
|
"form-action 'self'; frame-ancestors 'none'"
|
|
)
|
|
return response
|