|
4 | 4 |
|
5 | 5 | import go
|
6 | 6 | private import semmle.go.dataflow.ExternalFlow as ExternalFlow
|
| 7 | +private import codeql.threatmodels.ThreatModels |
7 | 8 |
|
8 | 9 | /**
|
9 | 10 | * DEPRECATED: Use `RemoteFlowSource` instead.
|
@@ -31,12 +32,43 @@ module RemoteFlowSource {
|
31 | 32 | * Extend this class to model new APIs. If you want to refine existing API models,
|
32 | 33 | * extend `RemoteFlowSource` instead.
|
33 | 34 | */
|
34 |
| - abstract class Range extends DataFlow::Node { } |
| 35 | + abstract class Range extends SourceNode { |
| 36 | + override string getThreatModel() { result = "remote" } |
| 37 | + } |
35 | 38 |
|
36 | 39 | /**
|
37 | 40 | * A source of data that is controlled by an untrusted user.
|
38 | 41 | */
|
39 | 42 | class MaDRemoteSource extends Range {
|
40 | 43 | MaDRemoteSource() { ExternalFlow::sourceNode(this, "remote") }
|
| 44 | + |
| 45 | + override string getSourceType() { result = "external" } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * A data flow source. |
| 51 | + */ |
| 52 | +abstract class SourceNode extends DataFlow::Node { |
| 53 | + /** |
| 54 | + * Gets a string that represents the source kind with respect to threat modeling. |
| 55 | + */ |
| 56 | + abstract string getThreatModel(); |
| 57 | + |
| 58 | + /** Gets a string that describes the type of this flow source. */ |
| 59 | + abstract string getSourceType(); |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * A class of data flow sources that respects the |
| 64 | + * current threat model configuration. |
| 65 | + */ |
| 66 | +class ThreatModelFlowSource extends DataFlow::Node { |
| 67 | + ThreatModelFlowSource() { |
| 68 | + exists(string kind | |
| 69 | + // Specific threat model. |
| 70 | + currentThreatModel(kind) and |
| 71 | + (this.(SourceNode).getThreatModel() = kind or ExternalFlow::sourceNode(this, kind)) |
| 72 | + ) |
41 | 73 | }
|
42 | 74 | }
|
0 commit comments