Certificate authentication re-use on redirect
Curl reuses a client certificate when following a redirect to a different host, allowing an attacker to control which resources are accessed with that certificate. This could lead to unauthorised access to confidential information if the application returns fetched content to the attacker.
- Disclosed after 2 days
Summary:
Curl will reuse existing certificate for further TLS requests when following redirects. This is similar to CVE 2022-27774 but with narrower impact, as the secret (private key) is not leaked.
Steps To Reproduce:
- Configure a site (
targetsite.tld) to require client certificates for authentication - Have
client.crtandclient.keythat can be used to access this site - Create an attacker controller site
https://evilsite.tld/somethingthat redirects tohttps://targetsite.tld/secretfile curl -L --cert client.crt --key client.key https://evilsite.tld/something- The redirect is followed and the secretfile content fetched
In effect the attacker can choose which content is accessed with the client certificate. This proof of concept is of course rather silly as one-liner curl command, but it still demonstrates the inability of libcurl to restrict where key/cert are used. This scenario of course requires that the application in question can be passed attacker controlled URLs and that redirects are followed. If the attacker also wishes to obtain the secretfile response the application in question should be returning the file contents to the request to the attacker (lets assume attacker can pass URLs the app and gets the fetched content back as result).
Configuring client key/cert for arbitrary requests is unwise. However, since the common understanding is that the client certificate public key is "useless" to the attacker without the corresponding private key, it might happen that this (arguably silly) use pattern might exists. It is "harmless" after all...
I believe that the key/cert should not used when following a redirect to a different protocol/host/port. This wouldn't prevent the minor leak of the client.crt to the attacker, but at least the attacker wouldn't get to choose which resources to access.
This is CWE-522: Insufficiently Protected Credentials
Impact
The attacker can control which resource is accessed with the key/cert, and potentially gain unauthorised access to confidential information.
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
Likely libcurl does not restrict the use of client certificates to the original host when following redirects.
Impact
The attacker can control which resource is accessed with the key/cert, and potentially gain unauthorised access to confidential information, but only if the application can be passed attacker-controlled URLs, follows redirects, and returns the fetched content to the attacker.
What the attacker needed
Application accepts attacker-controlled URLs; Application follows redirects; Application returns fetched content to attacker; Client certificate configured for requests
The fix
The key/cert should not be used when following a redirect to a different protocol, host, or port.
How it was found
- Configure a site to require client certificates for authentication.
- Obtain a client certificate and key that can access this site.
- Create an attacker-controlled site that redirects to the protected site.
- Run curl with the client certificate and key, following redirects, against the attacker site.
- The redirect is followed and the protected content is fetched.
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 a program like curl connects to a site that asks for a client certificate, it proves who it is. If an attacker-controlled site redirects curl to a protected site, curl still uses the same certificate there. The attacker can then make curl fetch files from the protected site, potentially exposing secrets.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.