Skip to content

Commit a6e5ec2

Browse files
committed
Python: Port py/flask-debug
1 parent 0cad5ce commit a6e5ec2

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Updated _Flask app is run in debug mode_ (`py/flask-debug`) query to use the new type-tracking approach instead of points-to analysis. You may see differences in the results found by the query, but overall this change should result in a more robust and accurate analysis.

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@
1111
*/
1212

1313
import python
14-
import semmle.python.web.flask.General
14+
import semmle.python.dataflow.new.DataFlow
15+
import semmle.python.ApiGraphs
16+
import semmle.python.frameworks.Flask
1517

16-
from CallNode call, Value isTrue
18+
/** Gets a reference to a truthy literal. */
19+
private DataFlow::LocalSourceNode truthyLiteral(DataFlow::TypeTracker t) {
20+
t.start() and
21+
result.asExpr().(ImmutableLiteral).booleanValue() = true
22+
or
23+
exists(DataFlow::TypeTracker t2 | result = truthyLiteral(t2).track(t2, t))
24+
}
25+
26+
/** Gets a reference to a truthy literal. */
27+
DataFlow::Node truthyLiteral() { truthyLiteral(DataFlow::TypeTracker::end()).flowsTo(result) }
28+
29+
from DataFlow::CallCfgNode call, DataFlow::Node debugArg
1730
where
18-
call = theFlaskClass().declaredAttribute("run").(FunctionValue).getACall() and
19-
call.getArgByName("debug").pointsTo(isTrue) and
20-
isTrue.getDefiniteBooleanValue() = true
31+
call.getFunction() = Flask::FlaskApp::instance().getMember("run").getAUse() and
32+
debugArg in [call.getArg(2), call.getArgByName("debug")] and
33+
debugArg = truthyLiteral()
2134
select call,
2235
"A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger."

0 commit comments

Comments
 (0)