解决火绒 6.0 造成的 Node.js fetch 方法 unable to verify the first certificate 报错

之前用 Electron 写了一个监控客户端,昨天突然用不成了,检查日志发现这样的一个报错:

1
2
3
4
5
6
7
8
9
10
11
12
Error occurred in handler for 'getPrice': TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:12293:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WebContents.<anonymous> (node:electron/js2c/browser_init:2:78167) {
cause: Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (node:_tls_wrap:1659:34)
at TLSSocket.emit (node:events:514:28)
at TLSSocket._finishInit (node:_tls_wrap:1070:8)
at ssl.onhandshakedone (node:_tls_wrap:856:12) {
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
}

看起来是调用 Node.js 的 fetch 方法时遇到了证书问题,然而网站的证书应该是正常的,也没有过期,怎么肥四呢?

用 Microsoft Edge 浏览器访问一下这个网站,到开发者工具 Secure 标签看一下证书颁发者,发现居然是火绒的根证书 Huorong Anti-Virus Personal Root Certificate

火绒的根证书不被 Node.js 信任,问题就出在这里了。回想自己昨天才刚刚把火绒安全的版本从 5.0 升级到 6.0,于是打开火绒设置找找线索,果然找到了一个名为“加密连接扫描”的设置,把这个设置关闭之后,问题解决。

解决火绒 6.0 造成的 Node.js fetch 方法 unable to verify the first certificate 报错

https://www.imaegoo.com/2024/nodejs-fetch-cert-error/

作者

iMaeGoo

发布于

2024-05-13

更新于

2024-05-13

许可协议

CC BY 4.0

评论