|
@@ -127,6 +127,10 @@
|
|
|
#define CPPHTTPLIB_HEADER_MAX_LENGTH 8192
|
|
#define CPPHTTPLIB_HEADER_MAX_LENGTH 8192
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+#ifndef CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH
|
|
|
|
|
+#define CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH 32768
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
#ifndef CPPHTTPLIB_HEADER_MAX_COUNT
|
|
#ifndef CPPHTTPLIB_HEADER_MAX_COUNT
|
|
|
#define CPPHTTPLIB_HEADER_MAX_COUNT 100
|
|
#define CPPHTTPLIB_HEADER_MAX_COUNT 100
|
|
|
#endif
|
|
#endif
|
|
@@ -243,6 +247,8 @@ static_assert(CPPHTTPLIB_REQUEST_URI_MAX_LENGTH > 0,
|
|
|
"CPPHTTPLIB_REQUEST_URI_MAX_LENGTH must be positive");
|
|
"CPPHTTPLIB_REQUEST_URI_MAX_LENGTH must be positive");
|
|
|
static_assert(CPPHTTPLIB_HEADER_MAX_LENGTH > 0,
|
|
static_assert(CPPHTTPLIB_HEADER_MAX_LENGTH > 0,
|
|
|
"CPPHTTPLIB_HEADER_MAX_LENGTH must be positive");
|
|
"CPPHTTPLIB_HEADER_MAX_LENGTH must be positive");
|
|
|
|
|
+static_assert(CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH > 0,
|
|
|
|
|
+ "CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH must be positive");
|
|
|
static_assert(CPPHTTPLIB_HEADER_MAX_COUNT > 0,
|
|
static_assert(CPPHTTPLIB_HEADER_MAX_COUNT > 0,
|
|
|
"CPPHTTPLIB_HEADER_MAX_COUNT must be positive");
|
|
"CPPHTTPLIB_HEADER_MAX_COUNT must be positive");
|
|
|
static_assert(CPPHTTPLIB_MAX_LINE_LENGTH > 0,
|
|
static_assert(CPPHTTPLIB_MAX_LINE_LENGTH > 0,
|
|
@@ -9224,7 +9230,8 @@ inline void erase_invalid_fields(Headers &headers) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-inline bool read_headers(Stream &strm, Headers &headers) {
|
|
|
|
|
|
|
+inline bool read_headers(Stream &strm, Headers &headers,
|
|
|
|
|
+ size_t max_field_length) {
|
|
|
const auto bufsiz = 2048;
|
|
const auto bufsiz = 2048;
|
|
|
char buf[bufsiz];
|
|
char buf[bufsiz];
|
|
|
stream_line_reader line_reader(strm, buf, bufsiz);
|
|
stream_line_reader line_reader(strm, buf, bufsiz);
|
|
@@ -9249,7 +9256,7 @@ inline bool read_headers(Stream &strm, Headers &headers) {
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }
|
|
|
|
|
|
|
+ if (line_reader.size() > max_field_length) { return false; }
|
|
|
|
|
|
|
|
// Check header count limit
|
|
// Check header count limit
|
|
|
if (header_count >= CPPHTTPLIB_HEADER_MAX_COUNT) { return false; }
|
|
if (header_count >= CPPHTTPLIB_HEADER_MAX_COUNT) { return false; }
|
|
@@ -9334,7 +9341,7 @@ inline bool read_response_head(Stream &strm, int &status, Headers &headers) {
|
|
|
if (!parse_status_line(line_reader.ptr(), version, status, reason)) {
|
|
if (!parse_status_line(line_reader.ptr(), version, status, reason)) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
- return read_headers(strm, headers);
|
|
|
|
|
|
|
+ return read_headers(strm, headers, CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
inline bool
|
|
@@ -16221,7 +16228,7 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Request headers
|
|
// Request headers
|
|
|
- if (!detail::read_headers(strm, req.headers)) {
|
|
|
|
|
|
|
+ if (!detail::read_headers(strm, req.headers, CPPHTTPLIB_HEADER_MAX_LENGTH)) {
|
|
|
connection_closed = true;
|
|
connection_closed = true;
|
|
|
res.status = StatusCode::BadRequest_400;
|
|
res.status = StatusCode::BadRequest_400;
|
|
|
output_error_log(Error::InvalidHeaders, &req);
|
|
output_error_log(Error::InvalidHeaders, &req);
|
|
@@ -17025,7 +17032,10 @@ inline bool ClientImpl::read_response_line(Stream &strm, const Request &req,
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
Headers interim_headers;
|
|
Headers interim_headers;
|
|
|
- if (!detail::read_headers(strm, interim_headers)) { return false; }
|
|
|
|
|
|
|
+ if (!detail::read_headers(strm, interim_headers,
|
|
|
|
|
+ CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
if (!line_reader.getline()) { return false; } // next response line
|
|
if (!line_reader.getline()) { return false; } // next response line
|
|
|
|
|
|
|
|
if (!detail::parse_status_line(line_reader.ptr(), res.version, res.status,
|
|
if (!detail::parse_status_line(line_reader.ptr(), res.version, res.status,
|
|
@@ -17315,7 +17325,8 @@ inline ClientImpl::StreamHandle ClientImpl::open_stream_(Request &req) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!read_response_line(strm, req, *handle.response) ||
|
|
if (!read_response_line(strm, req, *handle.response) ||
|
|
|
- !detail::read_headers(strm, handle.response->headers)) {
|
|
|
|
|
|
|
+ !detail::read_headers(strm, handle.response->headers,
|
|
|
|
|
+ CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH)) {
|
|
|
handle.error = Error::Read;
|
|
handle.error = Error::Read;
|
|
|
handle.response.reset();
|
|
handle.response.reset();
|
|
|
return handle;
|
|
return handle;
|
|
@@ -18349,7 +18360,8 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
|
|
|
// When using Expect: 100-continue, don't auto-skip `100 Continue` response
|
|
// When using Expect: 100-continue, don't auto-skip `100 Continue` response
|
|
|
if ((!status_line_read &&
|
|
if ((!status_line_read &&
|
|
|
!read_response_line(strm, req, res, !expect_100_continue)) ||
|
|
!read_response_line(strm, req, res, !expect_100_continue)) ||
|
|
|
- !detail::read_headers(strm, res.headers)) {
|
|
|
|
|
|
|
+ !detail::read_headers(strm, res.headers,
|
|
|
|
|
+ CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH)) {
|
|
|
if (write_request_success) { error = Error::Read; }
|
|
if (write_request_success) { error = Error::Read; }
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -18366,7 +18378,8 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
|
|
|
res.headers.clear();
|
|
res.headers.clear();
|
|
|
res.body.clear();
|
|
res.body.clear();
|
|
|
if (!read_response_line(strm, req, res) ||
|
|
if (!read_response_line(strm, req, res) ||
|
|
|
- !detail::read_headers(strm, res.headers)) {
|
|
|
|
|
|
|
+ !detail::read_headers(strm, res.headers,
|
|
|
|
|
+ CPPHTTPLIB_RESPONSE_HEADER_MAX_LENGTH)) {
|
|
|
error = Error::Read;
|
|
error = Error::Read;
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|