mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
Python: Model flask.jsonify
This commit is contained in:
4
python/ql/lib/change-notes/2022-09-22-flask-jsonify.md
Normal file
4
python/ql/lib/change-notes/2022-09-22-flask-jsonify.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Added modeling of creating Flask responses with `flask.jsonify`.
|
||||
@@ -171,6 +171,24 @@ module Flask {
|
||||
override DataFlow::Node getMimetypeOrContentTypeArg() { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A call to `flask.jsonify` function. This creates a JSON response.
|
||||
*
|
||||
* See
|
||||
* - https://flask.palletsprojects.com/en/2.2.x/api/#flask.json.jsonify
|
||||
*/
|
||||
private class FlaskJsonifyCall extends InstanceSource, DataFlow::CallCfgNode {
|
||||
FlaskJsonifyCall() {
|
||||
this = API::moduleImport("flask").getMember("jsonify").getACall()
|
||||
}
|
||||
|
||||
override DataFlow::Node getBody() { result = this.getArg(0) }
|
||||
|
||||
override string getMimetypeDefault() { result = "application/json" }
|
||||
|
||||
override DataFlow::Node getMimetypeOrContentTypeArg() { none() }
|
||||
}
|
||||
|
||||
/** Gets a reference to an instance of `flask.Response`. */
|
||||
private DataFlow::TypeTrackingNode instance(DataFlow::TypeTracker t) {
|
||||
t.start() and
|
||||
|
||||
@@ -67,7 +67,7 @@ def html8(): # $requestHandler
|
||||
@app.route("/jsonify") # $routeSetup="/jsonify"
|
||||
def jsonify_route(): # $requestHandler
|
||||
data = {"foo": "bar"}
|
||||
resp = jsonify(data) # $ MISSING: HttpResponse mimetype=application/json responseBody=data
|
||||
resp = jsonify(data) # $ HttpResponse mimetype=application/json responseBody=data
|
||||
return resp # $ SPURIOUS: HttpResponse mimetype=text/html responseBody=resp
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -5,6 +5,7 @@ edges
|
||||
| test.py:50:29:50:31 | ControlFlowNode for err | test.py:50:16:50:32 | ControlFlowNode for format_error() |
|
||||
| test.py:50:29:50:31 | ControlFlowNode for err | test.py:52:18:52:20 | ControlFlowNode for msg |
|
||||
| test.py:52:18:52:20 | ControlFlowNode for msg | test.py:53:12:53:27 | ControlFlowNode for BinaryExpr |
|
||||
| test.py:65:25:65:25 | SSA variable e | test.py:66:24:66:40 | ControlFlowNode for Dict |
|
||||
nodes
|
||||
| test.py:16:16:16:37 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
|
||||
| test.py:23:25:23:25 | SSA variable e | semmle.label | SSA variable e |
|
||||
@@ -16,6 +17,8 @@ nodes
|
||||
| test.py:50:29:50:31 | ControlFlowNode for err | semmle.label | ControlFlowNode for err |
|
||||
| test.py:52:18:52:20 | ControlFlowNode for msg | semmle.label | ControlFlowNode for msg |
|
||||
| test.py:53:12:53:27 | ControlFlowNode for BinaryExpr | semmle.label | ControlFlowNode for BinaryExpr |
|
||||
| test.py:65:25:65:25 | SSA variable e | semmle.label | SSA variable e |
|
||||
| test.py:66:24:66:40 | ControlFlowNode for Dict | semmle.label | ControlFlowNode for Dict |
|
||||
subpaths
|
||||
| test.py:50:29:50:31 | ControlFlowNode for err | test.py:52:18:52:20 | ControlFlowNode for msg | test.py:53:12:53:27 | ControlFlowNode for BinaryExpr | test.py:50:16:50:32 | ControlFlowNode for format_error() |
|
||||
#select
|
||||
@@ -23,3 +26,4 @@ subpaths
|
||||
| test.py:24:16:24:16 | ControlFlowNode for e | test.py:23:25:23:25 | SSA variable e | test.py:24:16:24:16 | ControlFlowNode for e | $@ flows to this location and may be exposed to an external user. | test.py:23:25:23:25 | SSA variable e | Stack trace information |
|
||||
| test.py:32:16:32:30 | ControlFlowNode for Attribute | test.py:31:25:31:25 | SSA variable e | test.py:32:16:32:30 | ControlFlowNode for Attribute | $@ flows to this location and may be exposed to an external user. | test.py:31:25:31:25 | SSA variable e | Stack trace information |
|
||||
| test.py:50:16:50:32 | ControlFlowNode for format_error() | test.py:49:15:49:36 | ControlFlowNode for Attribute() | test.py:50:16:50:32 | ControlFlowNode for format_error() | $@ flows to this location and may be exposed to an external user. | test.py:49:15:49:36 | ControlFlowNode for Attribute() | Stack trace information |
|
||||
| test.py:66:24:66:40 | ControlFlowNode for Dict | test.py:65:25:65:25 | SSA variable e | test.py:66:24:66:40 | ControlFlowNode for Dict | $@ flows to this location and may be exposed to an external user. | test.py:65:25:65:25 | SSA variable e | Stack trace information |
|
||||
|
||||
@@ -62,7 +62,7 @@ def maybe_xss():
|
||||
def bad_jsonify():
|
||||
try:
|
||||
do_computation()
|
||||
except Exception as e:
|
||||
except Exception as e: # $ exceptionInfo
|
||||
return jsonify({"error": str(e)})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user