Skip to content

Commit 531f2a1

Browse files
committed
python: model send_header from http.server
1 parent 1c1ccda commit 531f2a1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,22 @@ module StdlibPrivate {
19631963
/** Gets a reference to an instance of the `BaseHttpRequestHandler` class or any subclass. */
19641964
DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) }
19651965

1966+
/** A call to a method that writes to a response header. */
1967+
private class HeaderWriteCall extends Http::Server::ResponseHeaderWrite::Range,
1968+
DataFlow::MethodCallNode
1969+
{
1970+
HeaderWriteCall() { this.calls(instance(), "send_header") }
1971+
1972+
override DataFlow::Node getNameArg() { result = this.getArg(0) }
1973+
1974+
override DataFlow::Node getValueArg() { result = this.getArg(1) }
1975+
1976+
// TODO: These checks perhaps could be made more precise.
1977+
override predicate nameAllowsNewline() { any() }
1978+
1979+
override predicate valueAllowsNewline() { any() }
1980+
}
1981+
19661982
private class AdditionalTaintStep extends TaintTracking::AdditionalTaintStep {
19671983
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
19681984
nodeFrom = instance() and

python/ql/test/library-tests/frameworks/stdlib/http_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def taint_sources(self):
8383
def do_GET(self): # $ requestHandler
8484
# send_response will log a line to stderr
8585
self.send_response(200)
86-
self.send_header("Content-type", "text/plain; charset=utf-8")
86+
self.send_header("Content-type", "text/plain; charset=utf-8") # $ headerWriteNameUnsanitized="Content-type" headerWriteValueUnsanitized="text/plain; charset=utf-8"
8787
self.end_headers()
8888
self.wfile.write(b"Hello BaseHTTPRequestHandler\n")
8989
self.wfile.writelines([b"1\n", b"2\n", b"3\n"])

0 commit comments

Comments
 (0)