fix(api): reject NaN/Inf in min-savings query params#1233
Conversation
|
Warning Review limit reached
More reviews will be available in 11 minutes and 32 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR tightens validation in ChangesNon-finite input validation for min_savings parameter
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
parseMinSavingsParam used strconv.ParseFloat, which accepts "NaN", "Inf", "+Inf" and "Infinity" (case-insensitively), and only rejected v < 0, which is false for NaN. A NaN min_savings_usd bound into "monthly_savings >= $n" excludes every row with HTTP 200, and a NaN min_savings_pct is a silent no-op floor. Reject non-finite values at the input boundary with a 400 client error instead, per the fail-loud policy. Extends TestParseMinSavingsParam with NaN, +Inf, -Inf, bare/word infinity, and pct-path cases; the new cases fail on the pre-fix code. Closes #1183
|
@coderabbitai review |
Rate Limit Exceeded
|
Adversarial review (PR #1233)Reviewed against the brief's risk surfaces (input vs output layer, sibling float params, SQL-injection adjacent, FE pass-through, status-code class, fail-loud semantics, test coverage). The fix is correct, complete-in-scope, and the only follow-up is defense-in-depth on the FE side, filed separately. Nothing blocking. Verified
Out of scope, filed as follow-ups
CI UNSTABLE state
VerdictLGTM. CR re-ping posted. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Problem
parseMinSavingsParam(internal/api/validation.go) parses themin_savings_usd/min_savings_pctquery parameters withstrconv.ParseFloat, which acceptsNaN,Inf,+InfandInfinity(case-insensitively). The only guard wasv < 0, which is false for NaN. Downstream:min_savings_usdbound intomonthly_savings >= $nexcludes every row, returning an empty list with HTTP 200 instead of a 400min_savings_pctmakespct < filter.MinSavingsPctalways false, a silently inert floor+Infexcludes everythingReview finding COR-09 (docs/reviews/codebase-review-2026-06-10.md). Closes #1183.
Fix
Reject non-finite values at the input boundary:
err != nil || math.IsNaN(v) || math.IsInf(v, 0)now returns a 400 client error ("must be a finite non-negative number"). Negative finite values keep their existing 400. Docstring updated to state the non-finite rejection.Test evidence
Extended
TestParseMinSavingsParamwith table cases forNaN,nan,+Inf,Inf,Infinity,-Inf, and the pct-path (min_savings_pct) variants.go test ./internal/api/ -run TestParseMinSavingsParampasses (20 subtests)go test ./internal/api/passes (1635 tests);go build ./...cleanSummary by CodeRabbit
Bug Fixes
Tests