Skip to content

Commit 08bbe59

Browse files
committed
Create the sink ClassificationReasons
Write the reasons that indicate that an endpoint is a sink for each sink type. Also fix import error.
1 parent 649c3af commit 08bbe59

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Provides information about the results of boosted queries for use in adaptive threat modeling (ATM).
55
*/
66

7-
private import javascript::DataFlow as DataFlow
7+
private import javascript::DataFlow
88
import ATMConfig
99
private import BaseScoring
1010
private import EndpointScoring as EndpointScoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* For internal use only.
3+
*
4+
* Defines a set of characteristics that a particular endpoint might have. This set of characteristics is used to make
5+
* decisions about whether to include the endpoint in the training set and with what label, as well as whether to score
6+
* the endpoint at inference time.
7+
*/
8+
9+
import experimental.adaptivethreatmodeling.EndpointTypes
10+
import semmle.javascript.security.dataflow.SqlInjectionCustomizations
11+
private import semmle.javascript.security.dataflow.DomBasedXssCustomizations
12+
private import semmle.javascript.security.dataflow.NosqlInjectionCustomizations
13+
private import semmle.javascript.security.dataflow.TaintedPathCustomizations
14+
15+
abstract class ClassificationReason extends string {
16+
// The name of the reason, which should describe some characteristic of the endpoint that is meaningful for
17+
// determining whether it's a sink and if so of which type
18+
bindingset[this]
19+
ClassificationReason() { any() }
20+
21+
// Indicators with confidence at or above this threshold are considered to be high-confidence indicators.
22+
float getHighConfidenceThreshold() { result = 0.8 }
23+
24+
// Indicators with confidence at or above this threshold are considered to be medium-confidence indicators.
25+
float getMediumConfidenceThreshold() { result = 0.5 }
26+
27+
// The logic to identify which endpoints have this reason.
28+
abstract predicate getEndpoints(DataFlow::Node n);
29+
30+
// This predicate describes what the reason tells us about an endpoint.
31+
//
32+
// Params:
33+
// endpointClass: Class 0 is the negative class. Each positive int corresponds to a single sink type.
34+
// isPositiveIndicator: Does this reason indicate this endpoint _is_ a member of the class, or that it _isn't_ a
35+
// member of the class?
36+
// confidence: A number in [0, 1], which tells us how strong an indicator this reason is for the endpoint belonging /
37+
// not belonging to the given class.
38+
abstract predicate getImplications(
39+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
40+
);
41+
}
42+
43+
/*
44+
* Endpoints that were identified as "DomBasedXssSink" by the standard Javascript library are XSS sinks with maximal
45+
* confidence.
46+
*/
47+
48+
class DomBasedXssSinkReason extends ClassificationReason {
49+
DomBasedXssSinkReason() { 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 that were identified as "TaintedPathSink" by the standard Javascript library are path injection sinks with
62+
* maximal confidence.
63+
*/
64+
65+
class TaintedPathSinkReason extends ClassificationReason {
66+
TaintedPathSinkReason() { this = "TaintedPathSink" }
67+
68+
override predicate getEndpoints(DataFlow::Node n) { n instanceof TaintedPath::Sink }
69+
70+
override predicate getImplications(
71+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
72+
) {
73+
endpointClass instanceof TaintedPathSinkType and isPositiveIndicator = true and confidence = 1.0
74+
}
75+
}
76+
77+
/*
78+
* Endpoints that were identified as "SqlInjectionSink" by the standard Javascript library are SQL injection sinks with
79+
* maximal confidence.
80+
*/
81+
82+
class SqlInjectionSinkReason extends ClassificationReason {
83+
SqlInjectionSinkReason() { this = "SqlInjectionSink" }
84+
85+
override predicate getEndpoints(DataFlow::Node n) { n instanceof SqlInjection::Sink }
86+
87+
override predicate getImplications(
88+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
89+
) {
90+
endpointClass instanceof SqlInjectionSinkType and
91+
isPositiveIndicator = true and
92+
confidence = 1.0
93+
}
94+
}
95+
96+
/*
97+
* Endpoints that were identified as "NosqlInjectionSink" by the standard Javascript library are NoSQL injection sinks
98+
* with maximal confidence.
99+
*/
100+
101+
class NosqlInjectionSinkReason extends ClassificationReason {
102+
NosqlInjectionSinkReason() { this = "NosqlInjectionSink" }
103+
104+
override predicate getEndpoints(DataFlow::Node n) { n instanceof NosqlInjection::Sink }
105+
106+
override predicate getImplications(
107+
EndpointType endpointClass, boolean isPositiveIndicator, float confidence
108+
) {
109+
endpointClass instanceof NosqlInjectionSinkType and
110+
isPositiveIndicator = true and
111+
confidence = 1.0
112+
}
113+
}

0 commit comments

Comments
 (0)