fix(syncer): accept rest api response without size limit (#21702)

This commit is contained in:
ciel authored and GitHub committed 2026-10-29 19:50:36 +08:00
1 parent e1511aea11
commit c49a828e4e
1 file changed
+7 -2
+7 -2
View File
@@ -17,6 +17,7 @@
package connector
import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -87,6 +88,7 @@ const (
restAPIDefaultRequestDelay = 0.5
restAPIRequestTimeout = 60 * time.Second
restAPIMaxRedirects = 5
restAPIMaxResponseBytes = int64(32 * 1024 * 1024)
)
const (
@@ -727,11 +729,14 @@ func (c *RestAPIConnector) handleResponse(resp *http.Response) (any, error) {
return nil, fmt.Errorf("REST API request failed with http %d", status)
}
raw, err := io.ReadAll(resp.Body)
raw, err := io.ReadAll(io.LimitReader(resp.Body, restAPIMaxResponseBytes+1))
if err != nil {
return nil, err
}
decoder := json.NewDecoder(strings.NewReader(string(raw)))
if int64(len(raw)) > restAPIMaxResponseBytes {
return nil, &ConnectorValidationError{Message: fmt.Sprintf("REST API response exceeds the %d byte limit", restAPIMaxResponseBytes)}
}
decoder := json.NewDecoder(bytes.NewReader(raw))
decoder.UseNumber()
var value any
if err := decoder.Decode(&value); err != nil {