Skip to content

Commit 99efb61

Browse files
committed
Enhance URL handling in ClientRequest for got Options
1 parent b33f760 commit 99efb61

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ module ClientRequest {
436436
override DataFlow::Node getUrl() {
437437
result = this.getArgument(0) and
438438
not exists(this.getOptionArgument(1, "baseUrl"))
439+
or
440+
// Handle URL when passed as options
441+
exists(API::InvokeNode optionsCall |
442+
optionsCall = API::moduleImport("got").getMember("Options").getAnInvocation() and
443+
optionsCall.getReturn().getAValueReachableFromSource() = this.getAnArgument() and
444+
result = optionsCall.getParameter(0).getMember("url").asSink()
445+
)
439446
}
440447

441448
override DataFlow::Node getHost() {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ test_ClientRequest
9999
| tst.js:321:5:321:32 | superag ... st(url) |
100100
| tst.js:328:5:328:38 | got(und ... ptions) |
101101
| tst.js:329:5:329:45 | got(und ... {url})) |
102+
| tst.js:332:5:332:46 | got.ext ... ).get() |
102103
| tst.js:337:5:337:20 | jsonClient.get() |
104+
| tst.js:340:5:340:21 | jsonClient2.get() |
103105
test_getADataNode
104106
| axiosTest.js:12:5:17:6 | axios({ ... \\n }) | axiosTest.js:15:18:15:55 | { 'Cont ... json' } |
105107
| axiosTest.js:12:5:17:6 | axios({ ... \\n }) | axiosTest.js:16:15:16:35 | {x: 'te ... 'test'} |
@@ -257,8 +259,10 @@ test_getUrl
257259
| tst.js:319:5:319:26 | superag ... ', url) | tst.js:319:23:319:25 | url |
258260
| tst.js:320:5:320:23 | superagent.del(url) | tst.js:320:20:320:22 | url |
259261
| tst.js:321:5:321:32 | superag ... st(url) | tst.js:321:29:321:31 | url |
262+
| tst.js:328:5:328:38 | got(und ... ptions) | tst.js:327:34:327:36 | url |
260263
| tst.js:328:5:328:38 | got(und ... ptions) | tst.js:328:9:328:17 | undefined |
261264
| tst.js:329:5:329:45 | got(und ... {url})) | tst.js:329:9:329:17 | undefined |
265+
| tst.js:329:5:329:45 | got(und ... {url})) | tst.js:329:40:329:42 | url |
262266
test_getAResponseDataNode
263267
| axiosTest.js:4:5:7:6 | axios({ ... \\n }) | axiosTest.js:4:5:7:6 | axios({ ... \\n }) | json | true |
264268
| axiosTest.js:12:5:17:6 | axios({ ... \\n }) | axiosTest.js:12:5:17:6 | axios({ ... \\n }) | json | true |
@@ -341,4 +345,6 @@ test_getAResponseDataNode
341345
| tst.js:321:5:321:32 | superag ... st(url) | tst.js:321:5:321:32 | superag ... st(url) | stream | true |
342346
| tst.js:328:5:328:38 | got(und ... ptions) | tst.js:328:5:328:38 | got(und ... ptions) | text | true |
343347
| tst.js:329:5:329:45 | got(und ... {url})) | tst.js:329:5:329:45 | got(und ... {url})) | text | true |
348+
| tst.js:332:5:332:46 | got.ext ... ).get() | tst.js:332:5:332:46 | got.ext ... ).get() | text | true |
344349
| tst.js:337:5:337:20 | jsonClient.get() | tst.js:337:5:337:20 | jsonClient.get() | text | true |
350+
| tst.js:340:5:340:21 | jsonClient2.get() | tst.js:340:5:340:21 | jsonClient2.get() | text | true |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ import { Options } from 'got';
325325

326326
function gotTests(url){
327327
const options = new Options({url});
328-
got(undefined, undefined, options); // undefined is flagged, but should be url from options
329-
got(undefined, undefined, Options({url})); // undefined is flagged, but should be url from options
328+
got(undefined, undefined, options);
329+
got(undefined, undefined, Options({url}));
330330

331331
const options2 = new Options({url});
332332
got.extend(options2).extend(options).get(); // call flagged not the actual url flow

0 commit comments

Comments
 (0)