Skip to content

Commit 1b4fc93

Browse files
committed
JS: add HTTP::RequestInputAccess.getAHeaderName()
1 parent f7775f3 commit 1b4fc93

File tree

13 files changed

+71
-1
lines changed

13 files changed

+71
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,19 @@ module Express {
503503
override string getKind() {
504504
result = kind
505505
}
506+
507+
override string getAHeaderName() {
508+
kind = "header" and
509+
exists (string name |
510+
name = this.(DataFlow::PropRead).getPropertyName()
511+
or
512+
this.(DataFlow::CallNode).getArgument(0).mayHaveStringValue(name)
513+
|
514+
if name = "hostname" then
515+
result = "host"
516+
else
517+
result = name.toLowerCase())
518+
}
506519
}
507520

508521
/**

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,17 @@ module HTTP {
399399
* Note that this predicate is functional.
400400
*/
401401
abstract string getKind();
402+
403+
/**
404+
* Gets the lower-case name of an HTTP header from which this input is derived,
405+
* if this can be determined.
406+
*
407+
* When the input is not derived from a header, or the header name is
408+
* unknown, this has no result.
409+
*/
410+
string getAHeaderName() { none() }
402411
}
403-
412+
404413
/**
405414
* A node that looks like a route setup on a server.
406415
*

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ module Hapi {
144144
override string getKind() {
145145
result = kind
146146
}
147+
148+
override string getAHeaderName() {
149+
kind = "header" and
150+
result = this.(DataFlow::PropRead).getPropertyName().toLowerCase()
151+
}
147152
}
148153

149154
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ module Koa {
212212
override string getKind() {
213213
result = kind
214214
}
215+
216+
override string getAHeaderName() {
217+
kind = "header" and
218+
(
219+
result = this.(DataFlow::PropRead).getPropertyName().toLowerCase()
220+
or
221+
exists (string name |
222+
this.(DataFlow::CallNode).getArgument(0).mayHaveStringValue(name) and
223+
result = name.toLowerCase())
224+
)
225+
}
215226
}
216227

217228
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ module NodeJSLib {
161161
override string getKind() {
162162
result = kind
163163
}
164+
165+
override string getAHeaderName() {
166+
kind = "header" and
167+
result = this.(DataFlow::PropRead).getPropertyName().toLowerCase()
168+
}
164169
}
165170

166171
class RouteSetup extends CallExpr, HTTP::Servers::StandardRouteSetup {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| src/express.js:28:3:28:16 | req.get("foo") | foo |
2+
| src/express.js:29:3:29:19 | req.header("bar") | bar |
3+
| src/express.js:47:3:47:17 | req.headers.baz | baz |
4+
| src/express.js:48:3:48:10 | req.host | host |
5+
| src/express.js:49:3:49:14 | req.hostname | host |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from HTTP::RequestInputAccess access
4+
select access, access.getAHeaderName()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| src/http.js:9:3:9:17 | req.headers.foo | foo |
2+
| src/https.js:9:3:9:17 | req.headers.foo | foo |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from HTTP::RequestInputAccess access
4+
select access, access.getAHeaderName()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| src/hapi.js:25:3:25:21 | request.headers.baz | baz |

0 commit comments

Comments
 (0)