Skip to content

Commit 75cd7a9

Browse files
committed
Remove code duplication in query .ql files:
Define the query for finding ATM alerts in the base class `AtmConfig`, and call it from each query's .ql file.
1 parent a710b72 commit 75cd7a9

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
private import javascript as JS
88
import EndpointTypes
99
import EndpointCharacteristics as EndpointCharacteristics
10+
import AdaptiveThreatModeling::ATM::ResultsInfo as AtmResultsInfo
1011

1112
/**
1213
* EXPERIMENTAL. This API may change in the future.
@@ -140,6 +141,17 @@ abstract class AtmConfig extends JS::TaintTracking::Configuration {
140141
* A cut-off value of 1 produces all alerts including those that are likely false-positives.
141142
*/
142143
float getScoreCutoff() { result = 0.0 }
144+
145+
/**
146+
* Holds if there's an ATM alert (a flow path from `source` to `sink` with ML-determined likelihood `score`) according
147+
* to this ML-boosted configuration, whereas the unboosted base query is unlikely to report an alert for this source
148+
* and sink.
149+
*/
150+
predicate getAlerts(JS::DataFlow::PathNode source, JS::DataFlow::PathNode sink, float score) {
151+
this.hasFlowPath(source, sink) and
152+
not AtmResultsInfo::isFlowLikelyInBaseQuery(source.getNode(), sink.getNode()) and
153+
score = AtmResultsInfo::getScoreForFlow(source.getNode(), sink.getNode())
154+
}
143155
}
144156

145157
/** DEPRECATED: Alias for AtmConfig */

javascript/ql/experimental/adaptivethreatmodeling/src/NosqlInjectionATM.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ import ATM::ResultsInfo
1717
import DataFlow::PathGraph
1818
import experimental.adaptivethreatmodeling.NosqlInjectionATM
1919

20-
from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
21-
where
22-
cfg.hasFlowPath(source, sink) and
23-
not isFlowLikelyInBaseQuery(source.getNode(), sink.getNode()) and
24-
score = getScoreForFlow(source.getNode(), sink.getNode())
20+
from AtmConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
21+
where cfg.getAlerts(source, sink, score)
2522
select sink.getNode(), source, sink,
2623
"(Experimental) This may be a database query that depends on $@. Identified using machine learning.",
2724
source.getNode(), "a user-provided value", score

javascript/ql/experimental/adaptivethreatmodeling/src/SqlInjectionATM.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ import experimental.adaptivethreatmodeling.SqlInjectionATM
1717
import ATM::ResultsInfo
1818
import DataFlow::PathGraph
1919

20-
from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
21-
where
22-
cfg.hasFlowPath(source, sink) and
23-
not isFlowLikelyInBaseQuery(source.getNode(), sink.getNode()) and
24-
score = getScoreForFlow(source.getNode(), sink.getNode())
20+
from AtmConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
21+
where cfg.getAlerts(source, sink, score)
2522
select sink.getNode(), source, sink,
2623
"(Experimental) This may be a database query that depends on $@. Identified using machine learning.",
2724
source.getNode(), "a user-provided value", score

javascript/ql/experimental/adaptivethreatmodeling/src/TaintedPathATM.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ import ATM::ResultsInfo
2121
import DataFlow::PathGraph
2222
import experimental.adaptivethreatmodeling.TaintedPathATM
2323

24-
from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
25-
where
26-
cfg.hasFlowPath(source, sink) and
27-
not isFlowLikelyInBaseQuery(source.getNode(), sink.getNode()) and
28-
score = getScoreForFlow(source.getNode(), sink.getNode())
24+
from AtmConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
25+
where cfg.getAlerts(source, sink, score)
2926
select sink.getNode(), source, sink,
3027
"(Experimental) This may be a path that depends on $@. Identified using machine learning.",
3128
source.getNode(), "a user-provided value", score

javascript/ql/experimental/adaptivethreatmodeling/src/XssATM.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ import ATM::ResultsInfo
1818
import DataFlow::PathGraph
1919
import experimental.adaptivethreatmodeling.XssATM
2020

21-
from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
22-
where
23-
cfg.hasFlowPath(source, sink) and
24-
not isFlowLikelyInBaseQuery(source.getNode(), sink.getNode()) and
25-
score = getScoreForFlow(source.getNode(), sink.getNode())
21+
from AtmConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score
22+
where cfg.getAlerts(source, sink, score)
2623
select sink.getNode(), source, sink,
2724
"(Experimental) This may be a cross-site scripting vulnerability due to $@. Identified using machine learning.",
2825
source.getNode(), "a user-provided value", score

0 commit comments

Comments
 (0)