undici or node native fetch is not working with mTLS
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 880
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 68
Description
Bug Description
this works with node-fetch
import https from 'https';
const agent = new https.Agent({
key,
cert,
rejectUnauthorized: false,
keepAlive: true,
});
this does not work
import { Agent } from 'undici';
dispatcher: new Agent({
connect: {
cert: cert,
key: key,
rejectUnauthorized: false,
keepAlive: true,
},
})
Reproducible By
You can use this repo https://github.com/sibelius/node-mtls
to create cert, key for a server and for a client
Expected Behavior
mTLS should work with undici and node native fetch
Logs & Screenshots
FETCH 604571: request to GET https://endpoint errored - read ECONNRESET
Environment
System:
OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
CPU: (12) x64 Intel(R) Xeon(R) Platinum 8160 CPU @ 2.10GHz
Memory: 52.21 GB / 64.00 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
pnpm: 9.15.4 - ~/.nvm/versions/node/v22.13.0/bin/pnpm
Additional context
trying to make undici mTLS work
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided sibelius/node-mtls repository to reproduce the ECONNRESET case on Node 22, then inspect the undici Agent connect options used with native fetch and compare them with the working node-fetch https.Agent example. Done means the same mTLS certificates work successfully with undici and Node native fetch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100