Skip to content

undici or node native fetch is not working with mTLS #4034

Description

@sibelius

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions