mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-17 10:59:39 +00:00
Stop percent-decoding HTTP request header values
parse_header() applied decode_path_component() to every header value except Location and Referer, after is_field_value() validation. Wire sequences like %0D%0A passed the check and expanded into literal CR/LF inside stored values, enabling response splitting, log injection, and proxy smuggling. %3D/%2C/%3B also flipped Cookie and X-Forwarded-For boundaries against WAFs inspecting the wire form. RFC 9110 §5.5 specifies header values as opaque octets. Drop the decoding and the Location/Referer special case (originally workarounds for the same auto-decode misbehavior; redundant once decoding stops). Applications that need URI semantics should call decode_uri_component() or decode_path_component() on the result explicitly. Add regression tests covering CRLF injection, %3D/%2C/%3B boundary characters, UTF-8 and %uXXXX sequences, browser-style Referer URLs containing %0A (issue #2033), and the explicit-decode migration pattern.
This commit is contained in:
1 parent
7d5082cc0e
commit
fbb031ed85
2 files changed
+121
-6
No files matched your search
@@ -5016,12 +5016,11 @@ inline bool parse_header(const char *beg, const char *end, T fn) {
|
||||
|
||||
if (!detail::fields::is_field_value(val)) { return false; }
|
||||
|
||||
if (case_ignore::equal(key, "Location") ||
|
||||
case_ignore::equal(key, "Referer")) {
|
||||
fn(key, val);
|
||||
} else {
|
||||
fn(key, decode_path_component(val));
|
||||
}
|
||||
// RFC 9110 §5.5: header field values are opaque octets and MUST NOT be
|
||||
// percent-decoded by the recipient. Applications that need to interpret a
|
||||
// value as a URI component should call httplib::decode_uri_component()
|
||||
// (or decode_path_component()) explicitly.
|
||||
fn(key, val);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user