fix: limit webhook request body size to 1MB to prevent DoS (closes #1)
This commit is contained in:
@@ -9,6 +9,9 @@ import (
|
||||
"git.eeqj.de/sneak/upaas/internal/models"
|
||||
)
|
||||
|
||||
// maxWebhookBodySize is the maximum allowed size of a webhook request body (1MB).
|
||||
const maxWebhookBodySize = 1 << 20
|
||||
|
||||
// HandleWebhook handles incoming Gitea webhooks.
|
||||
func (h *Handlers) HandleWebhook() http.HandlerFunc {
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
@@ -38,8 +41,8 @@ func (h *Handlers) HandleWebhook() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// Read request body
|
||||
body, readErr := io.ReadAll(request.Body)
|
||||
// Read request body with size limit to prevent memory exhaustion
|
||||
body, readErr := io.ReadAll(io.LimitReader(request.Body, maxWebhookBodySize))
|
||||
if readErr != nil {
|
||||
h.log.Error("failed to read webhook body", "error", readErr)
|
||||
http.Error(writer, "Bad Request", http.StatusBadRequest)
|
||||
|
||||
Reference in New Issue
Block a user