#13940·traefik

Feature: PassTLSClientCert middleware leaf certificate only mode

Author: vantropCreated Sep 21, 2026Updated Sep 22, 2026
Labelskind/enhancementarea/tlscontributor/wanted

Welcome!

  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've searched similar issues on the Traefik community forum and didn't find any.

What did you expect to see?

Summary

When PassTLSClientCert is configured with pem: true and the client presents a certificate chain with more than one certificate, Traefik concatenates each certificate's PEM encoding with a comma into a single X-Forwarded-Tls-Client-Cert header value, e.g.:

X-Forwarded-Tls-Client-Cert: -----BEGIN CERTIFICATE-----MIIC...-----END CERTIFICATE-----,-----BEGIN CERTIFICATE-----MIID...-----END CERTIFICATE-----

This is not valid PEM and is not a format most libraries/servers expect to receive in a header. Servers that read this header and try to parse it as a single PEM-encoded certificate (rather than manually splitting on , and reconstructing/decoding each part) fail to parse it, or worse, silently parse only part of it.

Keycloak is a concrete example: it expects the header to contain a single PEM certificate it can decode directly. When Traefik forwards a multi-certificate chain in this comma-joined form, Keycloak's mutual-TLS authentication fails to extract the client certificate at all, breaking X.509 client-certificate authentication behind Traefik.

Suggestion

Add a middleware config option, onlyLeaf: true, wich would apply to pem mode. When set, the header should contain only the leaf certificate's PEM block. This gives users a way to guarantee a clean, single, standards-parseable PEM certificate in the header, improving compatibility with servers that expect a valid PEM.

Example config that could produce this behavior:

yaml
http:
  middlewares:
    test-passtlsclientcert:
      passTLSClientCert:
        pem: true
        onlyLeaf: true

Not to bring a breaking change, the default value should be false.

using PeerCertificates[0] in the middleware code should do the trick as the ConnectionState doc states :

    // PeerCertificates are the parsed certificates sent by the peer, in the
	// order in which they were sent. The first element is the leaf certificate
	// that the connection is verified against.
	//
	// On the client side, it can't be empty. On the server side, it can be
	// empty if Config.ClientAuth is not RequireAnyClientCert or
	// RequireAndVerifyClientCert.
	//
	// PeerCertificates and its contents should not be modified.
	PeerCertificates []*[x509](https://pkg.go.dev/crypto/x509).[Certificate](https://pkg.go.dev/crypto/x509#Certificate)

I'm happy to contribute a PR for this. Let me know if the suggested implementation option is a valid one.