🜃 Minimal CGI Script
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 and Shell Script CGI Security for more on why shell scripts are particularly risky.
- Links to
- CGI · CGI in 2026 · Shell Script CGI Security
- Linked from
- Shell Script CGI Security · CGI in 2026