Skip to content

Commit 5198ad7

Browse files
authored
Merge pull request github#11055 from github/tiferet/sink-classification-reasons
Sink endpoint characteristics
2 parents b32f4b8 + 833041c commit 5198ad7

File tree

6 files changed

+119
-9
lines changed

6 files changed

+119
-9
lines changed

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/ATMConfig.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
private import javascript as JS
88
import EndpointTypes
9+
import EndpointCharacteristics
910

1011
/**
1112
* EXPERIMENTAL. This API may change in the future.
@@ -44,7 +45,14 @@ abstract class AtmConfig extends string {
4445
*
4546
* Holds if `sink` is a known sink of flow.
4647
*/
47-
predicate isKnownSink(JS::DataFlow::Node sink) { none() }
48+
final predicate isKnownSink(JS::DataFlow::Node sink) {
49+
// If the list of characteristics includes positive indicators with maximal confidence for this class, then it's a
50+
// known sink for the class.
51+
exists(EndpointCharacteristic characteristic |
52+
characteristic.getEndpoints(sink) and
53+
characteristic.getImplications(this.getASinkEndpointType(), true, 1.0)
54+
)
55+
}
4856

4957
/**
5058
* EXPERIMENTAL. This API may change in the future.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* For internal use only.
3+
*/
4+
5+
import experimental.adaptivethreatmodeling.EndpointTypes
6+
private import semmle.javascript.security.dataflow.SqlInjectionCustomizations
7+
private import semmle.javascript.security.dataflow.DomBasedXssCustomizations
8+
private import semmle.javascript.security.dataflow.NosqlInjectionCustomizations
9+
private import semmle.javascript.security.dataflow.TaintedPathCustomizations
10+
11+
/**
12+
* A set of characteristics that a particular endpoint might have. This set of characteristics is used to make decisions
13+
* about whether to include the endpoint in the training set and with what label, as well as whether to score the
14+
* endpoint at inference time.
15+
*/
16+
abstract class EndpointCharacteristic extends string {
17+
/**
18+
* Holds when the string matches the name of the characteristic, which should describe some characteristic of the
19+
* endpoint that is meaningful for determining whether it's a sink and if so of which type
20+
*/
21+
bindingset[this]
22+
EndpointCharacteristic() { any() }
23+
24+
/**
25+
* Holds for endpoints that have this characteristic. This predicate contains the logic that applies characteristics
26+
* to the appropriate set of dataflow nodes.
27+
*/
28+
abstract predicate getEndpoints(DataFlow::Node n);
29+
30+
/**
31+
* This predicate describes what the characteristic tells us about an endpoint.
32+
*
33+
* Params:
34+
* endpointClass: Class 0 is the negative class. Each positive int corresponds to a single sink type.
35+
* isPositiveIndicator: Does this characteristic indicate this endpoint _is_ a member of the class, or that it
36+
* _isn't_ a member of the class?
37+
* confidence: A number in [0, 1], which tells us how strong an indicator this characteristic is for the endpoint
38+
* belonging / not belonging to the given class.
39+
*/
40+
abstract predicate getImplications(
41+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
42+
);
43+
}
44+
45+
/**
46+
* Endpoints identified as "DomBasedXssSink" by the standard JavaScript libraries are XSS sinks with maximal confidence.
47+
*/
48+
private class DomBasedXssSinkCharacteristic extends EndpointCharacteristic {
49+
DomBasedXssSinkCharacteristic() { this = "DomBasedXssSink" }
50+
51+
override predicate getEndpoints(DataFlow::Node n) { n instanceof DomBasedXss::Sink }
52+
53+
override predicate getImplications(
54+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
55+
) {
56+
endpointClass instanceof XssSinkType and isPositiveIndicator = true and confidence = 1.0
57+
}
58+
}
59+
60+
/**
61+
* Endpoints identified as "TaintedPathSink" by the standard JavaScript libraries are path injection sinks with maximal
62+
* confidence.
63+
*/
64+
private class TaintedPathSinkCharacteristic extends EndpointCharacteristic {
65+
TaintedPathSinkCharacteristic() { this = "TaintedPathSink" }
66+
67+
override predicate getEndpoints(DataFlow::Node n) { n instanceof TaintedPath::Sink }
68+
69+
override predicate getImplications(
70+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
71+
) {
72+
endpointClass instanceof TaintedPathSinkType and isPositiveIndicator = true and confidence = 1.0
73+
}
74+
}
75+
76+
/**
77+
* Endpoints identified as "SqlInjectionSink" by the standard JavaScript libraries are SQL injection sinks with maximal
78+
* confidence.
79+
*/
80+
private class SqlInjectionSinkCharacteristic extends EndpointCharacteristic {
81+
SqlInjectionSinkCharacteristic() { this = "SqlInjectionSink" }
82+
83+
override predicate getEndpoints(DataFlow::Node n) { n instanceof SqlInjection::Sink }
84+
85+
override predicate getImplications(
86+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
87+
) {
88+
endpointClass instanceof SqlInjectionSinkType and
89+
isPositiveIndicator = true and
90+
confidence = 1.0
91+
}
92+
}
93+
94+
/**
95+
* Endpoints identified as "NosqlInjectionSink" by the standard JavaScript libraries are NoSQL injection sinks with
96+
* maximal confidence.
97+
*/
98+
private class NosqlInjectionSinkCharacteristic extends EndpointCharacteristic {
99+
NosqlInjectionSinkCharacteristic() { this = "NosqlInjectionSink" }
100+
101+
override predicate getEndpoints(DataFlow::Node n) { n instanceof NosqlInjection::Sink }
102+
103+
override predicate getImplications(
104+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
105+
) {
106+
endpointClass instanceof NosqlInjectionSinkType and
107+
isPositiveIndicator = true and
108+
confidence = 1.0
109+
}
110+
}

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/NosqlInjectionATM.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ class NosqlInjectionAtmConfig extends AtmConfig {
9393
source instanceof NosqlInjection::Source or TaintedObject::isSource(source, _)
9494
}
9595

