Skip to content

Commit 71a6ef5

Browse files
committed
Python: Model RequestHandler from standard library explicitly
1 parent 05ab6cd commit 71a6ef5

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,20 @@ private module Stdlib {
16161616
)
16171617
}
16181618
}
1619+
1620+
/**
1621+
* The entry-point for handling a request with a `BaseHTTPRequestHandler` subclass.
1622+
*
1623+
* Not essential for any functionality, but provides a consistent modeling.
1624+
*/
1625+
private class RequestHandlerFunc extends HTTP::Server::RequestHandler::Range {
1626+
RequestHandlerFunc() {
1627+
this = any(HTTPRequestHandlerClassDef cls).getAMethod() and
1628+
this.getName() = "do_" + HTTP::httpVerb()
1629+
}
1630+
1631+
override Parameter getARoutedParameter() { none() }
1632+
}
16191633
}
16201634

16211635
// ---------------------------------------------------------------------------

python/ql/src/semmle/python/web/HttpConstants.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Gets an HTTP verb */
1+
/** Gets an HTTP verb, in upper case */
22
string httpVerb() {
33
result = "GET" or
44
result = "POST" or

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def taint_sources(self):
7878
ensure_tainted(form)
7979

8080

81-
def do_GET(self): # $ MISSING: requestHandler
81+
def do_GET(self): # $ requestHandler
8282
# send_response will log a line to stderr
8383
self.send_response(200)
8484
self.send_header("Content-type", "text/plain; charset=utf-8")
@@ -88,7 +88,7 @@ def do_GET(self): # $ MISSING: requestHandler
8888
print(self.headers)
8989

9090

91-
def do_POST(self): # $ MISSING: requestHandler
91+
def do_POST(self): # $ requestHandler
9292
form = cgi.FieldStorage(
9393
self.rfile,
9494
self.headers,

0 commit comments

Comments
 (0)