Skip to content

Commit fd715a5

Browse files
authored
Merge pull request #4179 from RasmusWL/python-tainttracking-ala-go
Approved by tausbn, yoff
2 parents 958f899 + 4387d10 commit fd715a5

File tree

8 files changed

+131
-0
lines changed

8 files changed

+131
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Contains customizations to the standard library.
3+
*
4+
* This module is imported by `python.qll`, so any customizations defined here automatically
5+
* apply to all queries.
6+
*
7+
* Typical examples of customizations include adding new subclasses of abstract classes such as
8+
* the `RemoteFlowSource::Range` and `AdditionalTaintStep` classes associated with the security
9+
* queries to model frameworks that are not covered by the standard library.
10+
*/
11+
12+
import python
13+
/* General import that is useful */
14+
// import experimental.dataflow.DataFlow
15+
//
16+
/* for extending `TaintTracking::AdditionalTaintStep` */
17+
// import experimental.dataflow.TaintTracking
18+
//
19+
/* for extending `RemoteFlowSource::Range` */
20+
// import experimental.dataflow.RemoteFlowSources
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
private import python
2+
private import experimental.dataflow.DataFlow
3+
// Need to import since frameworks can extend `RemoteFlowSource::Range`
4+
private import experimental.semmle.python.Frameworks
5+
6+
/**
7+
* A data flow source of remote user input.
8+
*
9+
* Extend this class to refine existing API models. If you want to model new APIs,
10+
* extend `RemoteFlowSource::Range` instead.
11+
*/
12+
class RemoteFlowSource extends DataFlow::Node {
13+
RemoteFlowSource::Range self;
14+
15+
RemoteFlowSource() { this = self }
16+
17+
/** Gets a string that describes the type of this remote flow source. */
18+
string getSourceType() { result = self.getSourceType() }
19+
}
20+
21+
/** Provides a class for modeling new sources of remote user input. */
22+
module RemoteFlowSource {
23+
/**
24+
* A data flow source of remote user input.
25+
*
26+
* Extend this class to model new APIs. If you want to refine existing API models,
27+
* extend `RemoteFlowSource` instead.
28+
*/
29+
abstract class Range extends DataFlow::Node {
30+
/** Gets a string that describes the type of this remote flow source. */
31+
abstract string getSourceType();
32+
}
33+
}

python/ql/src/experimental/dataflow/internal/TaintTrackingPublic.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
private import python
77
private import TaintTrackingPrivate
88
private import experimental.dataflow.DataFlow
9+
// Need to import since frameworks can extend `AdditionalTaintStep`
10+
private import experimental.semmle.python.Frameworks
911

1012
// Local taint flow and helpers
1113
/**
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Provides abstract classes representing generic concepts such as file system
3+
* access or system command execution, for which individual framework libraries
4+
* provide concrete subclasses.
5+
*/
6+
7+
import python
8+
private import experimental.dataflow.DataFlow
9+
private import experimental.semmle.python.Frameworks
10+
11+
/**
12+
* A data-flow node that executes an operating system command,
13+
* for instance by spawning a new process.
14+
*
15+
* Extend this class to refine existing API models. If you want to model new APIs,
16+
* extend `SystemCommandExecution::Range` instead.
17+
*/
18+
class SystemCommandExecution extends DataFlow::Node {
19+
SystemCommandExecution::Range self;
20+
21+
SystemCommandExecution() { this = self }
22+
23+
/** Gets the argument that specifies the command to be executed. */
24+
DataFlow::Node getCommand() { result = self.getCommand() }
25+
}
26+
27+
/** Provides a class for modeling new system-command execution APIs. */
28+
module SystemCommandExecution {
29+
/**
30+
* A data-flow node that executes an operating system command,
31+
* for instance by spawning a new process.
32+
*
33+
* Extend this class to model new APIs. If you want to refine existing API models,
34+
* extend `SystemCommandExecution` instead.
35+
*/
36+
abstract class Range extends DataFlow::Node {
37+
/** Gets the argument that specifies the command to be executed. */
38+
abstract DataFlow::Node getCommand();
39+
}
40+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Helper file that imports all framework modeling.
3+
*/
4+
5+
private import experimental.semmle.python.frameworks.Flask
6+
private import experimental.semmle.python.frameworks.Django
7+
private import experimental.semmle.python.frameworks.Stdlib
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `django` package.
3+
*/
4+
5+
private import python
6+
private import experimental.dataflow.DataFlow
7+
private import experimental.dataflow.RemoteFlowSources
8+
private import experimental.semmle.python.Concepts
9+
10+
private module Django { }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `flask` package.
3+
*/
4+
5+
private import python
6+
private import experimental.dataflow.DataFlow
7+
private import experimental.dataflow.RemoteFlowSources
8+
private import experimental.semmle.python.Concepts
9+
10+
private module Flask { }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the standard libraries.
3+
* Note: some modeling is done internally in the dataflow/taint tracking implementation.
4+
*/
5+
6+
private import python
7+
private import experimental.dataflow.DataFlow
8+
private import experimental.dataflow.RemoteFlowSources
9+
private import experimental.semmle.python.Concepts

0 commit comments

Comments
 (0)