Commit 53c4851
fix(mcp): set http server timeouts to close pre-auth slowloris hole (#214)
## Summary
- Adds `ReadHeaderTimeout` (10s), `ReadTimeout` (60s), `IdleTimeout`
(120s), and `MaxHeaderBytes` (1 MiB) to the MCP HTTP server, sourced
from named constants in the existing `const(...)` block alongside
`httpShutdownTimeout`.
- Leaves `WriteTimeout` at its zero value (intentional, commented): the
streamable HTTP transport keeps responses open for long-running POSTs
and SSE GETs; a server-wide cap would truncate them. Slow-read defense
belongs in the streaming handler's per-write deadlines.
- Adds `TestRunHttp_ReadHeaderTimeout_ClosesSlowClient` — opens a TCP
conn, writes a partial request line, asserts the server closes the
connection within `ReadHeaderTimeout + 3s` and rejects false positives
where the client-side read deadline (set well beyond the server's
window) fires first.
Closes #205.
## Test plan
- [x] `make build` clean
- [x] `make test` green (38 packages; `pkg/mcp` 10.7s incl. new
Slowloris regression test)
- [x] `gofmt -l pkg/mcp/` empty
- [x] `go vet ./...` clean
- [x] Codex review converged at pass 3 (caught the `WriteTimeout`
streaming-truncation issue + the test client-deadline false-positive —
both fixed before merge)
- [x] `go-style-reviewer` subagent: zero findings against
`.claude/rules/go-concise.md`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent efcb9a5 commit 53c4851
2 files changed
Lines changed: 78 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
52 | 66 | | |
53 | 67 | | |
54 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
207 | 267 | | |
208 | 268 | | |
209 | 269 | | |
| |||
0 commit comments