Skip to content

Commit d219e10

Browse files
committed
Add payload and timeout limits to HTTP/SSE servers
Addresses security audit issue #3: Unbounded request body parsing - Set 10MB max payload length to prevent memory exhaustion - Add 30 second read/write timeouts to prevent slowloris attacks - Applied to both HttpServerWrapper and SseServerWrapper This prevents DoS attacks via large request bodies or slow clients.
1 parent b2b2772 commit d219e10

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/server/http_server.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ bool HttpServerWrapper::start()
2424
if (running_)
2525
return false;
2626
svr_ = std::make_unique<httplib::Server>();
27+
28+
// Security: Set payload and timeout limits to prevent DoS
29+
svr_->set_payload_max_length(10 * 1024 * 1024); // 10MB max payload
30+
svr_->set_read_timeout(30, 0); // 30 second read timeout
31+
svr_->set_write_timeout(30, 0); // 30 second write timeout
32+
2733
// Generic POST: /<route>
2834
svr_->Post(R"(/(.*))",
2935
[this](const httplib::Request& req, httplib::Response& res)

src/server/sse_server.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ bool SseServerWrapper::start()
136136

137137
svr_ = std::make_unique<httplib::Server>();
138138

139+
// Security: Set payload and timeout limits to prevent DoS
140+
svr_->set_payload_max_length(10 * 1024 * 1024); // 10MB max payload
141+
svr_->set_read_timeout(30, 0); // 30 second read timeout
142+
svr_->set_write_timeout(30, 0); // 30 second write timeout
143+
139144
// Set up SSE endpoint (GET)
140145
svr_->Get(sse_path_,
141146
[this](const httplib::Request&, httplib::Response& res)

0 commit comments

Comments
 (0)