Skip to content

Commit 2983b08

Browse files
committed
Enhance SuperAgent URL request handling for both method calls and direct calls
1 parent 77ce0b9 commit 2983b08

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,16 @@ module ClientRequest {
522522
SuperAgentUrlRequest() {
523523
exists(string moduleName, DataFlow::SourceNode callee | this = callee.getACall() |
524524
moduleName = "superagent" and
525-
callee = DataFlow::moduleMember(moduleName, httpMethodName()) and
526-
url = this.getArgument(0)
525+
(
526+
// Handle method calls like superagent.get(url)
527+
callee = DataFlow::moduleMember(moduleName, httpMethodName()) and
528+
url = this.getArgument(0)
529+
or
530+
// Handle direct calls like superagent('GET', url)
531+
callee = DataFlow::moduleImport(moduleName) and
532+
this.getArgument(0).mayHaveStringValue([httpMethodName().toUpperCase(), httpMethodName()]) and
533+
url = this.getArgument(1)
534+
)
527535
)
528536
}
529537

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ test_ClientRequest
9191
| tst.js:286:20:286:55 | new Web ... :8080') |
9292
| tst.js:296:5:299:6 | axios({ ... \\n }) |
9393
| tst.js:312:12:312:36 | fetchPo ... o/bar') |
94+
| tst.js:319:5:319:26 | superag ... ', url) |
9495
| tst.js:320:5:320:23 | superagent.del(url) |
9596
test_getADataNode
9697
| axiosTest.js:12:5:17:6 | axios({ ... \\n }) | axiosTest.js:15:18:15:55 | { 'Cont ... json' } |
@@ -241,6 +242,7 @@ test_getUrl
241242
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:296:11:299:5 | {\\n ... ,\\n } |
242243
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:298:14:298:44 | "http:/ ... -axios" |
243244
| tst.js:312:12:312:36 | fetchPo ... o/bar') | tst.js:312:26:312:35 | '/foo/bar' |
245+
| tst.js:319:5:319:26 | superag ... ', url) | tst.js:319:23:319:25 | url |
244246
| tst.js:320:5:320:23 | superagent.del(url) | tst.js:320:20:320:22 | url |
245247
test_getAResponseDataNode
246248
| axiosTest.js:4:5:7:6 | axios({ ... \\n }) | axiosTest.js:4:5:7:6 | axios({ ... \\n }) | json | true |
@@ -316,4 +318,5 @@ test_getAResponseDataNode
316318
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:303:26:303:37 | err.response | json | false |
317319
| tst.js:296:5:299:6 | axios({ ... \\n }) | tst.js:304:27:304:38 | err.response | json | false |
318320
| tst.js:312:12:312:36 | fetchPo ... o/bar') | tst.js:312:12:312:36 | fetchPo ... o/bar') | fetch.response | true |
321+
| tst.js:319:5:319:26 | superag ... ', url) | tst.js:319:5:319:26 | superag ... ', url) | stream | true |
319322
| tst.js:320:5:320:23 | superagent.del(url) | tst.js:320:5:320:23 | superagent.del(url) | stream | true |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function usePolyfill() {
316316
}
317317

318318
function useSuperagent(url){
319-
superagent('GET', url); // Not flagged
319+
superagent('GET', url);
320320
superagent.del(url);
321321
superagent.agent().post(url).send(data); // Not flagged
322322
}

0 commit comments

Comments
 (0)