mTLS: When certificate authentication is done wrong
The blog post describes several implementation vulnerabilities in mTLS certificate authentication, including improper certificate extraction in Keycloak and LDAP injection in Bouncy Castle. An attacker could impersonate other users or perform blind LDAP injection to extract directory data.
Published on github.blog
Michael Stepankin·@artsploit
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the applications incorrectly assumed that all certificates in the client-provided chain were validated, or failed to escape user-controlled certificate fields before using them in queries.
Impact
An attacker could impersonate any user who uses mTLS authentication and mutate data on the server on their behalf.
What the attacker needed
A valid client certificate and key; ability to send a crafted certificate chain; target endpoint supports mTLS authentication
The fix
The vulnerability was fixed by using only the first certificate from the array.
How it was found
- Generate a valid client certificate and key for a legitimate user.
- Create a self-signed certificate for a different user.
- Concatenate the valid certificate, its key, the fake certificate, and the key again into a chain file.
- Send an HTTP request with the crafted chain to an mTLS-protected endpoint, specifying the fake user's client_id.
- Observe that the server performs actions on behalf of the fake user.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Mutual TLS (mTLS) is a way for a server to check a client's identity using a digital certificate, like a passport. The blog shows that if the server code mishandles the certificate, an attacker can pretend to be someone else or trick the server into sending data to an attacker-controlled server.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.