cpp-httplib is a C++11 single-file header-only cross platform HTTP/HTTPS library. Prior to 0.27.0, a vulnerability allows attacker-controlled HTTP headers to influence server-visible metadata, logging, and authorization decisions. An attacker can inject headers named REMOTE_ADDR, REMOTE_PORT, LOCAL_ADDR, LOCAL_PORT that are parsed into the request header multimap via read_headers() in httplib.h (headers.emplace), then the server later appends its own internal metadata using the same header names in Server::process_request without erasing duplicates. Because Request::get_header_value returns the first entry for a header key (id == 0) and the client-supplied headers are parsed before server-inserted headers, downstream code that uses these header names may inadvertently use attacker-controlled values. Affected files/locations: cpp-httplib/httplib.h (read_headers, Server::process_request, Request::get_header_value, get_header_value_u64) and cpp-httplib/docker/main.cc (get_client_ip, nginx_access_logger, nginx_error_logger). Attack surface: attacker-controlled HTTP headers in incoming requests flow into the Request.headers multimap and into logging code that reads forwarded headers, enabling IP spoofing, log poisoning, and authorization bypass via header shadowing. This vulnerability is fixed in 0.27.0.
The read_headers() function in httplib.h parses all headers of an incoming HTTP request into a shared multimap structure, including headers with names reserved for internal server metadata (REMOTE_ADDR, REMOTE_PORT, LOCAL_ADDR, LOCAL_PORT). Subsequently, Server::process_request appends its own values for these same headers, but without first removing previously inserted entries. Since Request::get_header_value returns the first matching entry (id == 0), and headers supplied by the client are parsed before server metadata, the application code reads values controlled by the attacker instead of actual system values. This also applies to the logging code in docker/main.cc (functions get_client_ip, nginx_access_logger, nginx_error_logger).
An attacker can spoof the client IP address visible on the server side (IP spoofing), poison application logs with injected values (log poisoning), and bypass authorization mechanisms based on these headers (authorization bypass via header shadowing).
The cpp-httplib library should be updated to version 0.27.0 or later, in which the issue was fixed (commit ac9ebb0ee333ce8bf13523f487bdfad9518a2aff). Until an update is applied, it is recommended to implement filtering of incoming request headers at the reverse proxy or WAF level to block headers named REMOTE_ADDR, REMOTE_PORT, LOCAL_ADDR, and LOCAL_PORT before they reach the application.
Yhirose cpp-httplib library (httplib.h) in all versions before 0.27.0
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:NYhirose Cpp Httplib
APPYhirose< 0.27.0
Related vulnerabilities
cpp-httplib: HTTP response splitting poprzez header injection (CRLF injection)
cpp-httplib is a C++11 single-file header-only cross platform HTTP/HTTPS library. Prior to 0.44.0, When the se...
cpp-httplib is a C++11 single-file header-only cross platform HTTP/HTTPS library. Prior to 0.39.0, the cpp-htt...
cpp-httplib is a C++11 single-file header-only cross platform HTTP/HTTPS library. Prior to 0.37.2, when a cpp-...
cpp-httplib is a C++11 single-file header-only cross platform HTTP/HTTPS library. Prior to 0.37.1, when a cpp-...