I want to deny access to certain paths on my server, which is using the CGIHttpServer
module. I've come up with a whitelist that I'll need to check on every request, but my problem is how to implement it.
I tried overriding the handle_one_request
method (which both processes the request and sends the response) but the problem is that the path information is not available before it's run. Meaning that I'll always be either too early or too late. Now I'm thinking of either copy-pasting the original function source and editing it myself or overriding wfile.flush
, which sounds way too ugly.
Can anyone give me a better solution?
Here's the source code for handle_one_request.
You can override
run_cgi
in theCGIHTTPRequestHandler
subclass, and only callsuper
when your whitelist matches.