Skip to content

Commit 144ec8c

Browse files
committed
JS: Update featurization for absent features optimization
Absent features are now represented implicitly by the absence of a row in the `tokenFeatures` relation, rather than explicitly by an empty string. This leads to improved runtime performance. To enable this implicit representation, we pass the set of supported token features to the `scoreEndpoints` HOP. Requires CodeQL CLI v2.7.4.
1 parent bebf4ca commit 144ec8c

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private module AccessPaths {
283283
}
284284

285285
/** Get a name of a supported generic token-based feature. */
286-
private string getASupportedFeatureName() {
286+
string getASupportedFeatureName() {
287287
result =
288288
[
289289
"enclosingFunctionName", "calleeName", "receiverName", "argumentIndex", "calleeApiName",
@@ -300,12 +300,5 @@ private string getASupportedFeatureName() {
300300
predicate tokenFeatures(DataFlow::Node endpoint, string featureName, string featureValue) {
301301
// Performance optimization: Restrict feature extraction to endpoints we've explicitly asked to featurize.
302302
endpoint = any(FeaturizationConfig cfg).getAnEndpointToFeaturize() and
303-
(
304-
if strictcount(getTokenFeature(endpoint, featureName)) = 1
305-
then featureValue = getTokenFeature(endpoint, featureName)
306-
else (
307-
// Performance note: this is a Cartesian product between all endpoints and feature names.
308-
featureValue = "" and featureName = getASupportedFeatureName()
309-
)
310-
)
303+
featureValue = getTokenFeature(endpoint, featureName)
311304
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ module ModelScoring {
101101
private int getARequestedEndpointType() { result = any(EndpointType type).getEncoding() }
102102

103103
predicate endpointScores(DataFlow::Node endpoint, int encodedEndpointType, float score) =
104-
scoreEndpoints(getARequestedEndpoint/0, getARequestedEndpointType/0,
105-
EndpointFeatures::tokenFeatures/3, getACompatibleModelChecksum/0)(endpoint,
106-
encodedEndpointType, score)
104+
scoreEndpoints(getARequestedEndpoint/0, EndpointFeatures::tokenFeatures/3,
105+
EndpointFeatures::getASupportedFeatureName/0, getARequestedEndpointType/0,
106+
getACompatibleModelChecksum/0)(endpoint, encodedEndpointType, score)
107107
}
108108

109109
/**

0 commit comments

Comments
 (0)