fix(line): add request body size limit to webhook handler
Prevent unauthenticated DoS via unbounded io.ReadAll on webhook request body. Apply the same io.LimitReader pattern used by the WeCom channel (4 MB cap) to reject oversized POST payloads before signature verification or JSON parsing. Fixes #1407
This commit is contained in:
parent
3bcbfd99b9
commit
0a6453ffb8
1 changed files with 7 additions and 1 deletions
|
|
@ -166,7 +166,9 @@ func (c *LINEChannel) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
// Limit request body to 4 MB to prevent memory exhaustion (DoS).
|
||||
const maxBodySize = 4 << 20 // 4 MB
|
||||
body, err := io.ReadAll(io.LimitReader(r.Body, maxBodySize+1))
|
||||
if err != nil {
|
||||
logger.ErrorCF("line", "Failed to read request body", map[string]any{
|
||||
"error": err.Error(),
|
||||
|
|
@ -174,6 +176,10 @@ func (c *LINEChannel) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if len(body) > maxBodySize {
|
||||
http.Error(w, "Request body too large", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
|
||||
signature := r.Header.Get("X-Line-Signature")
|
||||
if !c.verifySignature(body, signature) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue