Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2026-10-06 - Missing Write Deadline Due to Dynamic App Delays
**Vulnerability:** The HTTP server lacked a write deadline (write timeout) when no artificial response delay was configured. This omission left the application vulnerable to Slow Read Denial of Service (DoS) attacks, where an attacker could slowly read responses and hold server connections open indefinitely.
**Learning:** `http.Server.WriteTimeout` cannot be used safely if the application intends to hold requests open intentionally (e.g., simulating a 30s delay response or holding a long-poll connection). If `WriteTimeout` is set on the server, it enforces a hard global timeout. Therefore, `WriteTimeout` was omitted, but doing so without alternative dynamic deadlines leaves endpoints unprotected.
**Prevention:** When building servers that simulate long delays or handle long-polling, standard `http.Server` timeouts may be too restrictive. Instead of removing write deadlines completely, use `http.NewResponseController(w).SetWriteDeadline(...)` per-request to enforce a timeout that accommodates the expected specific response delay (e.g., `time.Now().Add(expectedDelay + 30*time.Second)`).
3 changes: 2 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
})

if s.opts.CORS && isPreflight(r) {
_ = http.NewResponseController(w).SetWriteDeadline(time.Now().Add(30 * time.Second))
resp := events.Response{Status: http.StatusNoContent, Headers: corsHeaders(r, true)}
write(w, resp)
s.store.Complete(id, resp, time.Since(start))
return
}

resp := s.resp.Render()
_ = http.NewResponseController(w).SetWriteDeadline(time.Now().Add(resp.Delay + 30*time.Second))
if resp.Delay > 0 {
_ = http.NewResponseController(w).SetWriteDeadline(time.Now().Add(resp.Delay + 30*time.Second))
timer := time.NewTimer(resp.Delay)
defer timer.Stop()
select {
Expand Down
Loading