Skip to content

Commit f38b498

Browse files
authored
Merge pull request #8433 from github/henrymercer/js-atm-remove-isEffectiveSinkWithOverridingScore
JS: Remove `isEffectiveSinkWithOverridingScore` from ML-powered libraries
2 parents 6f484d3 + 8b1b2af commit f38b498

File tree

3 files changed

+20
-60
lines changed

3 files changed

+20
-60
lines changed

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,6 @@ abstract class AtmConfig extends string {
6262
*/
6363
predicate isEffectiveSink(raw::DataFlow::Node candidateSink) { none() }
6464

65-
/**
66-
* EXPERIMENTAL. This API may change in the future.
67-
*
68-
* Holds if the candidate sink `candidateSink` predicted by the machine learning model should be
69-
* an effective sink that overrides the score provided by the machine learning model with the
70-
* score `score` for reason `why`. The effective sinks identified by this predicate MUST be a
71-
* subset of those identified by the `isEffectiveSink` predicate.
72-
*
73-
* For example, in the ATM external API query, we use this method to ensure the ATM external API
74-
* query produces the same results as the standard external API query, but assigns flows
75-
* involving sinks that are filtered out by the endpoint filters a score of 0.
76-
*
77-
* This predicate can be phased out once we no longer need to rely on predicates like
78-
* `paddedScore` in the ATM CodeQL libraries to add scores to alert messages in a way that works
79-
* with lexical sort orders.
80-
*/
81-
predicate isEffectiveSinkWithOverridingScore(
82-
raw::DataFlow::Node candidateSink, float score, string why
83-
) {
84-
none()
85-
}
86-
8765
/**
8866
* EXPERIMENTAL. This API may change in the future.
8967
*

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

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,11 @@ private float getScoreForSource(DataFlow::Node source) {
6262
private float getScoreForSink(DataFlow::Node sink) {
6363
if getCfg().isKnownSink(sink)
6464
then result = 1.0
65-
else
66-
if getCfg().isEffectiveSinkWithOverridingScore(sink, result, _)
67-
then any()
68-
else (
69-
// This restriction on `sink` has no semantic effect but improves performance.
70-
getCfg().isEffectiveSink(sink) and
71-
ModelScoring::endpointScores(sink, getCfg().getASinkEndpointType().getEncoding(), result)
72-
)
65+
else (
66+
// This restriction on `sink` has no semantic effect but improves performance.
67+
getCfg().isEffectiveSink(sink) and
68+
ModelScoring::endpointScores(sink, getCfg().getASinkEndpointType().getEncoding(), result)
69+
)
7370
}
7471

7572
class EndpointScoringResults extends ScoringResults {
@@ -109,10 +106,6 @@ class EndpointScoringResults extends ScoringResults {
109106
result = "known" and getCfg().isKnownSink(sink)
110107
or
111108
not getCfg().isKnownSink(sink) and
112-
getCfg().isEffectiveSinkWithOverridingScore(sink, _, result)
113-
or
114-
not getCfg().isKnownSink(sink) and
115-
not getCfg().isEffectiveSinkWithOverridingScore(sink, _, _) and
116109
result =
117110
"predicted (scores: " +
118111
concat(EndpointType type, float score |
@@ -127,29 +120,21 @@ class EndpointScoringResults extends ScoringResults {
127120
override predicate shouldResultBeIncluded(DataFlow::Node source, DataFlow::Node sink) {
128121
if getCfg().isKnownSink(sink)
129122
then any()
130-
else
131-
if getCfg().isEffectiveSinkWithOverridingScore(sink, _, _)
132-
then
133-
exists(float score |
134-
getCfg().isEffectiveSinkWithOverridingScore(sink, score, _) and
135-
score >= getCfg().getScoreCutoff()
136-
)
137-
else (
138-
// This restriction on `sink` has no semantic effect but improves performance.
139-
getCfg().isEffectiveSink(sink) and
140-
exists(float sinkScore |
141-
ModelScoring::endpointScores(sink, getCfg().getASinkEndpointType().getEncoding(),
142-
sinkScore) and
143-
// Include the endpoint if (a) the query endpoint type scores higher than all other
144-
// endpoint types, or (b) the query endpoint type scores at least
145-
// 0.5 - (getCfg().getScoreCutoff() / 2).
146-
sinkScore >=
147-
[
148-
max(float s | ModelScoring::endpointScores(sink, _, s)),
149-
0.5 - getCfg().getScoreCutoff() / 2
150-
]
151-
)
123+
else (
124+
// This restriction on `sink` has no semantic effect but improves performance.
125+
getCfg().isEffectiveSink(sink) and
126+
exists(float sinkScore |
127+
ModelScoring::endpointScores(sink, getCfg().getASinkEndpointType().getEncoding(), sinkScore) and
128+
// Include the endpoint if (a) the query endpoint type scores higher than all other
129+
// endpoint types, or (b) the query endpoint type scores at least
130+
// 0.5 - (getCfg().getScoreCutoff() / 2).
131+
sinkScore >=
132+
[
133+
max(float s | ModelScoring::endpointScores(sink, _, s)),
134+
0.5 - getCfg().getScoreCutoff() / 2
135+
]
152136
)
137+
)
153138
}
154139
}
155140

javascript/ql/experimental/adaptivethreatmodeling/modelbuilding/extraction/ExtractEndpointData.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ private DataFlow::Node getANotASink(NotASinkReason reason) {
7474
* specified query.
7575
*/
7676
private DataFlow::Node getAnUnknown(Query query) {
77-
(
78-
getAtmCfg(query).isEffectiveSink(result) or
79-
getAtmCfg(query).isEffectiveSinkWithOverridingScore(result, _, _)
80-
) and
77+
getAtmCfg(query).isEffectiveSink(result) and
8178
not result = getASink(query) and
8279
// Only consider the source code for the project being analyzed.
8380
exists(result.getFile().getRelativePath())

0 commit comments

Comments
 (0)