csp.py (666B)
1 def main(request, response): 2 csp = request.GET.first(b"policy") 3 headers = [ 4 (b"Content-Type", b"text/html"), 5 (b"Content-Security-Policy", csp) 6 ] 7 8 body = f"""<!DOCTYPE html> 9 <html> 10 <head> 11 <title>CSP</title> 12 </head> 13 <body> 14 <p>{csp}</p> 15 <img src="/content-security-policy/support/pass.png" /> 16 <script> 17 let img = document.querySelector("img"); 18 img.onload = img.onerror = (event) => {{ 19 window.parent.postMessage(event.type, '*'); 20 }}; 21 </script> 22 </body> 23 </html> 24 """ 25 return (headers, body)