#5834: fix(line): add timeout and size limit to readRequestBody to prevent DoS
Cluster:
Timeouts and Memory Management Fixes
## Summary
Fixes #5125 - LINE monitor `readRequestBody()` has no timeout or size limit (CWE-400: Uncontrolled Resource Consumption)
- Add 30-second timeout with `setTimeout`/`clearTimeout` pattern
- Add 1MB size limit to prevent memory exhaustion
- Add `done` flag to prevent race conditions between event handlers
- Add `close` event handler for client disconnect detection
- Call `req.destroy()` to terminate malicious connections
## Attack Vectors Mitigated
1. **Slowloris DoS**: Attacker sends data very slowly to hold connections indefinitely
2. **Memory Exhaustion**: Attacker sends oversized request body to cause OOM
## Implementation Pattern
Follows the same pattern as `readJsonBody()` in `src/gateway/hooks.ts:74-139` which was already correctly implemented.
## Test Plan
- [ ] Existing LINE webhook tests pass
- [ ] Manual test: Send normal webhook request (should work)
- [ ] Manual test: Slow connection times out after 30s
- [ ] Manual test: Large body (>1MB) is rejected
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens the LINE webhook request-body reader by adding a 30s timeout, a 1MB maximum size, and extra safeguards (`done` flag + `close` handling) to prevent slowloris-style hangs and memory exhaustion.
The change is localized to `src/line/monitor.ts` and affects how the webhook handler reads the raw request body before validating the LINE signature and parsing JSON.
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge and improves DoS resilience, with minor behavioral edge cases to consider.
- The change is small and well-scoped, adds clear resource limits, and uses guarded event handlers to avoid double-resolve/reject. Remaining concerns are mostly about semantics (absolute vs inactivity timeout) and returning more appropriate HTTP status codes for body-read failures.
- src/line/monitor.ts
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#6302: fix: Add timeouts to prevent indefinite hangs (issues #4954, #4956,...
by batumilove · 2026-02-01
77.1%
#17678: fix(gateway): expose timeoutMs in readJsonBody to prevent Slowloris...
by mcrolly · 2026-02-16
76.5%
#23621: fix(LINE): keep startAccount promise alive to prevent auto-restart ...
by ttakanawa · 2026-02-22
74.0%
#17182: security(line): fail closed when webhook token/secret are missing
by davidahmann · 2026-02-15
73.6%
#11443: LINE: fix buffer guards in detectContentType + add tests
by MdRahmatUllah · 2026-02-07
71.8%
#21956: fix(line): block monitorLineProvider on abort signal to prevent cra...
by lailoo · 2026-02-20
71.3%
#19763: fix(security): OC-53 enforce prompt size limit to prevent DoS — Aet...
by aether-ai-agent · 2026-02-18
70.1%
#21531: Security/Webhooks: block signed replay for Nextcloud, Google Chat, ...
by bmendonca3 · 2026-02-20
69.8%
#10636: fix: setTimeout integer overflow causing server crash
by devmangel · 2026-02-06
69.7%
#17593: security: fail closed when LINE webhook secret is missing
by davidahmann · 2026-02-15
69.6%