Skip to content

Commit b33f760

Browse files
committed
Manage chain calls of extend.
1 parent a58c4eb commit b33f760

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,21 @@ module ClientRequest {
414414
}
415415
}
416416

417+
/**
418+
* Gets a reference to an instance of the `got` library, including instances
419+
* created through chained `extend` calls.
420+
*/
421+
private API::Node getAGotInstance() {
422+
result = [API::moduleImport("got"), getAGotInstance().getMember("extend").getReturn()]
423+
}
424+
417425
/**
418426
* A model of a URL request made using the `got` library.
419427
*/
420428
class GotUrlRequest extends ClientRequest::Range {
421429
GotUrlRequest() {
422430
exists(API::Node callee, API::Node got | this = callee.getACall() |
423-
got = [API::moduleImport("got"), API::moduleImport("got").getMember("extend").getReturn()] and
431+
got = getAGotInstance() and
424432
callee = [got, got.getMember(["stream", "get", "post", "put", "patch", "head", "delete"])]
425433
)
426434
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ function gotTests(url){
329329
got(undefined, undefined, Options({url})); // undefined is flagged, but should be url from options
330330

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

334334
got.paginate(url, {}); // not flagged
335335

336336
const jsonClient = got.extend({url: url});
337337
jsonClient.get(); // call flagged not the actual url flow
338338

339339
const jsonClient2 = got.extend({url: url}).extend({url: url});
340-
jsonClient2.get(); // not flagged
340+
jsonClient2.get(); // call flagged not the actual url flow
341341
}

0 commit comments

Comments
 (0)