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 7d5ab8b

Browse filesBrowse files
Trotttargos
authored andcommitted
tls: introduce ERR_TLS_INVALID_CONTEXT
It is trivially possible to cause an internal assertion error with tls.createSecurePair(). Throw a friendly error instead. Reserve internal assertions for things that we believe to be impossible. PR-URL: #30718 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3f1ca18 commit 7d5ab8b
Copy full SHA for 7d5ab8b

File tree

Expand file treeCollapse file tree

4 files changed

+19
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+19
-4
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+8Lines changed: 8 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,14 @@ recommended to use 2048 bits or larger for stronger security.
18011801
A TLS/SSL handshake timed out. In this case, the server must also abort the
18021802
connection.
18031803

1804+
<a id="ERR_TLS_INVALID_CONTEXT">
1805+
### ERR_TLS_INVALID_CONTEXT
1806+
<!-- YAML
1807+
added: REPLACEME
1808+
-->
1809+
1810+
The context must be a `SecureContext`.
1811+
18041812
<a id="ERR_TLS_INVALID_PROTOCOL_METHOD"></a>
18051813
### `ERR_TLS_INVALID_PROTOCOL_METHOD`
18061814

Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const {
5252
ERR_SOCKET_CLOSED,
5353
ERR_TLS_DH_PARAM_SIZE,
5454
ERR_TLS_HANDSHAKE_TIMEOUT,
55+
ERR_TLS_INVALID_CONTEXT,
5556
ERR_TLS_RENEGOTIATION_DISABLED,
5657
ERR_TLS_REQUIRED_SERVER_NAME,
5758
ERR_TLS_SESSION_ATTACK,
@@ -513,8 +514,9 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
513514
options.credentials ||
514515
tls.createSecureContext(options);
515516
assert(handle.isStreamBase, 'handle must be a StreamBase');
516-
assert(context.context instanceof NativeSecureContext,
517-
'context.context must be a NativeSecureContext');
517+
if (!(context.context instanceof NativeSecureContext)) {
518+
throw new ERR_TLS_INVALID_CONTEXT('context');
519+
}
518520
const res = tls_wrap.wrap(handle, context.context, !!options.isServer);
519521
res._parent = handle; // C++ "wrap" object: TCPWrap, JSStream, ...
520522
res._parentWrap = wrap; // JS object: net.Socket, JSStreamSocket, ...
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ E('ERR_TLS_CERT_ALTNAME_INVALID', function(reason, host, cert) {
11741174
}, Error);
11751175
E('ERR_TLS_DH_PARAM_SIZE', 'DH parameter size %s is less than 2048', Error);
11761176
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout', Error);
1177+
E('ERR_TLS_INVALID_CONTEXT', '%s must be a SecureContext', TypeError),
11771178
E('ERR_TLS_INVALID_PROTOCOL_VERSION',
11781179
'%j is not a valid %s TLS protocol version', TypeError);
11791180
E('ERR_TLS_PROTOCOL_VERSION_CONFLICT',
Collapse file

‎test/parallel/test-tls-basic-validations.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-tls-basic-validations.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ common.expectsError(
7878
assert.throws(() => tls.createServer({ ticketKeys: Buffer.alloc(0) }),
7979
/TypeError: Ticket keys length must be 48 bytes/);
8080

81-
common.expectsInternalAssertion(
81+
assert.throws(
8282
() => tls.createSecurePair({}),
83-
'context.context must be a NativeSecureContext'
83+
{
84+
message: 'context must be a SecureContext',
85+
code: 'ERR_TLS_INVALID_CONTEXT',
86+
name: 'TypeError',
87+
}
8488
);
8589

8690
{

0 commit comments

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