fix(waf): harden against OOM and Slowloris DoS attacks
- P0: add 10MB hard request body size limit with io.LimitReader, return 413 Request Entity Too Large when exceeded, prevents OOM - P0: configure http.Server timeouts: ReadHeaderTimeout=10s (Slowloris), ReadTimeout=15s, WriteTimeout=30s, IdleTimeout=120s, MaxHeaderBytes=1MB - P1: properly handle body read errors, log and return on client disconnect - P2: drain and close r.Body in defer to ensure TCP connection reuse - Log errors from ReadRequestBodyFrom and ProcessRequestBody - Inject security headers on 413 responses - Add security audit report (docs/SECURITY_AUDIT_20260801.md) - Update README with timeout/body-limit docs and changelog
This commit is contained in:
1 parent
bd544a4181
commit
b4436b192a
4 files changed
+430
-15
No files matched your search
+8
-2
@@ -22,6 +22,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
@@ -108,8 +109,13 @@ func main() {
|
||||
}()
|
||||
|
||||
server := &http.Server{
|
||||
Addr: cfg.Listen,
|
||||
Handler: p,
|
||||
Addr: cfg.Listen,
|
||||
Handler: p,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
ReadHeaderTimeout: 10 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20, // 1MB
|
||||
TLSConfig: &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user