Skip to content

Commit eb04915

Browse files
authored
Merge pull request github#6009 from erik-krogh/whatwg-fetch
Approved by esbena
2 parents f21e949 + 46f9000 commit eb04915

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lgtm,codescanning
2+
* URIs used in the [whatwg-fetch](https://www.npmjs.com/package/whatwg-fetch) library are now recognized as sinks for `js/request-forgery`.
3+
Affected packages are
4+
[whatwg-fetch](https://www.npmjs.com/package/whatwg-fetch)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ module ClientRequest {
302302
exists(DataFlow::SourceNode fetch |
303303
fetch = DataFlow::moduleImport(["node-fetch", "cross-fetch", "isomorphic-fetch"])
304304
or
305+
fetch = DataFlow::moduleMember("whatwg-fetch", "fetch")
306+
or
305307
fetch = DataFlow::globalVarRef("fetch") // https://fetch.spec.whatwg.org/#fetch-api
306308
|
307309
this = fetch.getACall() and

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ test_ClientRequest
8888
| tst.js:274:1:283:2 | httpPro ... true\\n}) |
8989
| tst.js:286:20:286:55 | new Web ... :8080') |
9090
| tst.js:296:5:299:6 | axios({ ... \\n }) |
91+
| tst.js:312:12:312:36 | fetchPo ... o/bar') |
9192
test_getADataNode
9293
| tst.js:53:5:53:23 | axios({data: data}) | tst.js:53:18:53:21 | data |
9394
| tst.js:57:5:57:39 | axios.p ... data2}) | tst.js:57:19:57:23 | data1 |
@@ -230,6 +231,7 @@ test_getUrl
230231
| tst.js:286:20:286:55 | new Web ... :8080') | tst.js:286:34:286:54 | 'ws://l ... t:8080' |
231232
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:296:11:299:5 | {\\n ... ,\\n } |
232233
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:298:14:298:44 | "http:/ ... -axios" |
234+
| tst.js:312:12:312:36 | fetchPo ... o/bar') | tst.js:312:26:312:35 | '/foo/bar' |
233235
test_getAResponseDataNode
234236
| tst.js:19:5:19:23 | requestPromise(url) | tst.js:19:5:19:23 | requestPromise(url) | text | true |
235237
| tst.js:21:5:21:23 | superagent.get(url) | tst.js:21:5:21:23 | superagent.get(url) | stream | true |
@@ -301,3 +303,4 @@ test_getAResponseDataNode
301303
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:302:28:302:39 | err.response | json | false |
302304
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:303:26:303:37 | err.response | json | false |
303305
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:304:27:304:38 | err.response | json | false |
306+
| tst.js:312:12:312:36 | fetchPo ... o/bar') | tst.js:312:12:312:36 | fetchPo ... o/bar') | fetch.response | true |

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,13 @@ function moreAxios() {
304304
const agent = err.response.headers.useragent;
305305
}
306306
);
307-
}
307+
}
308+
309+
import { fetch as fetchPolyfill } from 'whatwg-fetch'
310+
311+
function usePolyfill() {
312+
return fetchPolyfill('/foo/bar')
313+
.then(function (response) {
314+
return response.text()
315+
})
316+
}

0 commit comments

Comments
 (0)