fix(zarinhub): limit upstream response size

This commit is contained in:
2026-09-21 11:30:01 +03:30
parent 14df432175
commit b713a4daf1
2 changed files with 46 additions and 1 deletions

View File

@@ -13,6 +13,8 @@ import (
"card-to-iban/internal/service"
)
const maxResponseBodySize = 1 << 20
type Client struct {
httpClient *http.Client
endpointURL string
@@ -95,7 +97,9 @@ func (c *Client) Convert(
UpstreamHTTPStatus: resp.StatusCode,
}
body, err := io.ReadAll(resp.Body)
body, err := io.ReadAll(
io.LimitReader(resp.Body, maxResponseBodySize+1),
)
if err != nil {
return result,
fmt.Errorf(
@@ -105,6 +109,14 @@ func (c *Client) Convert(
)
}
if len(body) > maxResponseBodySize {
return result,
fmt.Errorf(
"%w: response body is too large",
ErrInvalidResponse,
)
}
result.RawResponse = body
switch {