Skip to content
Crypto Disclosed report Advanced

curl/libcurl vulnerable to TLS truncation attacks

curl and libcurl do not require a TLS closure alert for protocols where the total data size is unknown, so a meddler-in-the-middle can end the connection early and leave a partial file that the tool treats as complete. The result is a silently truncated download.

nyymi Follow

Originally disclosed on HackerOne

  • Disclosed after 3.4 years

Summary:

curl/libcurl doesn't enforce "Closure Alerts" [1][2] for protocols that have no knowledge of the size of the transmitted data. This enables truncation attacks where the attacker in a meddler-in-the-middle position closes the connection prematurely. This results in partial file being downloaded without curl/libcurl being aware of the truncation.

Currently vulnerable protocols are at least:

  • gophers://
  • ldaps://
  • pop3s://
  • rtsps://

Remaining TLS protocols are vulnerable if CURLOPT_IGNORE_CONTENT_LENGTH is used:

  • https://
  • ftps://
  • imaps://

Arguably when this option is used the loss of security is desired. If this is intended behaviour, the lessened security should be documented.

Steps To Reproduce:

  1. Initiate curl/libcurl download over TLS (for example pop3s://)
  2. Perform man in the middle attack and terminate the connection
  3. Partial file will be downloaded

The problem can be reproduced for https:// with for example:

  1. `socat -v -x openssl-listen:8445,reuseaddr,fork,key=/etc/letsencrypt/live/example.tld/privkey.pem,cert=/etc/letsencrypt/live/example.tld/fullchain.pem,verify=0 stdout
  2. curl --output out.txt --ignore-content-length --remove-on-error https://example.tld:8445 && echo OK
  3. In socat, enter HTTP/1.1 200 OK <return>
  4. In socat, enter Content-Length: 200 <return>
  5. In socat, enter hello<return>
  6. Send CTRL-C to socat

Note that "OK" is printed and that out.txt file contains hello

Supporting Material/References:

[1] TLS 1.2 "Closure Alerts" - https://www.rfc-editor.org/rfc/rfc5246#section-7.2.1 [2] TLS 1.3 "Closure Alerts" - https://www.rfc-editor.org/rfc/rfc8446#section-6.1

Remediation

To ensure secure communications the Closure Alert should be required in case the content length is not available. An option to allow insecure operation is likely needed to allow communicating with non-compliant (and thus insecure) servers.

Impact

Truncated file transfer

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.

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 curl does not require a TLS closure alert when the protocol gives no content length, so an abrupt end of the connection is treated as a normal end of data.

Impact

An attacker in a meddler-in-the-middle position could cause a truncated file to be accepted as complete; the text notes that for https, ftps and imaps this only applies when the ignore-content-length option is used.

What the attacker needed

Attacker in a meddler-in-the-middle position; protocol without known content length, or…

The fix

curl should require a TLS closure alert when the content length is not available, with an option to allow insecure operation for non-compliant servers.

How it was found

  1. Start a curl or libcurl download over TLS, for example using the pop3s scheme.
  2. Act as a man in the middle and terminate the connection early.
  3. Observe that a partial file is downloaded without any error.

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 download finishes, the program should be able to tell that the other side said goodbye properly. Here, curl accepts a connection that just stops, so someone sitting in the middle of the network can cut it short and you get a file that looks fine but is only partly there.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by nyymi

View all

51 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.