Browse Source

fix: byte misalignment in endpoint service

Yeuoly 7 months ago
parent
commit
f385089d7f
1 changed files with 13 additions and 2 deletions
  1. 13 2
      internal/service/endpoint.go

+ 13 - 2
internal/service/endpoint.go

@@ -6,6 +6,7 @@ import (
 	"encoding/hex"
 	"errors"
 	"fmt"
+	"io"
 	"sync/atomic"
 	"time"
 
@@ -40,11 +41,21 @@ func Endpoint(
 	req := ctx.Request.Clone(context.Background())
 	req.URL.Path = path
 
-	var buffer bytes.Buffer
-	err := req.Write(&buffer)
+	// read request body until complete, max 10MB
+	body, err := io.ReadAll(io.LimitReader(req.Body, 10*1024*1024))
+	if err != nil {
+		ctx.JSON(500, exception.InternalServerError(err).ToResponse())
+		return
+	}
 
+	var buffer bytes.Buffer
+	req.Body = io.NopCloser(bytes.NewReader(body))
+	req.ContentLength = int64(len(body))
+	req.TransferEncoding = nil
+	err = req.Write(&buffer)
 	if err != nil {
 		ctx.JSON(500, exception.InternalServerError(err).ToResponse())
+		return
 	}
 
 	identifier, err := plugin_entities.NewPluginUniqueIdentifier(pluginInstallation.PluginUniqueIdentifier)