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/"): image_sources = "'self' data:" if request.resolver_match and request.resolver_match.url_name in { "inventory", "shared_inventory", "orders", }: image_sources += ( " https://cdn.shopify.com https://store.bblcdn.eu https://store.bblcdn.com" ) response["Content-Security-Policy"] = ( "default-src 'self'; script-src 'self'; style-src 'self'; " f"img-src {image_sources}; object-src 'none'; base-uri 'self'; " "form-action 'self'; frame-ancestors 'none'" ) return response