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 32b641e

Browse filesBrowse files
iSkoreBridgeAR
authored andcommitted
http: fixed socket.setEncoding fatal error
Applied updates from previous pull-requests to disallow socket.setEncoding before a http connection is parsed. Wrapped `socket.setEncoding` to throw an error. This previously resulted in a fatal error. PR-URL: #33405 Fixes: #18118 Refs: #18178 Refs: #19344 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 10596b6 commit 32b641e
Copy full SHA for 32b641e

File tree

Expand file treeCollapse file tree

4 files changed

+43
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+43
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+6Lines changed: 6 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,11 @@ An invalid HTTP header value was specified.
943943

944944
Status code was outside the regular status code range (100-999).
945945

946+
<a id="ERR_HTTP_SOCKET_ENCODING"></a>
947+
### `ERR_HTTP_SOCKET_ENCODING`
948+
949+
Changing the socket encoding is not allowed per [RFC 7230 Section 3][].
950+
946951
<a id="ERR_HTTP_TRAILER_INVALID"></a>
947952
### `ERR_HTTP_TRAILER_INVALID`
948953

@@ -2613,6 +2618,7 @@ such as `process.stdout.on('data')`.
26132618
[exports]: esm.html#esm_package_entry_points
26142619
[file descriptors]: https://en.wikipedia.org/wiki/File_descriptor
26152620
[policy]: policy.html
2621+
[RFC 7230 Section 3]: https://tools.ietf.org/html/rfc7230#section-3
26162622
[stream-based]: stream.html
26172623
[syscall]: http://man7.org/linux/man-pages/man2/syscalls.2.html
26182624
[Subresource Integrity specification]: https://www.w3.org/TR/SRI/#the-integrity-attribute
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const {
6363
const {
6464
ERR_HTTP_HEADERS_SENT,
6565
ERR_HTTP_INVALID_STATUS_CODE,
66+
ERR_HTTP_SOCKET_ENCODING,
6667
ERR_INVALID_ARG_TYPE,
6768
ERR_INVALID_CHAR
6869
} = codes;
@@ -476,6 +477,7 @@ function connectionListenerInternal(server, socket) {
476477
socket.on = generateSocketListenerWrapper('on');
477478
socket.addListener = generateSocketListenerWrapper('addListener');
478479
socket.prependListener = generateSocketListenerWrapper('prependListener');
480+
socket.setEncoding = socketSetEncoding;
479481

480482
// We only consume the socket if it has never been consumed before.
481483
if (socket._handle && socket._handle.isStreamBase &&
@@ -493,6 +495,10 @@ function connectionListenerInternal(server, socket) {
493495
socket._paused = false;
494496
}
495497

498+
function socketSetEncoding() {
499+
throw new ERR_HTTP_SOCKET_ENCODING();
500+
}
501+
496502
function updateOutgoingData(socket, state, delta) {
497503
state.outgoingData += delta;
498504
socketOnDrain(socket, state);
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,8 @@ E('ERR_HTTP_HEADERS_SENT',
935935
E('ERR_HTTP_INVALID_HEADER_VALUE',
936936
'Invalid value "%s" for header "%s"', TypeError);
937937
E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s', RangeError);
938+
E('ERR_HTTP_SOCKET_ENCODING',
939+
'Changing the socket encoding is not allowed per RFC7230 Section 3.', Error);
938940
E('ERR_HTTP_TRAILER_INVALID',
939941
'Trailers are invalid with this transfer encoding', Error);
940942
E('ERR_INCOMPATIBLE_OPTION_PAIR',
Collapse file
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const http = require('http');
6+
7+
const server = http.createServer().listen(0, connectToServer);
8+
9+
server.on('connection', common.mustCall((socket) => {
10+
assert.throws(
11+
() => {
12+
socket.setEncoding('');
13+
},
14+
{
15+
code: 'ERR_HTTP_SOCKET_ENCODING',
16+
name: 'Error',
17+
message: 'Changing the socket encoding is not ' +
18+
'allowed per RFC7230 Section 3.'
19+
}
20+
);
21+
22+
socket.end();
23+
}));
24+
25+
function connectToServer() {
26+
const client = new http.Agent().createConnection(this.address().port, () => {
27+
client.end();
28+
}).on('end', () => server.close());
29+
}

0 commit comments

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