@@ -414,20 +414,74 @@ module ClientRequest {
414
414
}
415
415
}
416
416
417
+ /**
418
+ * Represents an instance of the `got` HTTP client library.
419
+ */
420
+ abstract private class GotInstance extends API:: Node {
421
+ /**
422
+ * Gets the options object associated with this instance of `got`.
423
+ */
424
+ API:: Node getOptions ( ) { none ( ) }
425
+ }
426
+
427
+ /**
428
+ * Represents the root `got` module import.
429
+ * For example: `const got = require('got')`.
430
+ */
431
+ private class RootGotInstance extends GotInstance {
432
+ RootGotInstance ( ) { this = API:: moduleImport ( "got" ) }
433
+ }
434
+
435
+ /**
436
+ * Represents an instance of `got` created by calling the `extend()` method.
437
+ * It may also be chained with multiple calls to `extend()`.
438
+ *
439
+ * For example: `const client = got.extend({ prefixUrl: 'https://example.com' })`.
440
+ */
441
+ private class ExtendGotInstance extends GotInstance {
442
+ private GotInstance base ;
443
+ private API:: CallNode extendCall ;
444
+
445
+ ExtendGotInstance ( ) {
446
+ extendCall = base .getMember ( "extend" ) .getACall ( ) and
447
+ this = extendCall .getReturn ( )
448
+ }
449
+
450
+ override API:: Node getOptions ( ) {
451
+ result = extendCall .getParameter ( 0 ) or result = base .getOptions ( )
452
+ }
453
+ }
454
+
417
455
/**
418
456
* A model of a URL request made using the `got` library.
419
457
*/
420
458
class GotUrlRequest extends ClientRequest:: Range {
459
+ GotInstance got ;
460
+
421
461
GotUrlRequest ( ) {
422
- exists ( API:: Node callee , API:: Node got | this = callee .getACall ( ) |
423
- got = [ API:: moduleImport ( "got" ) , API:: moduleImport ( "got" ) .getMember ( "extend" ) .getReturn ( ) ] and
424
- callee = [ got , got .getMember ( [ "stream" , "get" , "post" , "put" , "patch" , "head" , "delete" ] ) ]
462
+ exists ( API:: Node callee | this = callee .getACall ( ) |
463
+ callee =
464
+ [
465
+ got ,
466
+ got .getMember ( [ "stream" , "get" , "post" , "put" , "patch" , "head" , "delete" , "paginate" ] )
467
+ ]
425
468
)
426
469
}
427
470
428
471
override DataFlow:: Node getUrl ( ) {
429
472
result = this .getArgument ( 0 ) and
430
473
not exists ( this .getOptionArgument ( 1 , "baseUrl" ) )
474
+ or
475
+ // Handle URL from options passed to extend()
476
+ result = got .getOptions ( ) .getMember ( "url" ) .asSink ( ) and
477
+ not exists ( this .getArgument ( 0 ) )
478
+ or
479
+ // Handle URL from options passed as third argument when first arg is undefined/missing
480
+ exists ( API:: InvokeNode optionsCall |
481
+ optionsCall = API:: moduleImport ( "got" ) .getMember ( "Options" ) .getAnInvocation ( ) and
482
+ optionsCall .getReturn ( ) .getAValueReachableFromSource ( ) = this .getAnArgument ( ) and
483
+ result = optionsCall .getParameter ( 0 ) .getMember ( "url" ) .asSink ( )
484
+ )
431
485
}
432
486
433
487
override DataFlow:: Node getHost ( ) {
0 commit comments