Skip to content

Commit f68a40f

Browse files
committed
JS: Simplify calculation of token features for endpoints
Use a `strictcount` to identify whether there is exactly one feature or not. If so, we use it. If not, we use the empty string. Add context to ensure we filter the set of data flow nodes down to only the set of endpoint nodes. This performance optimisation avoids calculating the Cartesian product of data flow nodes and feature names, but it does not avoid calculating the (slightly smaller) Cartesian product of endpoint nodes and feature names. Product size = number of endpoint nodes * number of feature names. At time of writing there are 8 feature names.
1 parent fac2769 commit f68a40f

File tree

1 file changed

+5
-4
lines changed
  • javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,11 @@ private string getASupportedFeatureName() {
277277
* `featureValue` for the endpoint `endpoint`.
278278
*/
279279
predicate tokenFeatures(DataFlow::Node endpoint, string featureName, string featureValue) {
280-
featureName = getASupportedFeatureName() and
280+
ModelScoring::endpoints(endpoint) and
281281
(
282-
featureValue = unique(string x | x = getTokenFeature(endpoint, featureName))
283-
or
284-
not exists(unique(string x | x = getTokenFeature(endpoint, featureName))) and featureValue = ""
282+
if strictcount(getTokenFeature(endpoint, featureName)) = 1
283+
then featureValue = getTokenFeature(endpoint, featureName)
284+
// Performance note: this is a Cartesian product between all endpoints and feature names.
285+
else (featureValue = "" and featureName = getASupportedFeatureName())
285286
)
286287
}

0 commit comments

Comments
 (0)