Skip to content

Commit f8b3c27

Browse files
author
Stephan Brandauer
committed
add documentations and rename a feature
1 parent 3422bde commit f8b3c27

2 files changed

Lines changed: 47 additions & 25 deletions

File tree

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ private newtype TEndpointFeature =
235235
TCalleeFlexibleAccessPath() or
236236
TInputAccessPathFromCallee() or
237237
TInputArgumentIndex() or
238-
TContextFunctionInterfacesInFile() or
239-
TContextSurroundingFunctionParametersInFile()
238+
TContextFunctionInterfaces() or
239+
TContextSurroundingFunctionParameters()
240240

241241
/**
242242
* An implementation of an endpoint feature: produces feature names and values for used in ML.
@@ -444,10 +444,20 @@ class FileImports extends EndpointFeature, TFileImports {
444444

445445
/**
446446
* The feature for the function parameters of the functions that enclose an endpoint.
447+
*
448+
* ### Example
449+
* ```javascript
450+
* function f(a, b) {
451+
* // ...
452+
* const g = (c, d) => x.foo(endpoint);
453+
* // ^^^^^^^^
454+
* }
455+
* ```
456+
* In the above example, the feature for the marked endpoint has value '(a, b)\n(c, d)'.
447457
*/
448-
class ContextSurroundingFunctionParametersInFile extends EndpointFeature,
449-
TContextSurroundingFunctionParametersInFile {
450-
override string getName() { result = "contextSurroundingFunctionParametersInFile" }
458+
class ContextSurroundingFunctionParameters extends EndpointFeature,
459+
TContextSurroundingFunctionParameters {
460+
override string getName() { result = "contextSurroundingFunctionParameters" }
451461

452462
Function getRelevantFunction(DataFlow::Node endpoint) {
453463
result = endpoint.asExpr().getEnclosingFunction*()
@@ -501,12 +511,24 @@ class CalleeImports extends EndpointFeature, TCalleeImports {
501511
}
502512
}
503513

504-
/*
514+
/**
505515
* The feature for the interfaces of all named functions in the same file as the endpoint.
516+
*
517+
* ### Example
518+
* ```javascript
519+
* // Will return: "f(a, b, c)\ng(x, y, z)\nh(u, v)" for this file.
520+
* function f(a, b, c) { ... }
521+
*
522+
* function g(x, y, z) {
523+
* function h(u, v) { ... }
524+
* ...
525+
* }
526+
* ```
527+
*
528+
* The feature value for the marked endpoint will be `f(a, b, c)\ng(x, y, z)\nh(u, v)`.
506529
*/
507-
508-
class ContextFunctionInterfacesInFile extends EndpointFeature, TContextFunctionInterfacesInFile {
509-
override string getName() { result = "contextFunctionInterfacesInFile" }
530+
class ContextFunctionInterfaces extends EndpointFeature, TContextFunctionInterfaces {
531+
override string getName() { result = "contextFunctionInterfaces" }
510532

511533
override string getValue(DataFlow::Node endpoint) {
512534
result = SyntacticUtilities::getFunctionInterfacesForFile(endpoint.getFile())

javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/FeatureValue.expected

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| test.html:2:61:2:68 | endpoint | calleeAccessPathWithStructuralInfo | |
66
| test.html:2:61:2:68 | endpoint | calleeName | item |
77
| test.html:2:61:2:68 | endpoint | contextFunctionInterfacesInFile | |
8-
| test.html:2:61:2:68 | endpoint | contextSurroundingFunctionParametersInFile | |
8+
| test.html:2:61:2:68 | endpoint | contextSurroundingFunctionParameters | |
99
| test.html:2:61:2:68 | endpoint | fileImports | |
1010
| test.js:6:7:6:14 | endpoint | CalleeFlexibleAccessPath | f |
1111
| test.js:6:7:6:14 | endpoint | InputArgumentIndex | 0 |
@@ -16,7 +16,7 @@
1616
| test.js:6:7:6:14 | endpoint | calleeImports | ? lib3 |
1717
| test.js:6:7:6:14 | endpoint | calleeName | f |
1818
| test.js:6:7:6:14 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
19-
| test.js:6:7:6:14 | endpoint | contextSurroundingFunctionParametersInFile | () |
19+
| test.js:6:7:6:14 | endpoint | contextSurroundingFunctionParameters | () |
2020
| test.js:6:7:6:14 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
2121
| test.js:6:7:6:14 | endpoint | enclosingFunctionName | |
2222
| test.js:6:7:6:14 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -27,7 +27,7 @@
2727
| test.js:7:11:7:18 | endpoint | calleeAccessPathWithStructuralInfo | |
2828
| test.js:7:11:7:18 | endpoint | calleeImports | ? lib3 |
2929
| test.js:7:11:7:18 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
30-
| test.js:7:11:7:18 | endpoint | contextSurroundingFunctionParametersInFile | () |
30+
| test.js:7:11:7:18 | endpoint | contextSurroundingFunctionParameters | () |
3131
| test.js:7:11:7:18 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
3232
| test.js:7:11:7:18 | endpoint | enclosingFunctionName | |
3333
| test.js:7:11:7:18 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -38,7 +38,7 @@
3838
| test.js:8:15:8:22 | endpoint | calleeAccessPathWithStructuralInfo | |
3939
| test.js:8:15:8:22 | endpoint | calleeImports | ? lib3 |
4040
| test.js:8:15:8:22 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
41-
| test.js:8:15:8:22 | endpoint | contextSurroundingFunctionParametersInFile | () |
41+
| test.js:8:15:8:22 | endpoint | contextSurroundingFunctionParameters | () |
4242
| test.js:8:15:8:22 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
4343
| test.js:8:15:8:22 | endpoint | enclosingFunctionName | |
4444
| test.js:8:15:8:22 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -51,7 +51,7 @@
5151
| test.js:9:9:9:16 | endpoint | calleeImports | ? lib2 |
5252
| test.js:9:9:9:16 | endpoint | calleeName | m |
5353
| test.js:9:9:9:16 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
54-
| test.js:9:9:9:16 | endpoint | contextSurroundingFunctionParametersInFile | () |
54+
| test.js:9:9:9:16 | endpoint | contextSurroundingFunctionParameters | () |
5555
| test.js:9:9:9:16 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
5656
| test.js:9:9:9:16 | endpoint | enclosingFunctionName | |
5757
| test.js:9:9:9:16 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -63,7 +63,7 @@
6363
| test.js:10:13:10:20 | endpoint | calleeAccessPathWithStructuralInfo | |
6464
| test.js:10:13:10:20 | endpoint | calleeImports | ? lib2 |
6565
| test.js:10:13:10:20 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
66-
| test.js:10:13:10:20 | endpoint | contextSurroundingFunctionParametersInFile | () |
66+
| test.js:10:13:10:20 | endpoint | contextSurroundingFunctionParameters | () |
6767
| test.js:10:13:10:20 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
6868
| test.js:10:13:10:20 | endpoint | enclosingFunctionName | |
6969
| test.js:10:13:10:20 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -74,7 +74,7 @@
7474
| test.js:11:17:11:24 | endpoint | calleeAccessPathWithStructuralInfo | |
7575
| test.js:11:17:11:24 | endpoint | calleeImports | ? lib2 |
7676
| test.js:11:17:11:24 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
77-
| test.js:11:17:11:24 | endpoint | contextSurroundingFunctionParametersInFile | () |
77+
| test.js:11:17:11:24 | endpoint | contextSurroundingFunctionParameters | () |
7878
| test.js:11:17:11:24 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
7979
| test.js:11:17:11:24 | endpoint | enclosingFunctionName | |
8080
| test.js:11:17:11:24 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -84,7 +84,7 @@
8484
| test.js:12:11:12:18 | endpoint | calleeAccessPathWithStructuralInfo | |
8585
| test.js:12:11:12:18 | endpoint | calleeImports | lib1 |
8686
| test.js:12:11:12:18 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
87-
| test.js:12:11:12:18 | endpoint | contextSurroundingFunctionParametersInFile | () |
87+
| test.js:12:11:12:18 | endpoint | contextSurroundingFunctionParameters | () |
8888
| test.js:12:11:12:18 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
8989
| test.js:12:11:12:18 | endpoint | enclosingFunctionName | |
9090
| test.js:12:11:12:18 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -97,7 +97,7 @@
9797
| test.js:13:17:13:24 | endpoint | calleeImports | ? lib2 |
9898
| test.js:13:17:13:24 | endpoint | calleeName | m |
9999
| test.js:13:17:13:24 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
100-
| test.js:13:17:13:24 | endpoint | contextSurroundingFunctionParametersInFile | () |
100+
| test.js:13:17:13:24 | endpoint | contextSurroundingFunctionParameters | () |
101101
| test.js:13:17:13:24 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
102102
| test.js:13:17:13:24 | endpoint | enclosingFunctionName | |
103103
| test.js:13:17:13:24 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -109,7 +109,7 @@
109109
| test.js:14:9:14:16 | endpoint | calleeApiName | lib3 |
110110
| test.js:14:9:14:16 | endpoint | calleeImports | ? lib3 |
111111
| test.js:14:9:14:16 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
112-
| test.js:14:9:14:16 | endpoint | contextSurroundingFunctionParametersInFile | () |
112+
| test.js:14:9:14:16 | endpoint | contextSurroundingFunctionParameters | () |
113113
| test.js:14:9:14:16 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
114114
| test.js:14:9:14:16 | endpoint | enclosingFunctionName | |
115115
| test.js:14:9:14:16 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -122,7 +122,7 @@
122122
| test.js:15:12:15:19 | endpoint | calleeImports | ? lib2 |
123123
| test.js:15:12:15:19 | endpoint | calleeName | m |
124124
| test.js:15:12:15:19 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
125-
| test.js:15:12:15:19 | endpoint | contextSurroundingFunctionParametersInFile | () |
125+
| test.js:15:12:15:19 | endpoint | contextSurroundingFunctionParameters | () |
126126
| test.js:15:12:15:19 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
127127
| test.js:15:12:15:19 | endpoint | enclosingFunctionName | |
128128
| test.js:15:12:15:19 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -135,7 +135,7 @@
135135
| test.js:16:16:16:23 | endpoint | calleeImports | ? lib2 |
136136
| test.js:16:16:16:23 | endpoint | calleeName | m |
137137
| test.js:16:16:16:23 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
138-
| test.js:16:16:16:23 | endpoint | contextSurroundingFunctionParametersInFile | () |
138+
| test.js:16:16:16:23 | endpoint | contextSurroundingFunctionParameters | () |
139139
| test.js:16:16:16:23 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
140140
| test.js:16:16:16:23 | endpoint | enclosingFunctionName | |
141141
| test.js:16:16:16:23 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -147,7 +147,7 @@
147147
| test.js:17:15:17:22 | endpoint | calleeApiName | lib1 |
148148
| test.js:17:15:17:22 | endpoint | calleeImports | lib1 |
149149
| test.js:17:15:17:22 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
150-
| test.js:17:15:17:22 | endpoint | contextSurroundingFunctionParametersInFile | () |
150+
| test.js:17:15:17:22 | endpoint | contextSurroundingFunctionParameters | () |
151151
| test.js:17:15:17:22 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
152152
| test.js:17:15:17:22 | endpoint | enclosingFunctionName | |
153153
| test.js:17:15:17:22 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -160,7 +160,7 @@
160160
| test.js:18:27:18:34 | endpoint | calleeImports | foo |
161161
| test.js:18:27:18:34 | endpoint | calleeName | baz |
162162
| test.js:18:27:18:34 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
163-
| test.js:18:27:18:34 | endpoint | contextSurroundingFunctionParametersInFile | () |
163+
| test.js:18:27:18:34 | endpoint | contextSurroundingFunctionParameters | () |
164164
| test.js:18:27:18:34 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
165165
| test.js:18:27:18:34 | endpoint | enclosingFunctionName | |
166166
| test.js:18:27:18:34 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -173,7 +173,7 @@
173173
| test.js:20:13:20:20 | endpoint | calleeImports | lib1 |
174174
| test.js:20:13:20:20 | endpoint | calleeName | bar |
175175
| test.js:20:13:20:20 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
176-
| test.js:20:13:20:20 | endpoint | contextSurroundingFunctionParametersInFile | () |
176+
| test.js:20:13:20:20 | endpoint | contextSurroundingFunctionParameters | () |
177177
| test.js:20:13:20:20 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
178178
| test.js:20:13:20:20 | endpoint | enclosingFunctionName | |
179179
| test.js:20:13:20:20 | endpoint | fileImports | foo lib1 lib2 lib3 |
@@ -184,7 +184,7 @@
184184
| test.js:22:21:22:28 | endpoint | calleeApiName | lib3 |
185185
| test.js:22:21:22:28 | endpoint | calleeImports | ? lib2 lib3 |
186186
| test.js:22:21:22:28 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() |
187-
| test.js:22:21:22:28 | endpoint | contextSurroundingFunctionParametersInFile | () |
187+
| test.js:22:21:22:28 | endpoint | contextSurroundingFunctionParameters | () |
188188
| test.js:22:21:22:28 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint |
189189
| test.js:22:21:22:28 | endpoint | enclosingFunctionName | |
190190
| test.js:22:21:22:28 | endpoint | fileImports | foo lib1 lib2 lib3 |

0 commit comments

Comments
 (0)