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: #29568Fixes: #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

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎lib/_http_agent.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ const net = require('net');
2727
constEventEmitter=require('events');
2828
constdebug=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
letservername=options.host;
241245
consthostHeader=req.getHeader('host');
242246
if(hostHeader){
247+
if(typeofhostHeader!=='string'){
248+
thrownewERR_INVALID_ARG_TYPE('options.headers.host',
249+
'String',hostHeader);
250+
}
251+
243252
// abc => abc
244253
// abc:123 => abc
245254
// [::1] => ::1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
constassert=require('assert');
6+
consthttp=require('http');
7+
8+
{
9+
10+
constoptions={
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)