diff --git a/internal/observabilityproxy/metricsparams.go b/internal/observabilityproxy/metricsparams.go index e74d2cbb5..fe9c8aafd 100644 --- a/internal/observabilityproxy/metricsparams.go +++ b/internal/observabilityproxy/metricsparams.go @@ -241,13 +241,18 @@ func parseStep(v string, lim MetricsLimits) (time.Duration, *HTTPError) { return step, nil } +// maxMetricsDuration is vmselect's own bound on step and timeout +// (maxDurationMsecs in lib/httputil); it also keeps the rounding below +// from overflowing. +const maxMetricsDuration = 100 * 365 * 24 * time.Hour + // parseMetricsDuration takes Prometheus float seconds or a duration such as // 1m30s. vmselect works in whole milliseconds and refuses anything shorter; // the value is rounded up to the millisecond so the limits are checked // against what vmselect will use, not against a fraction it drops. func parseMetricsDuration(key, v string) (time.Duration, *HTTPError) { d, err := parseDuration(v) - if err != nil || d < time.Millisecond { + if err != nil || d < time.Millisecond || d > maxMetricsDuration { return 0, errorf(http.StatusBadRequest, "invalid %s %q", key, v) } return (d + time.Millisecond - 1).Truncate(time.Millisecond), nil diff --git a/internal/observabilityproxy/metricsparams_test.go b/internal/observabilityproxy/metricsparams_test.go index ac9ff0ada..fc403191b 100644 --- a/internal/observabilityproxy/metricsparams_test.go +++ b/internal/observabilityproxy/metricsparams_test.go @@ -156,6 +156,8 @@ func TestBuildMetricsParamsLimits(t *testing.T) { {"points at the limit", "api/v1/query_range", rng(ago(10999*time.Minute), ago(0), "1m"), http.StatusOK}, {"points above the limit", "api/v1/query_range", rng(ago(11000*time.Minute), ago(0), "1m"), http.StatusUnprocessableEntity}, {"points above the limit after rounding the step up", "api/v1/query_range", rng(ago(22*time.Second), ago(0), "0.0019"), http.StatusUnprocessableEntity}, + {"overflowing step", "api/v1/query_range", rng(ago(time.Hour), ago(0), "2562047h47m16.854775807s"), http.StatusBadRequest}, + {"overflowing timeout", "api/v1/query", url.Values{"query": {"up"}, "timeout": {"2562047h47m16.854775807s"}}, http.StatusBadRequest}, {"step above the range limit", "api/v1/query_range", rng(ago(time.Hour), ago(0), "31d"), http.StatusUnprocessableEntity}, {"zero step", "api/v1/query_range", rng(ago(time.Hour), ago(0), "0"), http.StatusBadRequest}, {"sub-millisecond step", "api/v1/query_range", rng(ago(time.Hour), ago(0), "0.0001"), http.StatusBadRequest},