Skip to content

Commit ad83fc8

Browse files
authored
Merge pull request #10687 from RasmusWL/flask-debug
Python: Rewrite `py/flask-debug` to use API graphs instead of type-trackers
2 parents d0ea7ea + 2541af6 commit ad83fc8

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

python/ql/src/Security/CWE-215/FlaskDebug.ql

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,10 @@ import semmle.python.dataflow.new.DataFlow
1616
import semmle.python.ApiGraphs
1717
import semmle.python.frameworks.Flask
1818

19-
/** Gets a reference to a truthy literal. */
20-
private DataFlow::TypeTrackingNode truthyLiteral(DataFlow::TypeTracker t) {
21-
t.start() and
22-
result.asExpr().(ImmutableLiteral).booleanValue() = true
23-
or
24-
exists(DataFlow::TypeTracker t2 | result = truthyLiteral(t2).track(t2, t))
25-
}
26-
27-
/** Gets a reference to a truthy literal. */
28-
DataFlow::Node truthyLiteral() { truthyLiteral(DataFlow::TypeTracker::end()).flowsTo(result) }
29-
30-
from API::CallNode call, DataFlow::Node debugArg
19+
from API::CallNode call
3120
where
3221
call = Flask::FlaskApp::instance().getMember("run").getACall() and
33-
debugArg in [call.getArg(2), call.getArgByName("debug")] and
34-
debugArg = truthyLiteral()
22+
call.getParameter(2, "debug").getAValueReachingSink().asExpr().(ImmutableLiteral).booleanValue() =
23+
true
3524
select call,
3625
"A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger."
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| test.py:10:1:10:19 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
2-
| test.py:25:1:25:20 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
3-
| test.py:29:1:29:20 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
4-
| test.py:37:1:37:18 | ControlFlowNode for runapp() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
5-
| test.py:42:1:42:35 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
2+
| test.py:11:1:11:27 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
3+
| test.py:26:1:26:20 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
4+
| test.py:30:1:30:20 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
5+
| test.py:38:1:38:18 | ControlFlowNode for runapp() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |
6+
| test.py:43:1:43:35 | ControlFlowNode for Attribute() | A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger. |

python/ql/test/query-tests/Security/CWE-215-FlaskDebug/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def main():
88

99
# bad
1010
app.run(debug=True)
11+
app.run('host', 8080, True)
1112

1213
# okay
1314
app.run()

0 commit comments

Comments
 (0)