Skip to content

Commit 383437c

Browse files
committed
JS: Only featurize endpoints that are part of a flow path
1 parent c03f189 commit 383437c

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import javascript
88
import CodeToFeatures
9-
import EndpointScoring
9+
private import EndpointScoring
1010

1111
/**
1212
* Gets the value of the token-based feature named `featureName` for the endpoint `endpoint`.
@@ -269,14 +269,22 @@ private string getASupportedFeatureName() {
269269
]
270270
}
271271

272+
/** A configuration that defines which endpoints should be featurized. */
273+
abstract class FeaturizationConfig extends string {
274+
bindingset[this]
275+
FeaturizationConfig() { any() }
276+
277+
abstract DataFlow::Node getAnEndpointToFeaturize();
278+
}
279+
272280
/**
273281
* Generic token-based features for ATM.
274282
*
275283
* This predicate holds if the generic token-based feature named `featureName` has the value
276284
* `featureValue` for the endpoint `endpoint`.
277285
*/
278286
predicate tokenFeatures(DataFlow::Node endpoint, string featureName, string featureValue) {
279-
ModelScoring::endpoints(endpoint) and
287+
endpoint = any(FeaturizationConfig cfg).getAnEndpointToFeaturize() and
280288
(
281289
if strictcount(getTokenFeature(endpoint, featureName)) = 1
282290
then featureValue = getTokenFeature(endpoint, featureName)

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,30 @@ DatabaseFeatures::Entity getRepresentativeEntityForEndpoint(DataFlow::Node endpo
8080
}
8181

8282
module ModelScoring {
83-
predicate endpoints(DataFlow::Node endpoint) {
84-
getCfg().isEffectiveSource(endpoint) or
85-
getCfg().isEffectiveSink(endpoint)
83+
/**
84+
* A featurization config that only featurizes new candidate endpoints that are part of a flow
85+
* path.
86+
*/
87+
class RelevantFeaturizationConfig extends EndpointFeatures::FeaturizationConfig {
88+
RelevantFeaturizationConfig() { this = "RelevantFeaturization" }
89+
90+
override DataFlow::Node getAnEndpointToFeaturize() {
91+
getCfg().isEffectiveSource(result) and any(DataFlow::Configuration cfg).hasFlow(result, _)
92+
or
93+
getCfg().isEffectiveSink(result) and any(DataFlow::Configuration cfg).hasFlow(_, result)
94+
}
8695
}
8796

88-
private int requestedEndpointTypes() { result = any(EndpointType type).getEncoding() }
89-
90-
private predicate relevantTokenFeatures(
91-
DataFlow::Node endpoint, string featureName, string featureValue
92-
) {
93-
endpoints(endpoint) and
94-
EndpointFeatures::tokenFeatures(endpoint, featureName, featureValue)
97+
DataFlow::Node getARequestedEndpoint() {
98+
result = any(EndpointFeatures::FeaturizationConfig cfg).getAnEndpointToFeaturize()
9599
}
96100

101+
private int getARequestedEndpointType() { result = any(EndpointType type).getEncoding() }
102+
97103
predicate endpointScores(DataFlow::Node endpoint, int encodedEndpointType, float score) =
98-
scoreEndpoints(endpoints/1, requestedEndpointTypes/0, relevantTokenFeatures/3,
99-
getACompatibleModelChecksum/0)(endpoint, encodedEndpointType, score)
104+
scoreEndpoints(getARequestedEndpoint/0, getARequestedEndpointType/0,
105+
EndpointFeatures::tokenFeatures/3, getACompatibleModelChecksum/0)(endpoint,
106+
encodedEndpointType, score)
100107
}
101108

102109
/**
@@ -212,7 +219,9 @@ class EndpointScoringResults extends ScoringResults {
212219
}
213220

214221
module Debugging {
215-
query predicate hopInputEndpoints = ModelScoring::endpoints/1;
222+
query predicate hopInputEndpoints(DataFlow::Node endpoint) {
223+
endpoint = ModelScoring::getARequestedEndpoint()
224+
}
216225

217226
query predicate endpointScores = ModelScoring::endpointScores/3;
218227

0 commit comments

Comments
 (0)