Add test case for validated wsgiref servers + fix typo

This commit is contained in:
Joe Farebrother
2024-04-08 18:45:54 +01:00
parent f57ba3e642
commit f3b27d611a
8 changed files with 87 additions and 31 deletions

View File

@@ -0,0 +1,4 @@
edges
nodes
subpaths
#select

View File

@@ -0,0 +1 @@
Security/CWE-113/HeaderInjection.ql

View File

@@ -0,0 +1,33 @@
from wsgiref.simple_server import make_server
from wsgiref.headers import Headers
from wsgiref.validate import validator
def test_app(environ, start_response):
status = "200 OK"
h_name = environ["source_n"]
h_val = environ["source_v"]
headers = [(h_name, "val"), ("name", h_val)]
start_response(status, headers) # GOOD - the application is validated, so headers containing newlines will be rejected.
return [b"Hello"]
def test_app2(environ, start_response):
status = "200 OK"
h_name = environ["source_n"]
h_val = environ["source_v"]
headers = Headers([(h_name, "val"), ("name", h_val)]) # GOOD
headers.add_header(h_name, h_val) # GOOD
headers.setdefault(h_name, h_val) # GOOD
headers.__setitem__(h_name, h_val) # GOOD
headers[h_name] = h_val # GOOD
start_response(status, headers)
return [b"Hello"]
def main1():
with make_server('', 8000, validate(test_app)) as httpd:
print("Serving on port 8000...")
httpd.serve_forever()
def main2():
with make_server('', 8000, validate(test_app2)) as httpd:
print("Serving on port 8000...")
httpd.serve_forever()