@@ -56,7 +56,7 @@ private string getTokenFeature(DataFlow::Node endpoint, string featureName) {
56
56
result =
57
57
concat ( API:: Node node , string accessPath |
58
58
node .getInducingNode ( ) .( DataFlow:: CallNode ) .getAnArgument ( ) = endpoint and
59
- accessPath = AccessPaths:: getAccessPath ( node , includeStructuralInfo )
59
+ AccessPaths:: accessPaths ( node , includeStructuralInfo , accessPath , _ )
60
60
|
61
61
accessPath , " "
62
62
)
@@ -102,7 +102,9 @@ private string getACallBasedTokenFeatureComponent(
102
102
//
103
103
// would have a callee API name of `mongoose`.
104
104
featureName = "calleeApiName" and
105
- result = getAnApiName ( call )
105
+ exists ( API:: Node apiNode |
106
+ AccessPaths:: accessPaths ( apiNode , false , _, result ) and call = apiNode .getInducingNode ( )
107
+ )
106
108
)
107
109
}
108
110
@@ -145,16 +147,6 @@ module FunctionBodies {
145
147
}
146
148
}
147
149
148
- /**
149
- * Returns a name of the API that a node originates from, if the node originates from an API.
150
- *
151
- * This predicate may have multiple results if the node corresponds to multiple nodes in the API graph forest.
152
- */
153
- pragma [ inline]
154
- private string getAnApiName ( DataFlow:: Node node ) {
155
- API:: moduleImport ( result ) .getASuccessor * ( ) .getInducingNode ( ) = node
156
- }
157
-
158
150
/**
159
151
* This module provides functionality for getting a representation of the access path of nodes
160
152
* within the program.
@@ -200,65 +192,72 @@ private module AccessPaths {
200
192
}
201
193
202
194
/** Get the access path for the node. This includes structural information like `member`, `param`, and `functionalarg` if `includeStructuralInfo` is true. */
203
- string getAccessPath ( API:: Node node , Boolean includeStructuralInfo ) {
204
- node = API:: moduleImport ( result )
195
+ predicate accessPaths (
196
+ API:: Node node , Boolean includeStructuralInfo , string accessPath , string apiName
197
+ ) {
198
+ //node = API::moduleImport(result)
199
+ node = API:: moduleImport ( apiName ) and accessPath = apiName
205
200
or
206
- exists ( API:: Node base , string baseName |
207
- base .getDepth ( ) < node .getDepth ( ) and baseName = getAccessPath ( base , includeStructuralInfo )
201
+ exists ( API:: Node previousNode , string previousAccessPath |
202
+ previousNode .getDepth ( ) < node .getDepth ( ) and
203
+ accessPaths ( previousNode , includeStructuralInfo , previousAccessPath , apiName )
208
204
|
209
205
// e.g. `new X`, `X()`
210
- node = [ base .getInstance ( ) , base .getReturn ( ) ] and
206
+ node = [ previousNode .getInstance ( ) , previousNode .getReturn ( ) ] and
211
207
if includeStructuralInfo = true
212
- then result = baseName + " instanceorreturn"
213
- else result = baseName
208
+ then accessPath = previousAccessPath + " instanceorreturn"
209
+ else accessPath = previousAccessPath
214
210
or
215
211
// e.g. `x.y`, `x[y]`, `const { y } = x`, where `y` is non-numeric and is known at analysis
216
212
// time.
217
213
exists ( string member |
218
- node = base .getMember ( member ) and
219
- not node = base .getUnknownMember ( ) and
214
+ node = previousNode .getMember ( member ) and
215
+ not node = previousNode .getUnknownMember ( ) and
220
216
not isNumericString ( member ) and
221
- not ( member = "default" and base = API:: moduleImport ( _) ) and
217
+ not ( member = "default" and previousNode = API:: moduleImport ( _) ) and
222
218
not member = "then" // use the 'promised' edges for .then callbacks
223
219
|
224
220
if includeStructuralInfo = true
225
- then result = baseName + " member " + member
226
- else result = baseName + " " + member
221
+ then accessPath = previousAccessPath + " member " + member
222
+ else accessPath = previousAccessPath + " " + member
227
223
)
228
224
or
229
225
// e.g. `x.y`, `x[y]`, `const { y } = x`, where `y` is numeric or not known at analysis time.
230
226
(
231
- node = base .getUnknownMember ( ) or
232
- node = base .getMember ( any ( string s | isNumericString ( s ) ) )
227
+ node = previousNode .getUnknownMember ( ) or
228
+ node = previousNode .getMember ( any ( string s | isNumericString ( s ) ) )
233
229
) and
234
- if includeStructuralInfo = true then result = baseName + " member" else result = baseName
230
+ if includeStructuralInfo = true
231
+ then accessPath = previousAccessPath + " member"
232
+ else accessPath = previousAccessPath
235
233
or
236
234
// e.g. `x.then(y => ...)`
237
- node = base .getPromised ( ) and
238
- result = baseName
235
+ node = previousNode .getPromised ( ) and
236
+ accessPath = previousAccessPath
239
237
or
240
238
// e.g. `x.y((a, b) => ...)`
241
239
// Name callback parameters after their name in the source code.
242
240
// For example, the `res` parameter in `express.get('/foo', (req, res) => {...})` will be
243
241
// named `express member get functionalarg param res`.
244
242
exists ( string paramName |
245
- node = getNamedParameter ( base .getAParameter ( ) , paramName ) and
243
+ node = getNamedParameter ( previousNode .getAParameter ( ) , paramName ) and
246
244
(
247
245
if includeStructuralInfo = true
248
- then result = baseName + " functionalarg param " + paramName
249
- else result = baseName + " " + paramName
246
+ then accessPath = previousAccessPath + " functionalarg param " + paramName
247
+ else accessPath = previousAccessPath + " " + paramName
250
248
)
251
249
or
252
250
exists ( string callbackName , string index |
253
251
node =
254
- getNamedParameter ( base .getASuccessor ( "param " + index ) .getMember ( callbackName ) ,
252
+ getNamedParameter ( previousNode .getASuccessor ( "param " + index ) .getMember ( callbackName ) ,
255
253
paramName ) and
256
254
index != "-1" and // ignore receiver
257
255
if includeStructuralInfo = true
258
256
then
259
- result =
260
- baseName + " functionalarg " + index + " " + callbackName + " param " + paramName
261
- else result = baseName + " " + index + " " + callbackName + " " + paramName
257
+ accessPath =
258
+ previousAccessPath + " functionalarg " + index + " " + callbackName + " param " +
259
+ paramName
260
+ else accessPath = previousAccessPath + " " + index + " " + callbackName + " " + paramName
262
261
)
263
262
)
264
263
)
0 commit comments