fix(api): guard out-of-range numeric since on /api/pulls#234
Conversation
parseSinceIso took the numeric branch for any finite `since > 0` and called new Date(sinceMs).toISOString() without validating the result. A finite but out-of-range epoch (e.g. ?since=1e21 or a 20-digit integer) produces an Invalid Date, and Date.prototype.toISOString() throws RangeError on it, so the request crashed with an unhandled 500 instead of being treated as a malformed filter. Validate the millisecond date before formatting, mirroring the guard already applied to the date-string branch, so an out-of-range `since` falls through to null (no filter) like other malformed input.
|
Warning Review limit reached
More reviews will be available in 4 minutes and 43 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 We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
/api/pulls?since=...could crash with an unhandledRangeErroron a malformedsincevalue.parseSinceIsotook the numeric branch for any finitesince > 0and callednew Date(sinceMs).toISOString()without validating the result. A finite but out-of-range epoch (e.g.?since=1e21, or a 20-digit integer) produces an Invalid Date, andDate.prototype.toISOString()throwsRangeError: Invalid time valueon it — so the route returned a 500 instead of treating it as a bad filter.The date-string branch right below already guards with
Number.isFinite(sinceDate.getTime()); this applies the same guard to the numeric branch, so an out-of-rangesincefalls through tonull(no filter), consistent with how other malformed input is handled.Related Issues
No issue; small input-robustness fix in the same vein as the existing malformed-input handling.
Type of Change
Testing
pnpm buildpassesRan from the repo root (Node 22, pnpm 10):
Reproduced the bug and confirmed the fix against the isolated
parseSinceIsologic:Checklist