Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c21a047

Browse files
author
Esben Sparre Andreasen
committed
JS: implement getADataNode for AxiosUrlRequest
1 parent 1e115bc commit c21a047

6 files changed

Lines changed: 43 additions & 11 deletions

File tree

javascript/ql/src/semmle/javascript/frameworks/ClientRequests.qll

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,36 @@ private class RequestUrlRequest extends CustomClientRequest {
116116
*/
117117
private class AxiosUrlRequest extends CustomClientRequest {
118118

119-
DataFlow::Node url;
119+
string method;
120120

121121
AxiosUrlRequest() {
122122
exists (string moduleName, DataFlow::SourceNode callee |
123123
this = callee.getACall() |
124124
moduleName = "axios" and
125125
(
126-
callee = DataFlow::moduleImport(moduleName) or
127-
callee = DataFlow::moduleMember(moduleName, httpMethodName()) or
128-
callee = DataFlow::moduleMember(moduleName, "request")
129-
) and
130-
(
131-
url = getArgument(0) or
132-
// depends on the method name and the call arity, over-approximating slightly in the name of simplicity
133-
url = getOptionArgument([0..2], urlPropertyName())
126+
callee = DataFlow::moduleImport(moduleName) and method = "request" or
127+
callee = DataFlow::moduleMember(moduleName, method) and (method = httpMethodName() or method = "request")
134128
)
135129
)
136130
}
137131

138132
override DataFlow::Node getUrl() {
139-
result = url
133+
result = getArgument(0) or
134+
// depends on the method name and the call arity, over-approximating slightly in the name of simplicity
135+
result = getOptionArgument([0..2], urlPropertyName())
140136
}
141137

142138
override DataFlow::Node getADataNode() {
143-
none()
139+
method = "request" and
140+
result = getOptionArgument(0, "data")
141+
or
142+
(method = "post" or method = "put" or method = "put") and
143+
(result = getArgument(1) or result = getOptionArgument(2, "data"))
144+
or
145+
exists (string name |
146+
name = "headers" or name = "params"|
147+
result = getOptionArgument([0..2], name)
148+
)
144149
}
145150

146151
}

javascript/ql/test/library-tests/frameworks/ClientRequests/ClientRequest.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
| tst.js:41:5:41:29 | net.req ... url }) |
1717
| tst.js:43:5:43:26 | new Cli ... st(url) |
1818
| tst.js:45:5:45:35 | new Cli ... url }) |
19+
| tst.js:53:5:53:23 | axios({data: data}) |
20+
| tst.js:55:5:55:34 | axios.g ... _data}) |
21+
| tst.js:57:5:57:39 | axios.p ... data2}) |
22+
| tst.js:59:5:59:52 | axios({ ... sData}) |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| tst.js:53:5:53:23 | axios({data: data}) | tst.js:53:18:53:21 | data |
2+
| tst.js:57:5:57:39 | axios.p ... data2}) | tst.js:57:19:57:23 | data1 |
3+
| tst.js:57:5:57:39 | axios.p ... data2}) | tst.js:57:33:57:37 | data2 |
4+
| tst.js:59:5:59:52 | axios({ ... sData}) | tst.js:59:21:59:30 | headerData |
5+
| tst.js:59:5:59:52 | axios({ ... sData}) | tst.js:59:41:59:50 | paramsData |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from ClientRequest r
4+
select r, r.getADataNode()

javascript/ql/test/library-tests/frameworks/ClientRequests/ClientRequest_getUrl.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
| tst.js:43:5:43:26 | new Cli ... st(url) | tst.js:43:23:43:25 | url |
2121
| tst.js:45:5:45:35 | new Cli ... url }) | tst.js:45:23:45:34 | { url: url } |
2222
| tst.js:45:5:45:35 | new Cli ... url }) | tst.js:45:30:45:32 | url |
23+
| tst.js:53:5:53:23 | axios({data: data}) | tst.js:53:11:53:22 | {data: data} |
24+
| tst.js:55:5:55:34 | axios.g ... _data}) | tst.js:55:15:55:15 | x |
25+
| tst.js:57:5:57:39 | axios.p ... data2}) | tst.js:57:16:57:16 | x |
26+
| tst.js:59:5:59:52 | axios({ ... sData}) | tst.js:59:11:59:51 | {header ... msData} |

javascript/ql/test/library-tests/frameworks/ClientRequests/tst.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ import {ClientRequest, net} from 'electron';
4848

4949
unknown({ url:url });
5050
});
51+
52+
(function() {
53+
axios({data: data});
54+
55+
axios.get(x, {data: not_data});
56+
57+
axios.post(x, data1, {data: data2});
58+
59+
axios({headers: headerData, params: paramsData});
60+
});

0 commit comments

Comments
 (0)