diff --git a/internal/api/docker_metadata.go b/internal/api/docker_metadata.go index 579a819..7ebe590 100644 --- a/internal/api/docker_metadata.go +++ b/internal/api/docker_metadata.go @@ -78,6 +78,9 @@ func (h *DockerMetadataHandler) HandleUpdateMetadata(w http.ResponseWriter, r *h return } + // Limit request body to 16KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 16*1024) + var meta config.DockerMetadata if err := json.NewDecoder(r.Body).Decode(&meta); err != nil { http.Error(w, "Invalid request body", http.StatusBadRequest) diff --git a/internal/api/guest_metadata.go b/internal/api/guest_metadata.go index 8631424..3a56722 100644 --- a/internal/api/guest_metadata.go +++ b/internal/api/guest_metadata.go @@ -83,6 +83,9 @@ func (h *GuestMetadataHandler) HandleUpdateMetadata(w http.ResponseWriter, r *ht return } + // Limit request body to 16KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 16*1024) + var meta config.GuestMetadata if err := json.NewDecoder(r.Body).Decode(&meta); err != nil { http.Error(w, "Invalid request body", http.StatusBadRequest) diff --git a/internal/api/host_agents.go b/internal/api/host_agents.go index 7931ded..2fdad40 100644 --- a/internal/api/host_agents.go +++ b/internal/api/host_agents.go @@ -37,6 +37,8 @@ func (h *HostAgentHandlers) HandleReport(w http.ResponseWriter, r *http.Request) return } + // Limit request body to 256KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 256*1024) defer r.Body.Close() var report agentshost.Report diff --git a/internal/api/notification_queue.go b/internal/api/notification_queue.go index 99184d9..2d04ffa 100644 --- a/internal/api/notification_queue.go +++ b/internal/api/notification_queue.go @@ -85,6 +85,9 @@ func (h *NotificationQueueHandlers) RetryDLQItem(w http.ResponseWriter, r *http. return } + // Limit request body to 8KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 8*1024) + var request struct { ID string `json:"id"` } @@ -129,6 +132,9 @@ func (h *NotificationQueueHandlers) DeleteDLQItem(w http.ResponseWriter, r *http return } + // Limit request body to 8KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 8*1024) + var request struct { ID string `json:"id"` } diff --git a/internal/api/system_settings.go b/internal/api/system_settings.go index ab56443..2e5e288 100644 --- a/internal/api/system_settings.go +++ b/internal/api/system_settings.go @@ -462,6 +462,9 @@ func (h *SystemSettingsHandler) HandleUpdateSystemSettings(w http.ResponseWriter existingSettings = config.DefaultSystemSettings() } + // Limit request body to 64KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 64*1024) + // Read the request body into a map to check which fields were provided var rawRequest map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&rawRequest); err != nil { diff --git a/internal/api/temperature_proxy.go b/internal/api/temperature_proxy.go index c5021ba..135b686 100644 --- a/internal/api/temperature_proxy.go +++ b/internal/api/temperature_proxy.go @@ -176,6 +176,8 @@ func (h *TemperatureProxyHandlers) HandleRegister(w http.ResponseWriter, r *http return } + // Limit request body to 8KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 8*1024) defer r.Body.Close() var req struct { diff --git a/internal/api/updates.go b/internal/api/updates.go index 4d12158..8f382d7 100644 --- a/internal/api/updates.go +++ b/internal/api/updates.go @@ -83,6 +83,9 @@ func (h *UpdateHandlers) HandleApplyUpdate(w http.ResponseWriter, r *http.Reques return } + // Limit request body to 8KB to prevent memory exhaustion + r.Body = http.MaxBytesReader(w, r.Body, 8*1024) + var req struct { DownloadURL string `json:"downloadUrl"` }