Skip to content

Commit 2daf883

Browse files
gntemTrott
authored andcommitted
http: throw if 'host' agent header is not a string value
If the 'host' agent header is an array or other non-string value, throw. PR-URL: #29568 Fixes: #29408 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent a0c6cf8 commit 2daf883

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/_http_agent.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ const net = require('net');
2727
const EventEmitter = require('events');
2828
const debug = require('internal/util/debuglog').debuglog('http');
2929
const { async_id_symbol } = require('internal/async_hooks').symbols;
30-
30+
const {
31+
codes: {
32+
ERR_INVALID_ARG_TYPE,
33+
},
34+
} = require('internal/errors');
3135
// New Agent code.
3236

3337
// The largest departure from the previous implementation is that
@@ -240,6 +244,11 @@ function calculateServerName(options, req) {
240244
let servername = options.host;
241245
const hostHeader = req.getHeader('host');
242246
if (hostHeader) {
247+
if (typeof hostHeader !== 'string') {
248+
throw new ERR_INVALID_ARG_TYPE('options.headers.host',
249+
'String', hostHeader);
250+
}
251+
243252
// abc => abc
244253
// abc:123 => abc
245254
// [::1] => ::1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const http = require('http');
7+
8+
{
9+
10+
const options = {
11+
port: '80',
12+
path: '/',
13+
headers: {
14+
host: []
15+
}
16+
};
17+
18+
assert.throws(() => {
19+
http.request(options);
20+
}, {
21+
code: /ERR_INVALID_ARG_TYPE/
22+
}, 'http request should throw when passing array as header host');
23+
}

0 commit comments

Comments
 (0)