Python: Port py/flask-debug

This commit is contained in:
Rasmus Wriedt Larsen
2021-02-24 11:35:53 +01:00
parent 0cad5ce5ca
commit a6e5ec2e09
2 changed files with 20 additions and 5 deletions

View File

@@ -11,12 +11,25 @@
*/
import python
import semmle.python.web.flask.General
import semmle.python.dataflow.new.DataFlow
import semmle.python.ApiGraphs
import semmle.python.frameworks.Flask
from CallNode call, Value isTrue
/** Gets a reference to a truthy literal. */
private DataFlow::LocalSourceNode truthyLiteral(DataFlow::TypeTracker t) {
t.start() and
result.asExpr().(ImmutableLiteral).booleanValue() = true
or
exists(DataFlow::TypeTracker t2 | result = truthyLiteral(t2).track(t2, t))
}
/** Gets a reference to a truthy literal. */
DataFlow::Node truthyLiteral() { truthyLiteral(DataFlow::TypeTracker::end()).flowsTo(result) }
from DataFlow::CallCfgNode call, DataFlow::Node debugArg
where
call = theFlaskClass().declaredAttribute("run").(FunctionValue).getACall() and
call.getArgByName("debug").pointsTo(isTrue) and
isTrue.getDefiniteBooleanValue() = true
call.getFunction() = Flask::FlaskApp::instance().getMember("run").getAUse() and
debugArg in [call.getArg(2), call.getArgByName("debug")] and
debugArg = truthyLiteral()
select call,
"A Flask app appears to be run in debug mode. This may allow an attacker to run arbitrary code through the debugger."