Skip to content

Commit 27e5fce

Browse files
Esben Sparre Andreasenesbena
authored andcommitted
JS: make the default PoIConfiguration/enabled inclusive
1 parent 3b45bcd commit 27e5fce

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

javascript/ql/src/experimental/poi/PoI.qll

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* in an unknown code base.
44
*
55
* To use this module, subclass the
6-
* `Poi::PoI` class, override *one* of its `is` predicates, and use
6+
* `PoI` class, override *one* of its `is` predicates, and use
77
* `alertQuery` as a `@kind problem` query . This will present
88
* the desired points of interest as alerts that are easily browsable
99
* in a codeql IDE. By itself, this is no different from an ordinary
@@ -12,7 +12,6 @@
1212
*
1313
* - points of interest can be added, removed and mixed seamlessly
1414
* - this module comes with a collection of standard points of interest (see `StandardPoIs`)
15-
* - this modules comes with groupings of related points of interest (see `StandardPoIConfigurations`)
1615
*
1716
* A global configuration for the points of interest (see
1817
* `PoIConfg`) can be used to easily manage multiple points of
@@ -37,12 +36,12 @@
3736
* override predicate shown(DataFlow::Node n) { n.getFile().getBaseName() = "server-core.js" }
3837
* }
3938
*
40-
* class RouteHandlerPoI extends PoI {
39+
* class RouteHandlerPoI extends DefaultEnabledPoI {
4140
* RouteHandlerPoI() { this = "RouteHandlerPoI" }
4241
* override predicate is(DataFlow::Node l0) { l0 instanceof Express::RouteHandler }
4342
* }
4443
*
45-
* class RouteSetupAndRouteHandlerPoI extends PoI {
44+
* class RouteSetupAndRouteHandlerPoI extends DefaultEnabledPoI {
4645
* RouteSetupAndRouteHandlerPoI() { this = "RouteSetupAndRouteHandlerPoI" }
4746
*
4847
* override predicate is(DataFlow::Node l0, DataFlow::Node l1, string t1) {
@@ -61,12 +60,20 @@ private import semmle.javascript.RestrictedLocations
6160

6261
/**
6362
* Provides often used points of interest.
63+
*
64+
* Note that these points of interest should not extend
65+
* `DefaultEnabledPoI`, and that they can be enabled by default on
66+
* demand like this:
67+
*
68+
* ```
69+
* class MyPoI extends ServerRelatedPoI, DefaultEnabledPoI {}
70+
* ```
6471
*/
6572
private module StandardPoIs {
6673
/**
6774
* An unpromoted route setup candidate.
6875
*/
69-
class UnpromotedRouteSetupPoI extends StandardPoI {
76+
class UnpromotedRouteSetupPoI extends PoI {
7077
UnpromotedRouteSetupPoI() { this = "UnpromotedRouteSetupPoI" }
7178

7279
override predicate is(Node l0) {
@@ -77,7 +84,7 @@ private module StandardPoIs {
7784
/**
7885
* An unpromoted route handler candidate.
7986
*/
80-
class UnpromotedRouteHandlerPoI extends StandardPoI {
87+
class UnpromotedRouteHandlerPoI extends PoI {
8188
UnpromotedRouteHandlerPoI() { this = "UnpromotedRouteHandlerPoI" }
8289

8390
override predicate is(Node l0) {
@@ -88,7 +95,7 @@ private module StandardPoIs {
8895
/**
8996
* An unpromoted route handler candidate, with explnatory data flow information.
9097
*/
91-
class UnpromotedRouteHandlerWithFlowPoI extends StandardPoI {
98+
class UnpromotedRouteHandlerWithFlowPoI extends PoI {
9299
UnpromotedRouteHandlerWithFlowPoI() { this = "UnpromotedRouteHandlerWithFlowPoI" }
93100

94101
private DataFlow::SourceNode track(HTTP::RouteHandlerCandidate cand, DataFlow::TypeTracker t) {
@@ -109,7 +116,7 @@ private module StandardPoIs {
109116
/**
110117
* A callee that is unknown.
111118
*/
112-
class UnknownCalleePoI extends StandardPoI {
119+
class UnknownCalleePoI extends PoI {
113120
UnknownCalleePoI() { this = "UnknownCalleePoI" }
114121

115122
override predicate is(Node l0) {
@@ -120,7 +127,7 @@ private module StandardPoIs {
120127
/**
121128
* A source of remote flow.
122129
*/
123-
class RemoteFlowSourcePoI extends StandardPoI {
130+
class RemoteFlowSourcePoI extends PoI {
124131
RemoteFlowSourcePoI() { this = "RemoteFlowSourcePoI" }
125132

126133
override predicate is(Node l0) { l0 instanceof RemoteFlowSource }
@@ -129,7 +136,7 @@ private module StandardPoIs {
129136
/**
130137
* A "source" for any active configuration.
131138
*/
132-
class SourcePoI extends StandardPoI {
139+
class SourcePoI extends PoI {
133140
SourcePoI() { this = "SourcePoI" }
134141

135142
override predicate is(Node l0) {
@@ -140,7 +147,7 @@ private module StandardPoIs {
140147
/**
141148
* A "sink" for any active configuration.
142149
*/
143-
class SinkPoI extends StandardPoI {
150+
class SinkPoI extends PoI {
144151
SinkPoI() { this = "SinkPoI" }
145152

146153
override predicate is(Node l0) {
@@ -151,7 +158,7 @@ private module StandardPoIs {
151158
/**
152159
* A "barrier" for any active configuration.
153160
*/
154-
class BarrierPoI extends StandardPoI {
161+
class BarrierPoI extends PoI {
155162
BarrierPoI() { this = "BarrierPoI" }
156163

157164
override predicate is(Node l0) {
@@ -171,7 +178,7 @@ private module StandardPoIs {
171178
/**
172179
* A server-related points of interest.
173180
*/
174-
class ServerRelatedPoI extends StandardPoI {
181+
class ServerRelatedPoI extends PoI {
175182
ServerRelatedPoI() {
176183
this instanceof UnpromotedRouteSetupPoI or
177184
this instanceof UnpromotedRouteHandlerPoI or
@@ -182,7 +189,7 @@ private module StandardPoIs {
182189
/**
183190
* A configuration-related points of interest.
184191
*/
185-
class DataFlowConfigurationPoI extends StandardPoI {
192+
class DataFlowConfigurationPoI extends PoI {
186193
DataFlowConfigurationPoI() {
187194
this instanceof SourcePoI or
188195
this instanceof SinkPoI
@@ -196,15 +203,17 @@ private module StandardPoIs {
196203
import StandardPoIs
197204

198205
/**
199-
* A tagging interface for the standard points of interest.
206+
* A tagging interface for a custom point of interest that should be
207+
* enabled in the absence of an explicit
208+
* `PoIConfiguration::enabled/1`.
200209
*/
201-
abstract private class StandardPoI extends PoI {
210+
abstract class DefaultEnabledPoI extends PoI {
202211
bindingset[this]
203-
StandardPoI() { any() }
212+
DefaultEnabledPoI() { any() }
204213
}
205214

206215
private module PoIConfigDefaults {
207-
predicate enabled(PoI poi) { not poi instanceof StandardPoI }
216+
predicate enabled(PoI poi) { poi instanceof DefaultEnabledPoI }
208217

209218
predicate shown(Node n) { not classify(n.getFile(), _) }
210219
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| tst.js:6:1:6:16 | (req, res) => 42 | UnpromotedRouteHandlerPoI | tst.js:6:1:6:16 | (req, res) => 42 | irrelevant | tst.js:6:1:6:16 | (req, res) => 42 | irrelevant |
2+
| tst.js:6:1:6:16 | (req, res) => 42 | UnpromotedRouteHandlerWithFlowPoI: $@ | tst.js:6:1:6:16 | (req, res) => 42 | ends here | tst.js:6:1:6:16 | (req, res) => 42 | irrelevant |
3+
| tst.js:13:1:13:36 | otherAp ... h", rh) | UnpromotedRouteSetupPoI | tst.js:13:1:13:36 | otherAp ... h", rh) | irrelevant | tst.js:13:1:13:36 | otherAp ... h", rh) | irrelevant |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @kind problem
3+
*/
4+
5+
import javascript
6+
import experimental.poi.PoI
7+
8+
class MyServerRelatedPoI extends ServerRelatedPoI, DefaultEnabledPoI {}
9+
10+
query predicate problems = alertQuery/6;

javascript/ql/test/experimental/PoI/TestCustomPoIs.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import javascript
66
import experimental.poi.PoI
77
import DataFlow
88

9-
class RouteHandlerPoI extends PoI {
9+
class RouteHandlerPoI extends DefaultEnabledPoI {
1010
RouteHandlerPoI() { this = "RouteHandlerPoI" }
1111

1212
override predicate is(Node l0) { l0 instanceof Express::RouteHandler }
1313
}
1414

15-
class RouteHandlerAndSetupPoI extends PoI {
15+
class RouteHandlerAndSetupPoI extends DefaultEnabledPoI {
1616
RouteHandlerAndSetupPoI() { this = "RouteHandlerAndSetupPoI" }
1717

1818
override predicate is(Node l0, Node l1, string t1) {
1919
l1.asExpr().(Express::RouteSetup).getARouteHandler() = l0 and t1 = "setup"
2020
}
2121
}
2222

23-
class RouteSetupAndRouterAndRouteHandlerPoI extends PoI {
23+
class RouteSetupAndRouterAndRouteHandlerPoI extends DefaultEnabledPoI {
2424
RouteSetupAndRouterAndRouteHandlerPoI() { this = "RouteSetupAndRouterAndRouteHandlerPoI" }
2525

2626
override predicate is(Node l0, Node l1, string t1, Node l2, string t2) {

0 commit comments

Comments
 (0)