mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-17 10:59:39 +00:00
Fix CRLF injection in chunked response trailers
Trailer field names and values written by write_content_chunked()'s done_with_trailer lambda were never validated, unlike every other header output path (set_header, WebSocket handshake, client request headers). An application reflecting untrusted input into a trailer via DataSink::done_with_trailer() could inject CR/LF sequences and achieve HTTP response splitting. Skip trailer fields with invalid names or values, matching the silent-skip behavior of set_header().
This commit is contained in:
1 parent
0fa4912891
commit
568d434e72
2 files changed
+63
No files matched your search
@@ -7721,6 +7721,12 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
|
||||
// Trailer
|
||||
if (trailer) {
|
||||
for (const auto &kv : *trailer) {
|
||||
// Skip fields with invalid names or values to prevent response
|
||||
// splitting via CR/LF injection, matching set_header().
|
||||
if (!fields::is_field_name(kv.first) ||
|
||||
!fields::is_field_value(kv.second)) {
|
||||
continue;
|
||||
}
|
||||
std::string field_line = kv.first + ": " + kv.second + "\r\n";
|
||||
if (!write_data(strm, field_line.data(), field_line.size())) {
|
||||
ok = false;
|
||||
|
||||
Reference in new issue
Block a user