How to use `new tls.TLSSocket(...)` to establish a secure connection?
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
Affected URL(s)
https://nodejs.org/docs/latest-v18.x/api/tls.html
Description of the problem
What is the correct, non-deprecated way to use the new tls.TLSSocket(...) constructor to establish a secure connection? Context: https://github.com/typelevel/fs2/security/advisories/GHSA-2cpx-6pqp-wf35
According to two unmerged docs PRs, when directly calling new tls.TLSSocket(...) it is the user's responsibility to validate peer certificates and identity.
In https://github.com/nodejs/node/pull/10846 it says:
Warning: When directly constructing a
tls.TLSSocketinstead of using
[tls.connect()][] it is the caller's responsibility to:
- manage the lifetime of the the underlying socket, including connecting it;
- validate the peer certificate and identity, see the [
'secure'][] event.
Before using the connection, the user must make the following
checks or the connection should be considered completely insecure:
- Verify that the peer certificate is valid, see [
ssl.verifyError()][].- Verify that the peer certificate is for the expected host, see
[tls.checkServerIdentity()][] and [tls.TLSSocket.getPeerCertificate()][].
In https://github.com/nodejs/node/pull/23915 it says:
It is important to remember, however,
that it is the caller's responsibility to manage the lifecycle of the provided
net.Socket, including establishing the connection and validating peer
certificates and identity. See the ['secure'][] event.
And includes an example:
tlsSocket.on('secure', function() {
const err = this.verifyError() ||
tls.checkServerIdentity(hostname, this.getPeerCertificate());
if (err)
this.destroy(err);
});
Both PRs demonstrate how to do this validation, but require use of:
- The
'secure'event. In the current Node.js documentation, the only mention of'secure'is under the deprecatedtls.SecurePair, and is itself deprecated. It is also not clear that the'secure'event is also emitted ontls.TLSSocket.
https://nodejs.org/docs/latest-v18.x/api/tls.html#event-secure tlsSocket.ssl.verifyError(), which does not appear at all in the current documentation. Furthermore, according to https://github.com/nodejs/node/pull/840#issuecomment-74343250tlsSocket.sslis a "legacy property".
Note that the described validation steps appear to be consistent with internal use
https://github.com/nodejs/node/blob/5fbf33ef8641cf57bfbb7f0c87f83447c44266b8/lib/_tls_wrap.js#L1106
https://github.com/nodejs/node/blob/5fbf33ef8641cf57bfbb7f0c87f83447c44266b8/lib/_tls_wrap.js#L1044-L1055
This leaves me with two concerns:
- The current documentation does not indicate that using
new tls.TLSSocket(...)by itself does not result in a secure connection. - As far as I can tell it is impossible to use
new tls.TLSSocket(...)to establish a secure connection without relying on APIs that are undocumented, deprecated, and/or legacy.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 tls.TLSSocket、'secure' 事件以及链接的 lib/_tls_wrap.js 部分的 v18 TLS 文档开始。将文档记录的 API 与使用 verifyError()、tls.checkServerIdentity() 和 getPeerCertificate() 的验证示例进行比较。当文档清楚地说明一种受支持且未弃用的建立和验证安全连接的方式,或明确记录该限制时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- documentation, security
- Issue 类型
- 文档
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 50/100