36: HTTP upload resume offset consumed twice after early 307/308 redirect
A libcurl bug causes a resumed HTTP upload to skip the resume offset twice when a 307 or 308 redirect arrives before the body is sent, so the followed request uploads data from the wrong region of the source. The caller gets a success return code and cannot tell that the wrong bytes were sent.
Originally disclosed on HackerOne
- Disclosed after 12 days
Summary
A read-backed HTTP POST using CURLOPT_RESUME_FROM_LARGE with a non-seekable source silently uploads the wrong data when the server returns a 307 or 308 redirect before the request body is sent. curl_easy_perform() returns CURLE_OK, so the caller cannot detect the substitution.
The bug is in cr_in_resume_from() (lib/sendf.c): when it falls back to reading-and-discarding through ctx->read_cb (no seek callback available), it does not set ctx->has_used_cb. On redirect, cr_in_needs_rewind() checks only that flag and reports no rewind needed. A fresh reader is created and http_resume() applies the persistent resume_from offset a second time. For a source of configured size N and offset O, the followed request sends N−O bytes starting at source offset 2O instead of O.
Introduced by commit 14bcea074a ("lib: enhance client reader resume + rewind"), present since curl 8.7.0. Tested against commit c2676bf9e639.
Root cause detail
-
cr_in_resume_from()atlib/sendf.c:798-820invokesctx->read_cbto skip past the offset but never setsctx->has_used_cb = TRUE. The normal read path at line 687 does set it. -
cr_in_needs_rewind()atlib/sendf.c:755-760returns onlyctx->has_used_cb, sohttp_perhapsrewind()concludes no rewind is needed. -
http_resume()atlib/http.c:2400guards with!data->req.authnegand a comment saying "only act on the first request," but that condition does not exclude redirects. On the followed 308,set_reader()+http_resume()runs again (lines 3112-3116) and applies the offset a second time.
Reproduction
Prerequisites
Docker and a curl source tree at commit c2676bf9e639 or later (the bug is still present on HEAD).
Steps
- Build curl from source at commit
c2676bf9e639(or any commit since 8.7.0):
cmake -S . -B build \
-DBUILD_SHARED_LIBS=ON -DBUILD_CURL_EXE=OFF -DBUILD_TESTING=OFF \
-DCURL_USE_OPENSSL=OFF -DCURL_USE_LIBPSL=OFF -DCURL_ZLIB=OFF
cmake --build build -j$(nproc)
- Compile the client:
cc client.c -Iinclude -Lbuild/lib -lcurl -o poc-client
- Start the server:
python3 -u server.py &
- Run the client:
LD_LIBRARY_PATH=build/lib ./poc-client
Expected output (fixed curl)
The sink receives 4096 bytes of B (byte value 66), curl_easy_perform returns 0, and the callback consumes 8192 bytes total (4096 skipped + 4096 sent).
Actual output (vulnerable curl)
SINK_LENGTH=4096
SINK_BYTE_VALUES=[67]
VERDICT=VULNERABLE
CURL_RESULT=0
SOURCE_BYTES_CONSUMED=12288
The sink receives 4096 bytes of C (byte value 67). The callback consumed 12288 bytes: the offset was applied twice (4096 skipped on first request + 4096 skipped again on redirected request + 4096 C bytes sent). curl_easy_perform returns CURLE_OK.
Suggested fix
Set ctx->has_used_cb = TRUE in cr_in_resume_from() when the fallback read-and-discard path invokes ctx->read_cb. This makes cr_in_needs_rewind() return true after resume, so redirect handling requests a rewind. Seekable sources rewind and reapply the offset once; non-seekable sources fail with CURLE_SEND_FAIL_REWIND instead of silently uploading the wrong interval.
I am aware that docs/cmdline-opts/continue-at.md describes HTTP upload resume as non-standard and "not guaranteed." The issue here is the local reader-position bookkeeping and the silent wrong-body success, not server-side interoperability.
Impact
A malicious or misconfigured server returning an early body-preserving redirect causes libcurl to upload bytes from a different region of the application's upload source while reporting success. The caller has no indication that the wrong data was sent.
Constraints:
- Requires a read-backed POST/PUT with a positive resume offset.
- The source must lack a seek callback (non-seekable).
CURLOPT_FOLLOWLOCATIONmust be enabled (off by default in libcurl).- The server must return 307/308 before the body is sent.
- The read callback must be able to supply data beyond the configured upload size.
Does not read arbitrary process memory; the extra bytes come from the application's own read callback.
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 resume helper that skips bytes by reading and discarding them never marks the reader as having used the callback, so the redirect logic believes no rewind is needed and applies the resume offset again on the followed request.
Impact
A malicious or misconfigured server could make libcurl upload bytes from a different part of the application's upload source while reporting success, though this needs a non-seekable source, a positive resume offset, follow-location enabled and an early 307/308 redirect.
What the attacker needed
Read-backed POST or PUT; positive resume offset; source without a seek callback; follow-location enabled
The fix
The resume helper should mark the reader as having used the callback so a rewind is requested; seekable sources then reapply the offset once and non-seekable sources fail instead of sending the wrong data.
How it was found
- Build curl from source at the stated commit.
- Compile the proof-of-concept client against the built library.
- Start the local test server.
- Run the client and observe the sink contents and consumed byte count.
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 you resume an upload, the program is meant to skip the first part of the file and send the rest. Here, if the server first answers with a redirect (a message telling the client to send the request to another address), the library skips that first part a second time. The upload then finishes without any error, but the server receives the wrong section of the file.
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.