Skip to content

Commit 214aa07

Browse files
committed
support host for http-proxy client requests
1 parent cc48172 commit 214aa07

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ private module HttpProxy {
2121

2222
override DataFlow::Node getUrl() { result = getParameter(0).getMember("target").getARhs() }
2323

24-
override DataFlow::Node getHost() { none() }
24+
override DataFlow::Node getHost() {
25+
result = getParameter(0).getMember("target").getMember("host").getARhs()
26+
}
2527

2628
override DataFlow::Node getADataNode() { none() }
2729
}
@@ -37,17 +39,21 @@ private module HttpProxy {
3739
this = any(CreateServerCall server).getReturn().getMember(method).getACall()
3840
}
3941

40-
override DataFlow::Node getUrl() {
42+
private API::Node getOptionsObject() {
4143
exists(int optionsIndex |
4244
method = "web" and optionsIndex = 2
4345
or
4446
method = "ws" and optionsIndex = 3
4547
|
46-
result = getParameter(optionsIndex).getMember("target").getARhs()
48+
result = getParameter(optionsIndex)
4749
)
4850
}
4951

50-
override DataFlow::Node getHost() { none() }
52+
override DataFlow::Node getUrl() { result = getOptionsObject().getMember("target").getARhs() }
53+
54+
override DataFlow::Node getHost() {
55+
result = getOptionsObject().getMember("target").getMember("host").getARhs()
56+
}
5157

5258
override DataFlow::Node getADataNode() { none() }
5359
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ test_ClientRequest
8282
| tst.js:267:1:267:61 | httpPro ... 9000'}) |
8383
| tst.js:269:13:269:48 | httpPro ... ptions) |
8484
| tst.js:271:3:271:61 | proxy.w ... 080' }) |
85+
| tst.js:274:1:283:2 | httpPro ... true\\n}) |
8586
test_getADataNode
8687
| tst.js:53:5:53:23 | axios({data: data}) | tst.js:53:18:53:21 | data |
8788
| tst.js:57:5:57:39 | axios.p ... data2}) | tst.js:57:19:57:23 | data1 |
@@ -127,6 +128,7 @@ test_getHost
127128
| tst.js:93:5:93:35 | net.req ... host }) | tst.js:93:29:93:32 | host |
128129
| tst.js:219:5:219:41 | data.so ... Host"}) | tst.js:219:32:219:39 | "myHost" |
129130
| tst.js:257:1:262:2 | form.su ... rs()\\n}) | tst.js:259:11:259:23 | 'example.org' |
131+
| tst.js:274:1:283:2 | httpPro ... true\\n}) | tst.js:277:15:277:30 | 'my-domain-name' |
130132
test_getUrl
131133
| apollo.js:5:18:5:78 | new cre ... hql' }) | apollo.js:5:44:5:75 | 'https: ... raphql' |
132134
| apollo.js:10:1:10:54 | new Htt ... hql' }) | apollo.js:10:21:10:51 | 'http:/ ... raphql' |
@@ -215,6 +217,7 @@ test_getUrl
215217
| tst.js:257:1:262:2 | form.su ... rs()\\n}) | tst.js:257:13:262:1 | {\\n m ... ers()\\n} |
216218
| tst.js:267:1:267:61 | httpPro ... 9000'}) | tst.js:267:37:267:59 | 'http:/ ... t:9000' |
217219
| tst.js:271:3:271:61 | proxy.w ... 080' }) | tst.js:271:33:271:58 | 'http:/ ... m:8080' |
220+
| tst.js:274:1:283:2 | httpPro ... true\\n}) | tst.js:275:13:281:5 | {\\n ... ,\\n } |
218221
test_getAResponseDataNode
219222
| tst.js:19:5:19:23 | requestPromise(url) | tst.js:19:5:19:23 | requestPromise(url) | text | true |
220223
| tst.js:21:5:21:23 | superagent.get(url) | tst.js:21:5:21:23 | superagent.get(url) | stream | true |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,14 @@ var proxy = httpProxy.createProxyServer(options);
270270
http.createServer(function(req, res) {
271271
proxy.web(req, res, { target: 'http://mytarget.com:8080' });
272272
});
273+
274+
httpProxy.createProxyServer({
275+
target: {
276+
protocol: 'https:',
277+
host: 'my-domain-name',
278+
port: 443,
279+
pfx: fs.readFileSync('path/to/certificate.p12'),
280+
passphrase: 'password',
281+
},
282+
changeOrigin: true
283+
}).listen(8000);

0 commit comments

Comments
 (0)