Skip to content
Business logic Disclosed report Intermediate CVE-2021-22922

CVE-2021-22922: Wrong content via metalink not discarded

When curl is built with metalink support and used with the --metalink option, it verifies the cryptographic hash of downloaded files but only displays a failure message if the hash is wrong, leaving the corrupted file on disk. An attacker who can tamper with the download (e.g., over HTTP or FTP) could cause a file with an incorrect hash to be saved, and a user might mistakenly trust it as valid.

nyymi Follow

Originally disclosed on HackerOne

  • Triaged in 12 days
  • Fixed in 52 days
  • Paid in 31 days
  • Disclosed after 52 days

Summary:

When compiled --with-libmetalink and used with --metalink curl does check the cryptographics hash of the downloaded files. However, the only indication that the hash was incorrect is a message displayed to the user. The files with incorrect hashes are left to the disk as-is.

Since curl implements the hash validation and reports incorrect hashes there might be an expectation that files with incorrect hashes would not be kept either. Since the metalink can be used with insecure protocols such as http and ftp, the hash validation might be used an actual way to verify the download integrity against tampering.

Steps To Reproduce:

1.Configure libcurl --with-libmetalink and build libcurl 2. Have metalinktest.xml with <file name="testfile"> containing incorrect sha-256 hash for it. 3. Execute: curl --metalink https://testsite/metalinktest.xml

The following message will be displayed: Metalink: validating (testfile) [sha-256] FAILED (digest mismatch)

Yet, the downloaded file testfile with incorrect hash mismatch is kept.

Fix

It might be more sensible to download the file to a temporary name first, verify the hash and only then store the file to final name if the hash is correct. If hash mismatch is found remove the temporary file.

Impact

Modified or tampered files are kept and possibly incorrectly assumed valid

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, the metalink download logic writes the file to its final destination before hash verification and does not delete it upon mismatch.

Impact

Modified or tampered files are kept and possibly incorrectly assumed valid.

What the attacker needed

Curl built with --with-libmetalink; use of --metalink option; attacker can tamper with download

The fix

The file should be downloaded to a temporary name first, the hash verified, and only then moved to the final name if the hash is correct; if the hash mismatches, the temporary file should be removed.

How it was found

  1. Configure libcurl with --with-libmetalink and build libcurl
  2. Create a metalink XML file that specifies a file with an incorrect SHA-256 hash
  3. Run curl with the --metalink option pointing to the metalink file
  4. Observe that curl reports a hash validation failure but the downloaded file remains on disk

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.

Curl is a tool for downloading files. When you use a special 'metalink' file, curl can check that the downloaded file matches an expected fingerprint (a hash). This report says that if the fingerprint does not match, curl only prints a warning but still saves the bad file, so you might end up using a file that was tampered with.

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.

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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.