Skip to content

Commit cf29cde

Browse files
committed
Apply suggestions from code review
1 parent 93e3c72 commit cf29cde

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
erroneousEndpoints
2+
erroneousConfidences

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

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ import javascript
1010
private import experimental.adaptivethreatmodeling.EndpointCharacteristics as EndpointCharacteristics
1111
private import experimental.adaptivethreatmodeling.EndpointTypes as EndpointTypes
1212

13+
/**
14+
* Holds if `characteristic1` and `characteristic2` are among the several pairs of currently known high-confidence
15+
* negative characteristics that apply to some known sinks.
16+
*
17+
* TODO: Experiment with lowering the confidence of `"FileSystemAccess"`, `"DOM"`, `"DatabaseAccess"`, and
18+
* `"JQueryArgument"`.
19+
*/
20+
private predicate knownContradictoryCharacteristics(
21+
EndpointCharacteristics::EndpointCharacteristic characteristic1,
22+
EndpointCharacteristics::EndpointCharacteristic characteristic2
23+
) {
24+
characteristic1 != characteristic2 and
25+
(
26+
characteristic1 = ["TaintedPathSink", "FileSystemAccess"] and
27+
characteristic2 = ["TaintedPathSink", "FileSystemAccess"]
28+
or
29+
characteristic1 = ["DomBasedXssSink", "DOM"] and
30+
characteristic2 = ["DomBasedXssSink", "DOM"]
31+
or
32+
characteristic1 = ["DomBasedXssSink", "JQueryArgument"] and
33+
characteristic2 = ["DomBasedXssSink", "JQueryArgument"]
34+
or
35+
characteristic1 = ["NosqlInjectionSink", "DatabaseAccess"] and
36+
characteristic2 = ["NosqlInjectionSink", "DatabaseAccess"]
37+
or
38+
characteristic1 = ["SqlInjectionSink", "DatabaseAccess"] and
39+
characteristic2 = ["SqlInjectionSink", "DatabaseAccess"]
40+
)
41+
}
42+
1343
/**
1444
* Holds if the given endpoint has a self-contradictory combination of characteristics. Detects errors in our endpoint
1545
* characteristics. Lists the problematic characterisitics and their implications for all such endpoints, together with
@@ -33,24 +63,7 @@ query predicate erroneousEndpoints(
3363
confidence > characteristic.mediumConfidence() and
3464
confidence2 > characteristic2.mediumConfidence() and
3565
// 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-
)
66+
not knownContradictoryCharacteristics(characteristic, characteristic2)
5467
) and
5568
errorMessage = "Endpoint has high-confidence positive indicators for multiple classes"
5669
or
@@ -65,10 +78,13 @@ query predicate erroneousEndpoints(
6578
confidence2 > characteristic2.mediumConfidence()
6679
) and
6780
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
81+
}
82+
83+
query predicate erroneousConfidences(
84+
EndpointCharacteristics::EndpointCharacteristic characteristic, float confidence,
85+
string errorMessage
86+
) {
7187
characteristic.hasImplications(_, _, confidence) and
7288
(confidence < 0 or confidence > 1) and
73-
errorMessage = "Endpoint has an indicator with confidence outside of [0, 1]"
89+
errorMessage = "Characteristic has an indicator with confidence outside of [0, 1]"
7490
}

0 commit comments

Comments
 (0)