mTLS
When using HTTPS ↗, a server presents a certificate for the client to authenticate in order to prove their identity. For even tighter security, some services require that the client also present a certificate.
This process - known as mTLS ↗ - moves authentication to the protocol of TLS, rather than managing it in application code. Connections from unauthorized clients are rejected during the TLS handshake instead.
To present a client certificate when communicating with a service, create a mTLS certificate binding in your Worker project's Wrangler file. This will allow your Worker to present a client certificate to a service on your behalf.
First, upload a certificate and its private key to your account using the wrangler mtls-certificate command:
npx wrangler mtls-certificate upload --cert cert.pem --key key.pem --name my-client-certThen, update your Worker project's Wrangler file to create an mTLS certificate binding:
{ "mtls_certificates": [ { "binding": "MY_CERT", "certificate_id": "<CERTIFICATE_ID>" } ]}mtls_certificates = [ { binding = "MY_CERT", certificate_id = "<CERTIFICATE_ID>" }]Adding an mTLS certificate binding includes a variable in the Worker's environment on which the fetch() method is available. This fetch() method uses the standard Fetch API and has the exact same signature as the global fetch, but always presents the client certificate when establishing the TLS connection.
export default { async fetch(request, environment) { return await environment.MY_CERT.fetch("https://a-secured-origin.com"); },};interface Env { MY_CERT: Fetcher;}
export default { async fetch(request, environment): Promise<Response> { return await environment.MY_CERT.fetch("https://a-secured-origin.com") }} satisfies ExportedHandler<Env>;Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark