Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19dc04d

Browse files
committed
Python: Handle make_response on flask app
1 parent e38ac18 commit 19dc04d

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

python/ql/src/experimental/semmle/python/frameworks/Flask.qll

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private module FlaskModel {
130130
* WARNING: Only holds for a few predefined attributes.
131131
*/
132132
private DataFlow::Node instance_attr(DataFlow::TypeTracker t, string attr_name) {
133-
attr_name in ["route", "add_url_rule"] and
133+
attr_name in ["route", "add_url_rule", "make_response"] and
134134
t.startInAttr(attr_name) and
135135
result = flask::Flask::instance()
136136
or
@@ -165,6 +165,12 @@ private module FlaskModel {
165165

166166
/** Gets a reference to the `add_url_rule` method on an instance of `flask.Flask`. */
167167
DataFlow::Node add_url_rule() { result = instance_attr("add_url_rule") }
168+
169+
/** Gets a reference to the `make_response` method on an instance of `flask.Flask`. */
170+
// HACK: We can't call this predicate `make_response` since shadowing is
171+
// completely disallowed in QL. I added an underscore to move thing forwards for
172+
// now :(
173+
DataFlow::Node make_response_() { result = instance_attr("make_response") }
168174
}
169175
}
170176

@@ -367,14 +373,21 @@ private module FlaskModel {
367373
// Response modeling
368374
// ---------------------------------------------------------------------------
369375
/**
370-
* A call to the `flask.make_response` function.
376+
* A call to either `flask.make_response` function, or the `make_response` method on
377+
* an instance of `flask.Flask`.
371378
*
372-
* See https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response
379+
* See
380+
* - https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask.make_response
381+
* - https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response
373382
*/
374383
private class FlaskMakeResponseCall extends HTTP::Server::HttpResponse::Range, DataFlow::CfgNode {
375384
override CallNode node;
376385

377-
FlaskMakeResponseCall() { node.getFunction() = flask::make_response().asCfgNode() }
386+
FlaskMakeResponseCall() {
387+
node.getFunction() = flask::make_response().asCfgNode()
388+
or
389+
node.getFunction() = flask::Flask::make_response_().asCfgNode()
390+
}
378391

379392
override DataFlow::Node getBody() { result.asCfgNode() = node.getArg(0) }
380393

python/ql/test/experimental/library-tests/frameworks/flask/response_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def html2(): # $routeHandler
2121

2222
@app.route("/html3") # $routeSetup="/html3"
2323
def html3(): # $routeHandler
24-
resp = app.make_response("<h1>hello</h1>") # $f-:HttpResponse $f-:contentType=text/html $f-:statusCode=200 $f-:responseBody="<h1>hello</h1>"
24+
resp = app.make_response("<h1>hello</h1>") # $HttpResponse $contentType=text/html $statusCode=200 $responseBody="<h1>hello</h1>"
2525
return resp
2626

2727

0 commit comments

Comments
 (0)