96-
override predicate isKnownSink(DataFlow::Node sink) { sink instanceof NosqlInjection::Sink }
97-
9896
override predicate isEffectiveSink(DataFlow::Node sinkCandidate) {
9997
not exists(SinkEndpointFilter::getAReasonSinkExcluded(sinkCandidate))
10098
}

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/SqlInjectionATM.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class SqlInjectionAtmConfig extends AtmConfig {
6565

6666
override predicate isKnownSource(DataFlow::Node source) { source instanceof SqlInjection::Source }
6767

68-
override predicate isKnownSink(DataFlow::Node sink) { sink instanceof SqlInjection::Sink }
69-
7068
override predicate isEffectiveSink(DataFlow::Node sinkCandidate) {
7169
not exists(SinkEndpointFilter::getAReasonSinkExcluded(sinkCandidate))
7270
}

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/TaintedPathATM.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class TaintedPathAtmConfig extends AtmConfig {
6464

6565
override predicate isKnownSource(DataFlow::Node source) { source instanceof TaintedPath::Source }
6666

67-
override predicate isKnownSink(DataFlow::Node sink) { sink instanceof TaintedPath::Sink }
68-
6967
override predicate isEffectiveSink(DataFlow::Node sinkCandidate) {
7068
not exists(SinkEndpointFilter::getAReasonSinkExcluded(sinkCandidate))
7169
}

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/XssATM.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class DomBasedXssAtmConfig extends AtmConfig {
6565

6666
override predicate isKnownSource(DataFlow::Node source) { source instanceof DomBasedXss::Source }
6767

68-
override predicate isKnownSink(DataFlow::Node sink) { sink instanceof DomBasedXss::Sink }
69-
7068
override predicate isEffectiveSink(DataFlow::Node sinkCandidate) {
7169
not exists(SinkEndpointFilter::getAReasonSinkExcluded(sinkCandidate))
7270
}

0 commit comments

Comments
 (0)