Skip to content

Commit df6449c

Browse files
committed
Go: Add the SourceNode and ThreatModelFlowSource classes
1 parent b697068 commit df6449c

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

go/ql/lib/semmle/go/security/FlowSources.qll

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import go
66
private import semmle.go.dataflow.ExternalFlow as ExternalFlow
7+
private import codeql.threatmodels.ThreatModels
78

89
/**
910
* DEPRECATED: Use `RemoteFlowSource` instead.
@@ -31,12 +32,43 @@ module RemoteFlowSource {
3132
* Extend this class to model new APIs. If you want to refine existing API models,
3233
* extend `RemoteFlowSource` instead.
3334
*/
34-
abstract class Range extends DataFlow::Node { }
35+
abstract class Range extends SourceNode {
36+
override string getThreatModel() { result = "remote" }
37+
}
3538

3639
/**
3740
* A source of data that is controlled by an untrusted user.
3841
*/
3942
class MaDRemoteSource extends Range {
4043
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+
)
4173
}
4274
}

0 commit comments

Comments
 (0)