Created
December 6, 2024 22:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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