blob: 8806366a75e3f6734729875420c844a0574d2125 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
from twisted.web.server import Site, Request
class AddCSPHeaderRequest(Request):
HEADER_VALUES = "default-src 'self'; style-src 'self' 'unsafe-inline'"
def process(self):
self.setHeader("Content-Security-Policy", self.HEADER_VALUES)
self.setHeader("X-Content-Security-Policy", self.HEADER_VALUES)
self.setHeader("X-Webkit-CSP", self.HEADER_VALUES)
if self.isSecure():
self.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains')
Request.process(self)
class PixelatedSite(Site):
requestFactory = AddCSPHeaderRequest
@classmethod
def enable_csp_requests(cls):
cls.requestFactory = AddCSPHeaderRequest
@classmethod
def disable_csp_requests(cls):
cls.requestFactory = Site.requestFactory
|