Skip to content
Misconfiguration Disclosed report Advanced CVE-2024-30261

fetch with integrity option is too lax when algorithm is specified but hash value is in incorrect

The Subresource Integrity check in undici (and therefore Node.js fetch) failed to recognise a hash when the algorithm was given but the hash value was malformed, so the integrity check was skipped entirely. An attacker who could influence a resource's integrity attribute could have content loaded that should have been rejected.

uzlopak Follow

Originally disclosed on HackerOne

  • Triaged in 8 days
  • Fixed in 44 days
  • Disclosed after 2 months

A potential solution is attached as 0001-improve-bytesMatch.patch

Summary: I was investigating for some low hanging fruits regarding performance bottlenecks in undici, when I found this potential security issue in undici, and thus in nodejs. First I wrote a benchmark for bytesMatch and saw the following result:

Shell
aras@aras-Lenovo-Legion-5-17ARH05H:~/workspace/undici$ node benchmarks/bytesMatch.mjs 
cpu: AMD Ryzen 7 4800H with Radeon Graphics
runtime: node v21.6.2 (x64-linux)

benchmark                                    time (avg)             (min … max)       p75       p99      p999
------------------------------------------------------------------------------- -----------------------------
bytesMatch valid sha256 and base64        2'292 ns/iter   (2'009 ns … 9'452 ns)  2'209 ns  7'709 ns  9'452 ns
bytesMatch invalid sha256 and base64      2'153 ns/iter   (2'013 ns … 2'306 ns)  2'209 ns  2'275 ns  2'306 ns
bytesMatch valid sha256 and base64url       243 ns/iter       (205 ns … 318 ns)    261 ns    286 ns    301 ns
bytesMatch invalid sha256 and base64url     245 ns/iter       (203 ns … 400 ns)    264 ns    320 ns    390 ns

See attached 0001-add-benchmark.patch

So for some reason base64url was significantly faster than base64, even in the invalid case. So further investigations resulted in the finding that parseHashWithOptions in the underlying undici library is not matching base64url encoded hashes. Worse it is not matching any algorithms provided with invalid hashes. E.g. sha256-- wont result in detecting that a sha256 hash was provided, thus skipping totally the whole SRI check.

https://github.com/nodejs/undici/blob/e1195cbf32cb5f10f25e820d580264f24c7edc71/lib/fetch/util.js#L591

Steps To Reproduce:

See attached 0001-add-test.patch. It contains unit tests, which you can run against main branch.

Impact:

Resources which should be checked via SRI Logic are loaded nonetheless.

Supporting Material/References:

  • List any additional material (e.g. screenshots, logs, references, commits, code examples, etc.).

Impact

Resources which should be checked via SRI Logic are loaded nonetheless.

The original report as published on HackerOne, by uzlopak. 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 hash parsing function only recognised an algorithm when the following hash value matched a strict pattern, so a malformed value caused the whole integrity entry to be ignored rather than treated as a failure.

Impact

Resources that should have been checked by the integrity logic were loaded anyway.

What the attacker needed

Integrity attribute present with malformed hash; resource loaded through undici fetch

The fix

A patch improving bytesMatch was proposed as a potential solution for these malformed and base64url cases.

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.

Subresource Integrity (SRI) is a browser feature where a page says 'only run this file if its fingerprint matches this value'. If the fingerprint is written in a broken way, the code should refuse to load the file. Here the library instead treated the broken fingerprint as 'no check needed' and loaded the file anyway.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.