GHSL-2023-083: Improper certificate validation in KeyCloak - CVE-2023-2422
Keycloak's mTLS client authentication iterated over the entire certificate chain to match the client_id, while the Java HTTPS server only validated the first certificate. An attacker with a valid client certificate could append a self-signed certificate with another client's subject DN and impersonate that client.
Originally disclosed on GitHub Security Lab
When a Keycloak server is configured to support mTLS authentication for OAuth/OpenID clients, it does not properly verify the client certificate chain. A client that possesses a proper certificate can authorize itself as any other client and therefore access data that belongs to other clients.
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Keycloak matched the client_id against any certificate in the chain, but the TLS server only validated the first certificate, so a self-signed certificate appended to the chain was trusted.
Impact
A client with a valid certificate could impersonate any other client and access data belonging to other clients.
What the attacker needed
Keycloak configured with mTLS for OAuth clients; Attacker possesses a valid client certificate and key; Target client uses X509 Certificate authentication
The fix
The fix was to use only the first certificate in the chain for client_id matching, ensuring the validated certificate is the one used.
How it was found
- Generate server and client certificates, using the server certificate as a CA for client certificates.
- Start Keycloak with mTLS enabled, requesting client certificates and trusting the server certificate.
- Create two OAuth clients in the admin UI and configure each to use X509 Certificate authentication with the appropriate Subject DN.
- As client1, connect using its certificate and key to the register-node API with client_id=client1.
- Generate a self-signed certificate with subject CN=client2, append it to the chain, and connect to the same API with client_id=client2.
- Observe that the API executes on behalf of client2, returning HTTP 204.
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 report has not been written yet. The Original tab links to the source.
When two computers talk securely, they can show certificates to prove who they are. Keycloak checked every certificate in the list a client sent, but the underlying server only checked the first one. So an attacker could add a fake certificate for someone else at the end of the list and pretend to be that other client.
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.