Skip to content
Memory corruption Disclosed report Advanced

WebSocket decoder use-after-free when curl_easy_pause() unpauses from a debug callback

A use-after-free exists in libcurl's WebSocket receive path when an application pauses and resumes the transfer from inside a debug callback. A malicious WebSocket server could then cause corrupted bytes from freed heap memory to be delivered to the application's write callback.

rat5ak Follow

Originally disclosed on HackerOne

Informational View original
  • Disclosed after 43 hours

Summary

At lib/ws.c:503, ws_dec_pass_payload() holds a pointer into the WebSocket receive queue while passing a frame to the application's write callback. If that callback returns CURL_WRITEFUNC_PAUSE, the PAUSE requested trace invokes the debug callback before the WebSocket pass consumes those bytes (CURLOPT_VERBOSE=1 and curl_global_trace("write") enabled). Calling curl_easy_pause(CURLPAUSE_RECV) then curl_easy_pause(CURLPAUSE_CONT) there starts nested ws_cw_flush(). It frees the queued chunk before the outer pass reads it; in my curl 8.23.0 run, the PoC's client exits 0 after receiving all 200,005 bytes, but byte offset 32,756 differs from the server's stream, and ASan reports a 65,518-byte use-after-free read.

Affected version

  • curl 8.22.0 and 8.23.0 on Linux x86-64: reproduced; b940cb1566 introduced this path in 8.22.0; attached ASan trace is from 8.22.0
  • Master at 629646d (17 October 2026): same unguarded path confirmed by source inspection

This reports a different WebSocket queue from report #4102061: applying the proposed cw-out and cw-pause guards from the still-open PR #23431 leaves this PoC corrupting output; the attached diff adds regression test 2312.

I used AI assistance to find and patch this; I reproduced the Release corruption and ASan UAF with the attached PoC.

Steps To Reproduce

  1. Check out curl-8_23_0 and build static libcurl with WebSockets and verbose strings:

    Shell
    cmake -S . -B bld-vuln -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCURL_USE_OPENSSL=ON -DENABLE_DEBUG=OFF -DCURL_DISABLE_VERBOSE_STRINGS=OFF
    cmake --build bld-vuln --target libcurl_static -j2
    
  2. Put the attached client.c, server.py, and run.sh in one directory; run sh run.sh /absolute/path/to/curl/bld-vuln vulnerable there to see the changed output

  3. Build the same tag with ASan and run sh run.sh /absolute/path/to/curl/bld-asan asan:

    Shell
    cmake -S . -B bld-asan -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCURL_USE_OPENSSL=ON -DENABLE_DEBUG=OFF -DCURL_DISABLE_VERBOSE_STRINGS=OFF -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer -g" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
    cmake --build bld-asan --target libcurl_static -j2
    
  4. Apply ws-fix-and-test.diff, configure and build with the Release flags from step 1 using bld-fixed instead of bld-vuln, then run sh run.sh /absolute/path/to/curl/bld-fixed fixed for the clean control

Impact

A WebSocket server can supply the large frame, but the client must use the callback pattern above; libcurl can then deliver bytes from reused heap storage to that application's write callback, with no peer-visible leak or code execution demonstrated.

The original report as published on HackerOne, by rat5ak. 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 WebSocket payload pass keeps a pointer into the receive queue across a callback that can re-enter the flush logic and free the queued chunk.

Impact

A malicious WebSocket server could cause libcurl to deliver bytes from reused heap storage to the application's write callback, though no peer-visible leak or code execution was demonstrated and the client must use the specific callback pattern.

What the attacker needed

Application pauses and resumes in debug callback; verbose tracing enabled; malicious WebSocket server

The fix

The report supplies a patch adding guards and a regression test, but does not state that it was merged or released.

How it was found

  1. Build static libcurl from the 8.23.0 tag with WebSockets and verbose strings enabled.
  2. Run the supplied client, server and script against the vulnerable build to observe changed output.
  3. Rebuild the same tag with AddressSanitizer and run the script again to see the use-after-free report.
  4. Apply the supplied patch, rebuild, and run the script to confirm clean output.

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 data arrives over a WebSocket, libcurl stores it in a queue and hands it to the program. If the program pauses and immediately resumes the transfer from a logging callback, libcurl frees that queued data while still reading from it. The program then receives bytes from memory that has already been released, so the data can be wrong.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by rat5ak

View all

3 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.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.