From 1aa6588cfb1616b7906ae778f0157dafb55f960a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 1 Feb 2023 10:32:40 +0100 Subject: [PATCH 1/5] fix: ensure header value is a string --- lib/core/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/request.js b/lib/core/request.js index bee1a872960..9d63040528e 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -279,7 +279,7 @@ class Request { } function processHeaderValue (key, val) { - if (val && (typeof val === 'object' && !Array.isArray(val))) { + if (typeof val !== 'string') { throw new InvalidArgumentError(`invalid ${key} header`) } else if (headerCharRegex.exec(val) !== null) { throw new InvalidArgumentError(`invalid ${key} header`) From a2c96af1784eb08c58ba5f92107594606dc69e46 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 1 Feb 2023 10:34:00 +0100 Subject: [PATCH 2/5] fixup --- lib/core/request.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/core/request.js b/lib/core/request.js index 9d63040528e..4cbe0638622 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -279,9 +279,7 @@ class Request { } function processHeaderValue (key, val) { - if (typeof val !== 'string') { - throw new InvalidArgumentError(`invalid ${key} header`) - } else if (headerCharRegex.exec(val) !== null) { + if (typeof val !== 'string' || headerCharRegex.exec(val) !== null) { throw new InvalidArgumentError(`invalid ${key} header`) } return `${key}: ${val}\r\n` From 1aadf9105e3636d4af4592805a5a713bb1ba3e11 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 1 Feb 2023 10:46:05 +0100 Subject: [PATCH 3/5] fixup --- lib/core/request.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/core/request.js b/lib/core/request.js index 4cbe0638622..279295a29f8 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -279,9 +279,16 @@ class Request { } function processHeaderValue (key, val) { - if (typeof val !== 'string' || headerCharRegex.exec(val) !== null) { + if (val && typeof val === 'object') { throw new InvalidArgumentError(`invalid ${key} header`) } + + val = val == null ? `${val}` : '' + + if (headerCharRegex.exec(val) !== null) { + throw new InvalidArgumentError(`invalid ${key} header`) + } + return `${key}: ${val}\r\n` } From ea4e9f7cffe58e9a262fa8946d4a54b899e2a63e Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 1 Feb 2023 13:06:29 +0100 Subject: [PATCH 4/5] fixup --- lib/core/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/request.js b/lib/core/request.js index 279295a29f8..5cf269bd284 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -283,7 +283,7 @@ function processHeaderValue (key, val) { throw new InvalidArgumentError(`invalid ${key} header`) } - val = val == null ? `${val}` : '' + val = val != null ? `${val}` : '' if (headerCharRegex.exec(val) !== null) { throw new InvalidArgumentError(`invalid ${key} header`) From fb2837cab0ab8dde5c32c488e95ec4c98bd16090 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 5 Feb 2023 20:27:38 +0100 Subject: [PATCH 5/5] fixup --- test/client-dispatch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/client-dispatch.js b/test/client-dispatch.js index 9e59fdb2fb5..2196e5d53f5 100644 --- a/test/client-dispatch.js +++ b/test/client-dispatch.js @@ -94,7 +94,7 @@ test('basic dispatch get', (t) => { t.equal(`localhost:${server.address().port}`, req.headers.host) t.equal(undefined, req.headers.foo) t.equal('bar', req.headers.bar) - t.equal('null', req.headers.baz) + t.equal('', req.headers.baz) t.equal(undefined, req.headers['content-length']) res.end('hello') })