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 3fe37e6

Browse filesBrowse files
vighnesh153targos
authored andcommitted
https: prevent options object from being mutated
Previously, when passing options object to the agent.createConnection method, the same options object got modified within the method. Now, any modification will happen on only a copy of the object. Fixes: #31119 PR-URL: #31151 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent f281946 commit 3fe37e6
Copy full SHA for 3fe37e6

File tree

Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-1
lines changed
Open diff view settings
Collapse file

‎lib/https.js‎

Copy file name to clipboardExpand all lines: lib/https.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ function createConnection(port, host, options) {
9696
if (port !== null && typeof port === 'object') {
9797
options = port;
9898
} else if (host !== null && typeof host === 'object') {
99-
options = host;
99+
options = { ...host };
100100
} else if (options === null || typeof options !== 'object') {
101101
options = {};
102+
} else {
103+
options = { ...options };
102104
}
103105

104106
if (typeof port === 'number') {
Collapse file

‎test/parallel/test-https-agent-create-connection.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-https-agent-create-connection.js
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,27 @@ function createServer() {
132132
}));
133133
}));
134134
}
135+
136+
// `options` should not be modified
137+
{
138+
const server = createServer();
139+
server.listen(0, common.mustCall(() => {
140+
const port = server.address().port;
141+
const host = 'localhost';
142+
const options = {
143+
port: 3000,
144+
rejectUnauthorized: false
145+
};
146+
147+
const socket = agent.createConnection(port, host, options);
148+
socket.on('connect', common.mustCall((data) => {
149+
socket.end();
150+
}));
151+
socket.on('end', common.mustCall(() => {
152+
assert.deepStrictEqual(options, {
153+
port: 3000, rejectUnauthorized: false
154+
});
155+
server.close();
156+
}));
157+
}));
158+
}

0 commit comments

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