Repository navigation
feat(postgrest): add URL length validation and timeout protection - #2078
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds optional request timeout support to PostgrestClient (wraps fetch with AbortController), threads a configurable URL length limit through builders, and enhances client-side error objects (AbortError and headers-overflow) with hints and codes; includes tests and TS lib updates. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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 |
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
8adab00 to
61abc1a
Compare
61abc1a to
04f162a
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/postgrest-js/src/PostgrestBuilder.ts (1)
229-283: Avoid empty-string hint/code for generic fetch errors.When errors aren’t Abort/HeadersOverflow,
hint/codebecome empty strings, which is a behavior change vs. “not present” and can trip strict checks. Consider keeping themnullunless explicitly set.💡 Suggested change
- let hint = '' - let code = '' + let hint: string | null = null + let code: string | null = null ... - hint: hint, - code: code, + hint, + code,
🤖 Fix all issues with AI agents
In `@packages/core/postgrest-js/src/PostgrestClient.ts`:
- Around line 84-109: The abort-signal listener added in PostgrestClient (inside
the this.fetch wrapper where AbortController, originalFetch and existingSignal
are used) can leak if the same AbortSignal is reused; update the code to (1)
register the listener with the options { once: true } and capture the listener
function reference, and (2) ensure you remove that listener in the finally block
that clears timeoutId (so the listener is explicitly removed if the fetch
completes before the signal fires). Locate the existing addEventListener call on
existingSignal and modify it to use a named handler plus { once: true } and
removeEventListener(handler) in the finally that wraps the originalFetch call.
In `@packages/core/postgrest-js/test/timeout-and-url-length.test.ts`:
- Around line 124-145: The test fails because the AbortController's signal isn't
passed into the query and the mock fetch ignores the init.signal; update the
test so the query uses the controller's signal via the query builder's
abortSignal(...) (call .abortSignal(controller.signal) on
postgrest.from('users').select()), and change the fastFetch mock (the local
fastFetch function used by PostgrestClient) to inspect init?.signal and
immediately return a rejected promise with an aborted DOMException (or a
rejected Error with name 'AbortError') if init.signal?.aborted or attach an
'abort' listener to reject when signaled, so the request actually aborts and the
expected error is produced.
In `@packages/core/postgrest-js/tsconfig.json`:
- Around line 12-13: The tsconfig.json is inconsistent: "lib" is ES2022 while
"target" remains ES2017; update the "target" compiler option value to "ES2022"
so it matches the "lib" setting and the repo's TypeScript config convention,
ensuring the compiler emits code compatible with ES2022 features referenced by
the lib.
Could we instead have the above protection for the whole URL? Because this can also happen when filters are too large: |
|
And when filters are too large, we can give a hint to solve the error by using RPC to send the values. |
Could we leave I think leaving it empty should be fine as it's a pure client-side error. |
a18d394 to
a65493f
Compare
a65493f to
37b032d
Compare
Problem
When users create queries with very long field lists (10k+ characters), requests can hang indefinitely instead of returning an error. This occurs because:
Content-Locationresponse headersSolution
This PR implements three defensive changes to prevent indefinite hangs and improve developer experience:
1. URL Length Warning (PostgrestQueryBuilder.ts)
selectparameter exceeds 8000 characters2. Timeout Option (PostgrestClient.ts)
timeoutparameter in constructor3. Enhanced Error Messages (PostgrestBuilder.ts)
PGRST_TIMEOUTerror code for easier error handlingBreaking Changes
None. All features are:
Usage
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.