Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 87adb34

Browse filesBrowse files
mcollinaaduh95
authored andcommitted
http: harden ClientRequest options merge
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #63082 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent cb33a79 commit 87adb34
Copy full SHA for 87adb34

2 files changed

+63-1Lines changed: 63 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function ClientRequest(input, options, cb) {
209209
cb = options;
210210
options = input || kEmptyObject;
211211
} else {
212-
options = ObjectAssign(input || {}, options);
212+
options = ObjectAssign({ __proto__: null }, input, options);
213213
}
214214

215215
let agent = options.agent;
Collapse file
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('node:assert');
5+
const http = require('node:http');
6+
7+
const server = http.createServer(common.mustCall((req, res) => {
8+
req.resume();
9+
req.on('end', common.mustCall(() => {
10+
res.end('ok');
11+
}));
12+
}, 2));
13+
14+
function makeRequest(options, callback) {
15+
Object.defineProperty(Object.prototype, 'hostname', {
16+
__proto__: null,
17+
configurable: true,
18+
get: common.mustNotCall('get %Object.prototype%.hostname'),
19+
});
20+
21+
let req;
22+
try {
23+
req = http.request(options, callback);
24+
} finally {
25+
delete Object.prototype.hostname;
26+
}
27+
28+
req.on('error', common.mustNotCall());
29+
req.end();
30+
}
31+
32+
server.listen(0, common.localhostIPv4, common.mustCall(() => {
33+
const { address, port } = server.address();
34+
35+
makeRequest(
36+
{
37+
host: address,
38+
port,
39+
path: '/',
40+
},
41+
common.mustCall((res) => {
42+
assert.strictEqual(res.statusCode, 200);
43+
res.resume();
44+
res.on('end', common.mustCall());
45+
}),
46+
);
47+
48+
const nullProtoOptions = { __proto__: null, host: address, port, path: '/' };
49+
50+
assert.strictEqual(Object.getPrototypeOf(nullProtoOptions), null);
51+
52+
makeRequest(
53+
nullProtoOptions,
54+
common.mustCall((res) => {
55+
assert.strictEqual(res.statusCode, 200);
56+
res.resume();
57+
res.on('end', common.mustCall(() => {
58+
server.close(common.mustCall());
59+
}));
60+
}),
61+
);
62+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.