[MEDIUM] HTTP Server 缺少超时配置:Slowloris DoS 攻击风险 #11

Closed
opened 2026-04-30 03:55:59 +08:00 by lan · 0 comments
Owner

漏洞描述

cmd/server/app.go:74-77 创建 http.Server 时未配置任何超时参数:

a.Server = &http.Server{
    Addr:    addr,
    Handler: a.Router.Engine(),
}

缺少 ReadHeaderTimeoutReadTimeoutWriteTimeoutIdleTimeout

风险

Slowloris 攻击:攻击者可以发送不完整的 HTTP 请求(极慢地发送头部),保持连接打开,耗尽服务器的连接池,导致正常用户无法访问。

  • 无需高带宽,单台机器即可造成影响
  • Go 标准库 http.Server 无默认超时保护

修复建议

a.Server = &http.Server{
    Addr:              addr,
    Handler:           a.Router.Engine(),
    ReadHeaderTimeout: 10 * time.Second,  // 读取请求头超时
    ReadTimeout:       30 * time.Second,  // 读取整个请求超时
    WriteTimeout:      60 * time.Second,  // 写入响应超时
    IdleTimeout:       120 * time.Second, // 保持连接空闲超时
}

严重程度

MEDIUM — 低门槛 DoS 攻击向量,建议尽快修复。

## 漏洞描述 `cmd/server/app.go:74-77` 创建 `http.Server` 时未配置任何超时参数: ```go a.Server = &http.Server{ Addr: addr, Handler: a.Router.Engine(), } ``` 缺少 `ReadHeaderTimeout`、`ReadTimeout`、`WriteTimeout` 和 `IdleTimeout`。 ## 风险 **Slowloris 攻击**:攻击者可以发送不完整的 HTTP 请求(极慢地发送头部),保持连接打开,耗尽服务器的连接池,导致正常用户无法访问。 - 无需高带宽,单台机器即可造成影响 - Go 标准库 `http.Server` 无默认超时保护 ## 修复建议 ```go a.Server = &http.Server{ Addr: addr, Handler: a.Router.Engine(), ReadHeaderTimeout: 10 * time.Second, // 读取请求头超时 ReadTimeout: 30 * time.Second, // 读取整个请求超时 WriteTimeout: 60 * time.Second, // 写入响应超时 IdleTimeout: 120 * time.Second, // 保持连接空闲超时 } ``` ## 严重程度 **MEDIUM** — 低门槛 DoS 攻击向量,建议尽快修复。
lan closed this issue 2026-04-30 12:23:20 +08:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: carrot_bbs/backend#11