Skip to content

Commit 93e3c72

Browse files
committed
Test for contradictory endpoint characteristics
1 parent a11756b commit 93e3c72

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/ContradictoryEndpointCharacteristics.expected

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* ContradictoryEndpointCharacteristics.ql
3+
*
4+
* This tests surfaces endpoints that have a set of characteristics are logically incompatible with one another (e.g one
5+
* high-confidence characteristic that implies a non-sink and another that implies a sink). If the test surfaces any
6+
* such endpoints, this is a hint that some of our endpoint characteristics may be need to be adjusted.
7+
*/
8+
9+
import javascript
10+
private import experimental.adaptivethreatmodeling.EndpointCharacteristics as EndpointCharacteristics
11+
private import experimental.adaptivethreatmodeling.EndpointTypes as EndpointTypes
12+
13+
/**
14+
* Holds if the given endpoint has a self-contradictory combination of characteristics. Detects errors in our endpoint
15+
* characteristics. Lists the problematic characterisitics and their implications for all such endpoints, together with
16+
* an error message indicating why this combination is problematic.
17+
*/
18+
query predicate erroneousEndpoints(
19+
DataFlow::Node endpoint, EndpointCharacteristics::EndpointCharacteristic characteristic,
20+
EndpointTypes::EndpointType endpointClass, float confidence, string errorMessage
21+
) {
22+
// An endpoint's characteristics should not include positive indicators with medium/high confidence for more than one
23+
// class.
24+
exists(
25+
EndpointCharacteristics::EndpointCharacteristic characteristic2,
26+
EndpointTypes::EndpointType endpointClass2, float confidence2
27+
|
28+
endpointClass.getEncoding() != endpointClass2.getEncoding() and
29+
characteristic.appliesToEndpoint(endpoint) and
30+
characteristic2.appliesToEndpoint(endpoint) and
31+
characteristic.hasImplications(endpointClass, true, confidence) and
32+
characteristic2.hasImplications(endpointClass2, true, confidence2) and
33+
confidence > characteristic.mediumConfidence() and
34+
confidence2 > characteristic2.mediumConfidence() and
35+
// We currently know of several high-confidence negative characteristics that apply to some known sinks.
36+
// TODO: Experiment with lowering the confidence of `"FileSystemAccess"`, `"DOM"`, `"DatabaseAccess"`, and
37+
// `"JQueryArgument"`.
38+
not (
39+
characteristic = ["TaintedPathSink", "FileSystemAccess"] and
40+
characteristic2 = ["TaintedPathSink", "FileSystemAccess"]
41+
or
42+
characteristic = ["DomBasedXssSink", "DOM"] and
43+
characteristic2 = ["DomBasedXssSink", "DOM"]
44+
or
45+
characteristic = ["DomBasedXssSink", "JQueryArgument"] and
46+
characteristic2 = ["DomBasedXssSink", "JQueryArgument"]
47+
or
48+
characteristic = ["NosqlInjectionSink", "DatabaseAccess"] and
49+
characteristic2 = ["NosqlInjectionSink", "DatabaseAccess"]
50+
or
51+
characteristic = ["SqlInjectionSink", "DatabaseAccess"] and
52+
characteristic2 = ["SqlInjectionSink", "DatabaseAccess"]
53+
)
54+
) and
55+
errorMessage = "Endpoint has high-confidence positive indicators for multiple classes"
56+
or
57+
// An enpoint's characteristics should not include positive indicators with medium/high confidence for some class and
58+
// also include negative indicators with medium/high confidence for this same class.
59+
exists(EndpointCharacteristics::EndpointCharacteristic characteristic2, float confidence2 |
60+
characteristic.appliesToEndpoint(endpoint) and
61+
characteristic2.appliesToEndpoint(endpoint) and
62+
characteristic.hasImplications(endpointClass, true, confidence) and
63+
characteristic2.hasImplications(endpointClass, false, confidence2) and
64+
confidence > characteristic.mediumConfidence() and
65+
confidence2 > characteristic2.mediumConfidence()
66+
) and
67+
errorMessage = "Endpoint has high-confidence positive and negative indicators for the same class"
68+
or
69+
// The endpoint's characteristics should not include indicators with confidence outside of [0, 1].
70+
characteristic.appliesToEndpoint(endpoint) and
71+
characteristic.hasImplications(_, _, confidence) and
72+
(confidence < 0 or confidence > 1) and
73+
errorMessage = "Endpoint has an indicator with confidence outside of [0, 1]"
74+
}

0 commit comments

Comments
 (0)