Skip to content

Commit 0af86cb

Browse files
committed
Python: Port CodeInjection query
and the dummy test-case we already have
1 parent 5f6e4d4 commit 0af86cb

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @name Code injection
3+
* @description Interpreting unsanitized user input as code allows a malicious user arbitrary
4+
* code execution.
5+
* @kind path-problem
6+
* @problem.severity error
7+
* @sub-severity high
8+
* @precision high
9+
* @id py/code-injection
10+
* @tags security
11+
* external/owasp/owasp-a1
12+
* external/cwe/cwe-094
13+
* external/cwe/cwe-095
14+
* external/cwe/cwe-116
15+
*/
16+
17+
import python
18+
import experimental.dataflow.DataFlow
19+
import experimental.dataflow.TaintTracking
20+
import experimental.semmle.python.Concepts
21+
import experimental.dataflow.RemoteFlowSources
22+
import DataFlow::PathGraph
23+
24+
class CodeInjectionConfiguration extends TaintTracking::Configuration {
25+
CodeInjectionConfiguration() { this = "CodeInjectionConfiguration" }
26+
27+
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
28+
29+
override predicate isSink(DataFlow::Node sink) { sink = any(CodeExecution e).getCode() }
30+
}
31+
32+
from CodeInjectionConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
33+
where config.hasFlowPath(source, sink)
34+
select sink.getNode(), source, sink, "$@ flows to here and is interpreted as code.",
35+
source.getNode(), "A user-provided value"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
edges
2+
nodes
3+
#select
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security-new-dataflow/CWE-094/CodeInjection.ql
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from flask import Flask, request
2+
app = Flask(__name__)
3+
4+
@app.route("/code-execution")
5+
def code_execution():
6+
code = request.args.get("code")
7+
exec(code)
8+
eval(code)

0 commit comments

Comments
 (0)