Skip to content

Instantly share code, notes, and snippets.

@ACK-J
Created December 6, 2024 22:36
Show Gist options
  • Save ACK-J/1ea99b3c1524ce81f124266ff0f3cf25 to your computer and use it in GitHub Desktop.
Save ACK-J/1ea99b3c1524ce81f124266ff0f3cf25 to your computer and use it in GitHub Desktop.
Quick and Easy Python Server that Returns a Vulnerable CSP via Headers
import http.server
import socketserver
PORT = 8000
class MyRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
# Set the Content Security Policy header
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header("Content-Security-Policy", "script-src 'unsafe-inline' 'unsafe-eval' 'self' data: https://www.google.com")
self.end_headers()
# Send a simple HTML response
self.wfile.write(b"<html><body><h1>Hello, World!</h1><p>This page has a CSP header.</p></body></html>")
# Set up the server
with socketserver.TCPServer(("", PORT), MyRequestHandler) as httpd:
print(f"Serving on port {PORT}")
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment