|
99 | 99 | apiIdleTimeoutMs = cli.GetEnvInt("API_TIMEOUT_IDLE_MS", 3_000) |
100 | 100 | apiWriteTimeoutMs = cli.GetEnvInt("API_TIMEOUT_WRITE_MS", 10_000) |
101 | 101 | apiMaxHeaderBytes = cli.GetEnvInt("API_MAX_HEADER_BYTES", 60_000) |
| 102 | + apiMaxPayloadBytes = cli.GetEnvInt("API_MAX_PAYLOAD_BYTES", 15*1024*1024) // 15 MiB |
102 | 103 |
|
103 | 104 | // api shutdown: wait time (to allow removal from load balancer before stopping http server) |
104 | 105 | apiShutdownWaitDuration = common.GetEnvDurationSec("API_SHUTDOWN_WAIT_SEC", 30) |
@@ -1040,9 +1041,10 @@ func (api *RelayAPI) handleRegisterValidator(w http.ResponseWriter, req *http.Re |
1040 | 1041 | return |
1041 | 1042 | } |
1042 | 1043 |
|
1043 | | - body, err := io.ReadAll(req.Body) |
| 1044 | + limitReader := io.LimitReader(req.Body, int64(apiMaxPayloadBytes)) |
| 1045 | + body, err := io.ReadAll(limitReader) |
1044 | 1046 | if err != nil { |
1045 | | - log.WithError(err).WithField("contentLength", req.ContentLength).Warn("failed to read request body") |
| 1047 | + log.WithError(err).Warn("failed to read request body") |
1046 | 1048 | api.RespondError(w, http.StatusBadRequest, "failed to read request body") |
1047 | 1049 | return |
1048 | 1050 | } |
@@ -1408,7 +1410,8 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) |
1408 | 1410 | } |
1409 | 1411 |
|
1410 | 1412 | // Read the body first, so we can decode it later |
1411 | | - body, err := io.ReadAll(req.Body) |
| 1413 | + limitReader := io.LimitReader(req.Body, int64(apiMaxPayloadBytes)) |
| 1414 | + body, err := io.ReadAll(limitReader) |
1412 | 1415 | if err != nil { |
1413 | 1416 | if strings.Contains(err.Error(), "i/o timeout") { |
1414 | 1417 | log.WithError(err).Error("getPayload request failed to decode (i/o timeout)") |
@@ -2044,7 +2047,7 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque |
2044 | 2047 | } |
2045 | 2048 | } |
2046 | 2049 |
|
2047 | | - limitReader := io.LimitReader(r, 10*1024*1024) // 10 MB |
| 2050 | + limitReader := io.LimitReader(r, int64(apiMaxPayloadBytes)) |
2048 | 2051 | requestPayloadBytes, err := io.ReadAll(limitReader) |
2049 | 2052 | if err != nil { |
2050 | 2053 | log.WithError(err).Warn("could not read payload") |
|
0 commit comments