-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for validated wsgiref servers + fix typo
- Loading branch information
1 parent
f57ba3e
commit f3b27d6
Showing
8 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests2/HeaderInjection.expected
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
edges | ||
nodes | ||
subpaths | ||
#select |
1 change: 1 addition & 0 deletions
1
python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests2/HeaderInjection.qlref
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Security/CWE-113/HeaderInjection.ql |
33 changes: 33 additions & 0 deletions
33
python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests2/wsgiref_tests.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |