Skip to content

Commit cdf4f53

Browse files
committed
Enhance SuperAgent URL request handling for both method calls and direct calls
1 parent 2e1734e commit cdf4f53

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
@@ -529,8 +529,16 @@ module ClientRequest {
529529
SuperAgentUrlRequest() {
530530
exists(string moduleName, DataFlow::SourceNode callee | this = callee.getACall() |
531531
moduleName = "superagent" and
532-
callee = DataFlow::moduleMember(moduleName, getSuperagentRequestMethodName()) and
533-
url = this.getArgument(0)
532+
(
533+
// Handle method calls like superagent.get(url)
534+
callee = DataFlow::moduleMember(moduleName, getSuperagentRequestMethodName()) and
535+
url = this.getArgument(0)
536+
or
537+
// Handle direct calls like superagent('GET', url)
538+
callee = DataFlow::moduleImport(moduleName) and
539+
this.getArgument(0).mayHaveStringValue(getSuperagentRequestMethodName()) and
540+
url = this.getArgument(1)
541+
)
534542
)
535543
}
536544

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)