|
| 1 | +From 286a9c4e5b1b7bb7373195992a0f570c3eab8aaa Mon Sep 17 00:00:00 2001 |
| 2 | +From: Matteo Collina <hello@matteocollina.com> |
| 3 | +Date: Thu, 19 Feb 2026 15:49:43 +0100 |
| 4 | +Subject: [PATCH] http: use null prototype for headersDistinct/trailersDistinct |
| 5 | + |
| 6 | +Use { __proto__: null } instead of {} when initializing the |
| 7 | +headersDistinct and trailersDistinct destination objects. |
| 8 | + |
| 9 | +A plain {} inherits from Object.prototype, so when a __proto__ |
| 10 | +header is received, dest["__proto__"] resolves to Object.prototype |
| 11 | +(truthy), causing _addHeaderLineDistinct to call .push() on it, |
| 12 | +which throws an uncaught TypeError and crashes the process. |
| 13 | + |
| 14 | +Ref: https://hackerone.com/reports/3560402 |
| 15 | +PR-URL: https://github.com/nodejs-private/node-private/pull/821 |
| 16 | +Refs: https://hackerone.com/reports/3560402 |
| 17 | +Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> |
| 18 | +Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> |
| 19 | +CVE-ID: CVE-2026-21710 |
| 20 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 21 | +Upstream-reference: https://github.com/nodejs/node/commit/00ad47a28eb2e3dc0ff5610d58c53341acf3cf8d.patch |
| 22 | +--- |
| 23 | + lib/_http_incoming.js | 4 +-- |
| 24 | + .../test-http-headers-distinct-proto.js | 36 +++++++++++++++++++ |
| 25 | + test/parallel/test-http-multiple-headers.js | 16 ++++----- |
| 26 | + 3 files changed, 46 insertions(+), 10 deletions(-) |
| 27 | + create mode 100644 test/parallel/test-http-headers-distinct-proto.js |
| 28 | + |
| 29 | +diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js |
| 30 | +index e45ae819..77433e55 100644 |
| 31 | +--- a/lib/_http_incoming.js |
| 32 | ++++ b/lib/_http_incoming.js |
| 33 | +@@ -131,7 +131,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', { |
| 34 | + __proto__: null, |
| 35 | + get: function() { |
| 36 | + if (!this[kHeadersDistinct]) { |
| 37 | +- this[kHeadersDistinct] = {}; |
| 38 | ++ this[kHeadersDistinct] = { __proto__: null }; |
| 39 | + |
| 40 | + const src = this.rawHeaders; |
| 41 | + const dst = this[kHeadersDistinct]; |
| 42 | +@@ -171,7 +171,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'trailersDistinct', { |
| 43 | + __proto__: null, |
| 44 | + get: function() { |
| 45 | + if (!this[kTrailersDistinct]) { |
| 46 | +- this[kTrailersDistinct] = {}; |
| 47 | ++ this[kTrailersDistinct] = { __proto__: null }; |
| 48 | + |
| 49 | + const src = this.rawTrailers; |
| 50 | + const dst = this[kTrailersDistinct]; |
| 51 | +diff --git a/test/parallel/test-http-headers-distinct-proto.js b/test/parallel/test-http-headers-distinct-proto.js |
| 52 | +new file mode 100644 |
| 53 | +index 00000000..bd4cb82b |
| 54 | +--- /dev/null |
| 55 | ++++ b/test/parallel/test-http-headers-distinct-proto.js |
| 56 | +@@ -0,0 +1,36 @@ |
| 57 | ++'use strict'; |
| 58 | ++ |
| 59 | ++const common = require('../common'); |
| 60 | ++const assert = require('assert'); |
| 61 | ++const http = require('http'); |
| 62 | ++const net = require('net'); |
| 63 | ++ |
| 64 | ++// Regression test: sending a __proto__ header must not crash the server |
| 65 | ++// when accessing req.headersDistinct or req.trailersDistinct. |
| 66 | ++ |
| 67 | ++const server = http.createServer(common.mustCall((req, res) => { |
| 68 | ++ const headers = req.headersDistinct; |
| 69 | ++ assert.strictEqual(Object.getPrototypeOf(headers), null); |
| 70 | ++ assert.deepStrictEqual(Object.getOwnPropertyDescriptor(headers, '__proto__').value, ['test']); |
| 71 | ++ res.end(); |
| 72 | ++})); |
| 73 | ++ |
| 74 | ++server.listen(0, common.mustCall(() => { |
| 75 | ++ const port = server.address().port; |
| 76 | ++ |
| 77 | ++ const client = net.connect(port, common.mustCall(() => { |
| 78 | ++ client.write( |
| 79 | ++ 'GET / HTTP/1.1\r\n' + |
| 80 | ++ 'Host: localhost\r\n' + |
| 81 | ++ '__proto__: test\r\n' + |
| 82 | ++ 'Connection: close\r\n' + |
| 83 | ++ '\r\n', |
| 84 | ++ ); |
| 85 | ++ })); |
| 86 | ++ |
| 87 | ++ client.on('end', common.mustCall(() => { |
| 88 | ++ server.close(); |
| 89 | ++ })); |
| 90 | ++ |
| 91 | ++ client.resume(); |
| 92 | ++})); |
| 93 | +diff --git a/test/parallel/test-http-multiple-headers.js b/test/parallel/test-http-multiple-headers.js |
| 94 | +index 8f52f817..d0fea85c 100644 |
| 95 | +--- a/test/parallel/test-http-multiple-headers.js |
| 96 | ++++ b/test/parallel/test-http-multiple-headers.js |
| 97 | +@@ -27,13 +27,13 @@ const server = createServer( |
| 98 | + host, |
| 99 | + 'transfer-encoding': 'chunked' |
| 100 | + }); |
| 101 | +- assert.deepStrictEqual(req.headersDistinct, { |
| 102 | ++ assert.deepStrictEqual(req.headersDistinct, Object.assign({ __proto__: null }, { |
| 103 | + 'connection': ['close'], |
| 104 | + 'x-req-a': ['eee', 'fff', 'ggg', 'hhh'], |
| 105 | + 'x-req-b': ['iii; jjj; kkk; lll'], |
| 106 | + 'host': [host], |
| 107 | +- 'transfer-encoding': ['chunked'] |
| 108 | +- }); |
| 109 | ++ 'transfer-encoding': ['chunked'], |
| 110 | ++ })); |
| 111 | + |
| 112 | + req.on('end', function() { |
| 113 | + assert.deepStrictEqual(req.rawTrailers, [ |
| 114 | +@@ -46,7 +46,7 @@ const server = createServer( |
| 115 | + ); |
| 116 | + assert.deepStrictEqual( |
| 117 | + req.trailersDistinct, |
| 118 | +- { 'x-req-x': ['xxx', 'yyy'], 'x-req-y': ['zzz; www'] } |
| 119 | ++ Object.assign({ __proto__: null }, { 'x-req-x': ['xxx', 'yyy'], 'x-req-y': ['zzz; www'] }) |
| 120 | + ); |
| 121 | + |
| 122 | + res.setHeader('X-Res-a', 'AAA'); |
| 123 | +@@ -129,14 +129,14 @@ server.listen(0, common.mustCall(() => { |
| 124 | + 'x-res-d': 'JJJ; KKK; LLL', |
| 125 | + 'transfer-encoding': 'chunked' |
| 126 | + }); |
| 127 | +- assert.deepStrictEqual(res.headersDistinct, { |
| 128 | ++ assert.deepStrictEqual(res.headersDistinct, Object.assign({ __proto__: null }, { |
| 129 | + 'x-res-a': [ 'AAA', 'BBB', 'CCC' ], |
| 130 | + 'x-res-b': [ 'DDD; EEE; FFF; GGG' ], |
| 131 | + 'connection': [ 'close' ], |
| 132 | + 'x-res-c': [ 'HHH', 'III' ], |
| 133 | + 'x-res-d': [ 'JJJ; KKK; LLL' ], |
| 134 | +- 'transfer-encoding': [ 'chunked' ] |
| 135 | +- }); |
| 136 | ++ 'transfer-encoding': [ 'chunked' ], |
| 137 | ++ })); |
| 138 | + |
| 139 | + res.on('end', function() { |
| 140 | + assert.deepStrictEqual(res.rawTrailers, [ |
| 141 | +@@ -150,7 +150,7 @@ server.listen(0, common.mustCall(() => { |
| 142 | + ); |
| 143 | + assert.deepStrictEqual( |
| 144 | + res.trailersDistinct, |
| 145 | +- { 'x-res-x': ['XXX', 'YYY'], 'x-res-y': ['ZZZ; WWW'] } |
| 146 | ++ Object.assign({ __proto__: null }, { 'x-res-x': ['XXX', 'YYY'], 'x-res-y': ['ZZZ; WWW'] }) |
| 147 | + ); |
| 148 | + server.close(); |
| 149 | + }); |
| 150 | +-- |
| 151 | +2.45.4 |
| 152 | + |
0 commit comments