fix(libhttp): 服务器读超时防 Slowloris (P1-4)

- 新增 setHeaderTimeout()(default 10s) / setReadTimeout()(default 30s),对齐 WAF
- doSSLHandshake 设置头超时覆盖握手,doRead 拆分为 async_read_header (头超时) + async_read (体超时)
- doWsRead 每次读取设置空闲超时,自动清理长期空闲连接
- 更新审计文档 P1-4 状态、README v3.4.2
This commit is contained in:
qing committed 2026-08-04 17:39:27 +08:00
1 parent 507054c4b2
commit 37c6d401d6
6 files changed
+64 -4

No files matched your search

+10
View File
@@ -21,6 +21,7 @@
#include <mutex>
#include <regex>
#include <deque>
#include <chrono>
namespace pmc {
namespace net {
@@ -124,6 +125,13 @@ public:
void setMaxWsMessageSize(std::size_t bytes) { max_ws_message_size_ = bytes; }
std::size_t getMaxWsMessageSize() const { return max_ws_message_size_; }
// 入站读超时(防 Slowloris,P1-4)。默认与 WAF 对齐:头 10s、体 30s。
// 头超时覆盖 TCP 连接建立 + SSL 握手 + 请求头读取;体超时覆盖请求体读取。
void setHeaderTimeout(std::chrono::seconds t) { header_timeout_ = t; }
std::chrono::seconds getHeaderTimeout() const { return header_timeout_; }
void setReadTimeout(std::chrono::seconds t) { read_timeout_ = t; }
std::chrono::seconds getReadTimeout() const { return read_timeout_; }
class debug {
public:
static void print_all_header_fields(const http::request<http::string_body>& req);
@@ -140,6 +148,8 @@ private:
std::size_t max_body_size_ = 10 * 1024 * 1024; // 默认 10MB,与 WAF 对齐
std::size_t max_ws_message_size_ = 16 * 1024 * 1024; // 默认 16MB,与 Beast 默认一致
std::chrono::seconds header_timeout_{10}; // 头/握手超时,防 Slowloris(对齐 WAF ReadHeaderTimeout)
std::chrono::seconds read_timeout_{30}; // 体超时(对齐 WAF ReadTimeout)
bool ssl_enabled_{false};
std::string cert_file_;