Skip to content

Commit 7c04c59

Browse files
committed
Python: Move CodeInjection configuration to own file
This makes it easy to extend the sources/sinks of the configuration and re-run the query from the query console on LGTM.com. File location in `semmle.<lang>.security.dataflow.<QueryName>.qll` is matching what we currently do in other languages (JS and C# sampled). I did not follow the pattern in other languages for wrapping all the code in a `module CodeInjection`, since I didn't understand the value in doing so -- I would like confirmation from the other teams if we _should_ actually do that, before merging.
1 parent 9f2eb84 commit 7c04c59

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

python/ql/src/Security/CWE-094/CodeInjection.ql

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,9 @@
1515
*/
1616

1717
import python
18-
import semmle.python.dataflow.new.DataFlow
19-
import semmle.python.dataflow.new.TaintTracking
20-
import semmle.python.Concepts
21-
import semmle.python.dataflow.new.RemoteFlowSources
18+
import semmle.python.security.dataflow.CodeInjection
2219
import DataFlow::PathGraph
2320

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-
3221
from CodeInjectionConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
3322
where config.hasFlowPath(source, sink)
3423
select sink.getNode(), source, sink, "$@ flows to here and is interpreted as code.",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Provides a taint-tracking configuration for reasoning about code injection
3+
* vulnerabilities.
4+
*/
5+
6+
import python
7+
import semmle.python.dataflow.new.DataFlow
8+
import semmle.python.dataflow.new.TaintTracking
9+
import semmle.python.Concepts
10+
import semmle.python.dataflow.new.RemoteFlowSources
11+
12+
/**
13+
* A taint-tracking configuration for reasoning about code injection vulnerabilities.
14+
*/
15+
class CodeInjectionConfiguration extends TaintTracking::Configuration {
16+
CodeInjectionConfiguration() { this = "CodeInjectionConfiguration" }
17+
18+
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
19+
20+
override predicate isSink(DataFlow::Node sink) { sink = any(CodeExecution e).getCode() }
21+
}

0 commit comments

Comments
 (0)