From 0a6453ffb8866e453390f7c3848c679e567b9c69 Mon Sep 17 00:00:00 2001 From: Subash Date: Fri, 13 Mar 2026 07:58:47 +0530 Subject: [PATCH] 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 --- pkg/channels/line/line.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/channels/line/line.go b/pkg/channels/line/line.go index b36350a06..5b1caff18 100644 --- a/pkg/channels/line/line.go +++ b/pkg/channels/line/line.go @@ -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) {