Skip to content

Commit 7fec005

Browse files
author
Esben Sparre Andreasen
committed
JS: use DataFlow::SourceNode in three locations in Koa
1 parent 919eed6 commit 7fec005

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ module Koa {
202202
e instanceof ContextExpr and
203203
kind = "cookie" and
204204
cookies.accesses(e, "cookies") and
205-
this.asExpr().(MethodCallExpr).calls(cookies, "get")
205+
this = cookies.flow().(DataFlow::SourceNode).getAMethodCall("get")
206206
)
207207
or
208208
exists(RequestHeaderAccess access | access = this |
@@ -221,7 +221,10 @@ module Koa {
221221

222222
private DataFlow::Node getAQueryParameterAccess(RouteHandler rh) {
223223
// `ctx.query.name` or `ctx.request.query.name`
224-
result.asExpr().(PropAccess).getBase().(PropAccess).accesses(rh.getARequestOrContextExpr(), "query")
224+
exists (PropAccess q |
225+
q.accesses(rh.getARequestOrContextExpr(), "query") and
226+
result = q.flow().(DataFlow::SourceNode).getAPropertyRead()
227+
)
225228
}
226229

227230
/**
@@ -235,7 +238,7 @@ module Koa {
235238
exists(string propName, PropAccess headers |
236239
// `ctx.request.header.<name>`, `ctx.request.headers.<name>`
237240
headers.accesses(e, propName) and
238-
this.asExpr().(PropAccess).accesses(headers, _)
241+
this = headers.flow().(DataFlow::SourceNode).getAPropertyRead()
239242
|
240243
propName = "header" or
241244
propName = "headers"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ test_RequestInputAccess
2121
| src/koa.js:38:2:38:16 | ctx.headers.bar | header | src/koa.js:30:10:45:1 | async c ... url);\\n} |
2222
| src/koa.js:40:2:40:15 | ctx.get('bar') | header | src/koa.js:30:10:45:1 | async c ... url);\\n} |
2323
| src/koa.js:42:12:42:27 | ctx.query.target | parameter | src/koa.js:30:10:45:1 | async c ... url);\\n} |
24+
| src/koa.js:49:2:49:14 | cookies.get() | cookie | src/koa.js:47:10:56:1 | async c ... .foo;\\n} |
25+
| src/koa.js:52:2:52:10 | query.foo | parameter | src/koa.js:47:10:56:1 | async c ... .foo;\\n} |
26+
| src/koa.js:55:2:55:12 | headers.foo | header | src/koa.js:47:10:56:1 | async c ... .foo;\\n} |
2427
test_RouteHandler_getAResponseHeader
2528
| src/koa.js:10:10:28:1 | functio ... az');\\n} | header1 | src/koa.js:11:3:11:25 | this.se ... 1', '') |
2629
| src/koa.js:10:10:28:1 | functio ... az');\\n} | header2 | src/koa.js:12:3:12:37 | this.re ... 2', '') |
@@ -97,6 +100,7 @@ test_HeaderAccess
97100
| src/koa.js:37:2:37:15 | ctx.header.bar | bar |
98101
| src/koa.js:38:2:38:16 | ctx.headers.bar | bar |
99102
| src/koa.js:40:2:40:15 | ctx.get('bar') | bar |
103+
| src/koa.js:55:2:55:12 | headers.foo | foo |
100104
test_RouteHandler_getAResponseExpr
101105
| src/koa.js:10:10:28:1 | functio ... az');\\n} | src/koa.js:12:3:12:15 | this.response |
102106
| src/koa.js:10:10:28:1 | functio ... az');\\n} | src/koa.js:14:3:14:14 | ctx.response |

0 commit comments

Comments
 (0)