🜃 Minimal CGI Script

177 2026-08-01 snippet ♈︎ ♄︎

The whole CGI contract in one script: read the environment, print headers, print a blank line, print a body.

#!/usr/bin/env python3
import os

query = os.environ.get("QUERY_STRING", "")

print("Content-Type: text/plain")
print()
print(f"Hello from CGI. Query string: {query}")

Apache or any CGI-capable server sets QUERY_STRING, REQUEST_METHOD, REMOTE_ADDR, and the rest of RFC 3875's meta-variables before exec'ing the script.

Never do this in a shell script, sandboxing backticks against injection is close to impossible. See CGI in 2026 for the rest of the security story.