-
-
Notifications
You must be signed in to change notification settings - Fork 597
fix: HTTP status code 3XX redirection for Parse Server URL not handled properly #2608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🚀 Thanks for opening this pull request! |
📝 Walkthrough""" WalkthroughManual HTTP redirect handling was introduced to the RESTController, ensuring requests explicitly follow redirects rather than relying on the default fetch behavior. New tests were added to verify correct redirect handling in both the RESTController and the ParseServer integration, particularly for batch requests and reverse proxy scenarios. No changes were made to public API signatures. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RESTController
participant Server
participant RedirectedServer
Client->>RESTController: request(method, path, data, options)
RESTController->>Server: fetch (original URL)
Server-->>RESTController: HTTP 301/302/303/307 with Location header
RESTController->>RedirectedServer: fetch (redirect Location URL, possibly with method change)
RedirectedServer-->>RESTController: HTTP 200 (success)
RESTController-->>Client: Response (final result)
Assessment against linked issues
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## alpha #2608 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 63 63
Lines 6174 6193 +19
Branches 1465 1472 +7
=========================================
+ Hits 6174 6193 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (1)
src/__tests__/RESTController-test.js (1)
437-472
: Great addition – covers custom base URL + redirect pathThe test simulates a reverse-proxy scenario accurately and ensures both the
initial and redirected URLs are hit in the correct order. Consider adding one
more case for a 308 response so that behaviour stays correct when you extend
support in the controller.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
integration/test/ParseServerTest.js
(2 hunks)src/RESTController.ts
(5 hunks)src/__tests__/RESTController-test.js
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/RESTController.ts (2)
src/__tests__/RESTController-test.js (3)
CoreManager
(7-7)RESTController
(8-8)headers
(29-33)src/CoreManager.ts (1)
RESTController
(135-145)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: build (Node 22, 22.4.1)
- GitHub Check: build (Node 18, 18.20.4)
- GitHub Check: build (Node 20, 20.15.1)
🔇 Additional comments (2)
src/RESTController.ts (2)
150-151
:redirect: 'manual'
is not universally supported – please verify runtimesNode 18’s built-in
fetch
currently throwsTypeError: redirect option ‘manual’ not supported
and some older browsers ignore it. If any officially-supported environment still
lacks this capability we will break networking completely.Please confirm support matrix or polyfill it; otherwise fall back to the
default behaviour when'manual'
is rejected.
235-236
: Nice abstractionReplacing string concatenation with
getPath()
centralises the URL-building logic and makes future fixes easier. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
src/RESTController.ts (2)
57-62
: Fix potential double-slash issue in URL constructionThe
getPath
function can introduce a double-slash whenpath
already starts with a leading slash, which can cause issues with some reverse proxies.-function getPath(url: string, path: string) { - if (url[url.length - 1] !== '/') { - url += '/'; - } - return url + path; +function getPath(base: string, pathname: string) { + if (base.endsWith('/')) { + base = base.slice(0, -1); + } + if (!pathname.startsWith('/')) { + pathname = '/' + pathname; + } + return base + pathname; }
316-327
: 🛠️ Refactor suggestionLimited redirect handling should support multiple hops
The current implementation only follows a single redirect. If the second request also returns a redirect, it won't be followed, which can lead to incomplete request handling in multi-hop redirect scenarios.
return RESTController.ajax(method, url, payloadString, {}, options).then(async (result) => { - if (result.location) { - const newURL = getPath(result.location, path); - result = await RESTController.ajax(result.method, newURL, result.body, {}, options); + // Follow redirects (up to 5 hops to prevent infinite loops) + let redirectCount = 0; + const MAX_REDIRECTS = 5; + + while (result.location && redirectCount < MAX_REDIRECTS) { + redirectCount++; + const newURL = getPath(result.location, path); + result = await RESTController.ajax(result.method, newURL, result.body, {}, options); } + + // Warn if we hit the redirect limit + if (redirectCount === MAX_REDIRECTS && result.location) { + console.warn('Maximum redirect limit reached, response might be incomplete'); + } + const { response, status, headers } = result; if (options.returnStatus) { return { ...response, _status: status, _headers: headers }; } else { return response; } });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
integration/test/ParseServerTest.js
(2 hunks)src/RESTController.ts
(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- integration/test/ParseServerTest.js
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: build (Node 22, 22.4.1)
- GitHub Check: build (Node 18, 18.20.4)
- GitHub Check: build (Node 20, 20.15.1)
🔇 Additional comments (2)
src/RESTController.ts (2)
150-150
: Good addition of manual redirect handlingSetting
redirect: 'manual'
in fetch options is necessary to prevent automatic redirect following, allowing the SDK to implement its own redirect handling logic.
200-207
: Proper implementation of redirect status code handlingThe implementation correctly handles all redirect status codes (301, 302, 303, 307, 308) and properly adjusts the method and body for 303 redirects as per HTTP standards.
Changed PR title to bug fix, does that look right? |
Looks good! |
Pull Request
Issue
The SDK doesn't support 3XX redirection status codes
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
Closes: #1945
Approach
Tasks
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Tests