Skip to content

Commit 0b733b4

Browse files
author
Esben Sparre Andreasen
committed
JS: treat the last argument to https.createServer as a route handler
1 parent 54b4e59 commit 0b733b4

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

change-notes/1.21/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Support for the following frameworks and libraries has been improved:
66
- [socket.io](http://socket.io)
7+
- [Node.js](http://nodejs.org)
78

89
* The security queries now track data flow through Base64 decoders such as the Node.js `Buffer` class, the DOM function `atob`, and a number of npm packages intcluding [`abab`](https://www.npmjs.com/package/abab), [`atob`](https://www.npmjs.com/package/atob), [`btoa`](https://www.npmjs.com/package/btoa), [`base-64`](https://www.npmjs.com/package/base-64), [`js-base64`](https://www.npmjs.com/package/js-base64), [`Base64.js`](https://www.npmjs.com/package/Base64) and [`base64-js`](https://www.npmjs.com/package/base64-js).
910

javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module NodeJSLib {
180180

181181
RouteSetup() {
182182
server.flowsTo(this) and
183-
handler = getArgument(0)
183+
handler = getLastArgument()
184184
or
185185
server.flowsTo(getReceiver()) and
186186
this.(MethodCallExpr).getMethodName().regexpMatch("on(ce)?") and
@@ -663,7 +663,7 @@ module NodeJSLib {
663663

664664
RouteSetupCandidate() {
665665
getMethodName() = "createServer" and
666-
arg = getArgument(0)
666+
arg = getLastArgument()
667667
or
668668
getMethodName().regexpMatch("on(ce)?") and
669669
getArgument(0).mayHaveStringValue("request") and
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var https = require('https');
2+
https.createServer(function (req, res) {});
3+
https.createServer(o, function (req, res) {});

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
test_isCreateServer
2+
| createServer.js:2:1:2:42 | https.c ... es) {}) |
3+
| createServer.js:3:1:3:45 | https.c ... es) {}) |
24
| src/http.js:4:14:10:2 | http.cr ... foo;\\n}) |
35
| src/http.js:12:1:16:2 | http.cr ... r");\\n}) |
46
| src/http.js:57:1:57:31 | http.cr ... dler()) |
@@ -47,6 +49,8 @@ test_HeaderDefinition
4749
| src/https.js:7:3:7:42 | res.wri ... rget }) | src/https.js:4:33:10:1 | functio ... .foo;\\n} |
4850
| src/https.js:13:3:13:44 | res.set ... /html') | src/https.js:12:20:16:1 | functio ... ar");\\n} |
4951
test_RouteSetup_getServer
52+
| createServer.js:2:1:2:42 | https.c ... es) {}) | createServer.js:2:1:2:42 | https.c ... es) {}) |
53+
| createServer.js:3:1:3:45 | https.c ... es) {}) | createServer.js:3:1:3:45 | https.c ... es) {}) |
5054
| src/http.js:4:14:10:2 | http.cr ... foo;\\n}) | src/http.js:4:14:10:2 | http.cr ... foo;\\n}) |
5155
| src/http.js:12:1:16:2 | http.cr ... r");\\n}) | src/http.js:12:1:16:2 | http.cr ... r");\\n}) |
5256
| src/http.js:57:1:57:31 | http.cr ... dler()) | src/http.js:57:1:57:31 | http.cr ... dler()) |
@@ -66,6 +70,8 @@ test_HeaderDefinition_getAHeaderName
6670
| src/https.js:7:3:7:42 | res.wri ... rget }) | location |
6771
| src/https.js:13:3:13:44 | res.set ... /html') | content-type |
6872
test_ServerDefinition
73+
| createServer.js:2:1:2:42 | https.c ... es) {}) |
74+
| createServer.js:3:1:3:45 | https.c ... es) {}) |
6975
| src/http.js:4:14:10:2 | http.cr ... foo;\\n}) |
7076
| src/http.js:12:1:16:2 | http.cr ... r");\\n}) |
7177
| src/http.js:57:1:57:31 | http.cr ... dler()) |
@@ -95,6 +101,8 @@ test_RouteHandler_getAResponseExpr
95101
| src/https.js:12:20:16:1 | functio ... ar");\\n} | src/https.js:14:3:14:5 | res |
96102
| src/https.js:12:20:16:1 | functio ... ar");\\n} | src/https.js:15:3:15:5 | res |
97103
test_ServerDefinition_getARouteHandler
104+
| createServer.js:2:1:2:42 | https.c ... es) {}) | createServer.js:2:20:2:41 | functio ... res) {} |
105+
| createServer.js:3:1:3:45 | https.c ... es) {}) | createServer.js:3:23:3:44 | functio ... res) {} |
98106
| src/http.js:4:14:10:2 | http.cr ... foo;\\n}) | src/http.js:4:32:10:1 | functio ... .foo;\\n} |
99107
| src/http.js:12:1:16:2 | http.cr ... r");\\n}) | src/http.js:12:19:16:1 | functio ... ar");\\n} |
100108
| src/http.js:57:1:57:31 | http.cr ... dler()) | src/http.js:55:12:55:30 | function(req,res){} |
@@ -110,6 +118,8 @@ test_ResponseSendArgument
110118
| src/https.js:14:13:14:17 | "foo" | src/https.js:12:20:16:1 | functio ... ar");\\n} |
111119
| src/https.js:15:11:15:15 | "bar" | src/https.js:12:20:16:1 | functio ... ar");\\n} |
112120
test_RouteSetup_getARouteHandler
121+
| createServer.js:2:1:2:42 | https.c ... es) {}) | createServer.js:2:20:2:41 | functio ... res) {} |
122+
| createServer.js:3:1:3:45 | https.c ... es) {}) | createServer.js:3:23:3:44 | functio ... res) {} |
113123
| src/http.js:4:14:10:2 | http.cr ... foo;\\n}) | src/http.js:4:32:10:1 | functio ... .foo;\\n} |
114124
| src/http.js:12:1:16:2 | http.cr ... r");\\n}) | src/http.js:12:19:16:1 | functio ... ar");\\n} |
115125
| src/http.js:57:1:57:31 | http.cr ... dler()) | src/http.js:55:12:55:30 | function(req,res){} |
@@ -137,6 +147,8 @@ test_RemoteFlowSources
137147
| src/https.js:8:3:8:20 | req.headers.cookie |
138148
| src/https.js:9:3:9:17 | req.headers.foo |
139149
test_RouteHandler
150+
| createServer.js:2:20:2:41 | functio ... res) {} | createServer.js:2:1:2:42 | https.c ... es) {}) |
151+
| createServer.js:3:23:3:44 | functio ... res) {} | createServer.js:3:1:3:45 | https.c ... es) {}) |
140152
| src/http.js:4:32:10:1 | functio ... .foo;\\n} | src/http.js:4:14:10:2 | http.cr ... foo;\\n}) |
141153
| src/http.js:12:19:16:1 | functio ... ar");\\n} | src/http.js:12:1:16:2 | http.cr ... r");\\n}) |
142154
| src/http.js:55:12:55:30 | function(req,res){} | src/http.js:57:1:57:31 | http.cr ... dler()) |

0 commit comments

Comments
 (0)