Fix api proxy requests#4
Conversation
… modified headers, to improve debugging and monitoring capabilities. - Captured initial headers from the incoming request to facilitate better tracking of header modifications. These changes enhance the observability of API proxy interactions.
📝 WalkthroughWalkthroughAdds scheme-related header filtering in the API proxy, updates Nginx to prefer incoming X-Forwarded-Proto and clear conflicting scheme headers, adds ".fly.dev" to Django ALLOWED_HOSTS, and introduces a small test file. Changes
Sequence Diagram(s)(Skipped — changes are configuration/header-filter tweaks and do not introduce new multi-component control flow requiring a diagram.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @front_end/src/app/(api)/api-proxy/[...path]/route.ts:
- Line 45: The variable initialHeaders is assigned the iterator from
request.headers.entries(), which is single-use and logs as [object Iterator];
replace that assignment to capture a reusable, loggable array by converting the
iterator to an array (e.g., via Array.from or spread) so subsequent uses and the
log on line 88 show actual header key/value pairs while keeping the same
variable name (initialHeaders) used elsewhere in route.ts.
- Around line 85-90: The console.log call is exposing sensitive auth headers and
is iterating over header iterators (requestHeaders.entries()/initialHeaders)
which is both insecure and unreadable; remove the console.log or replace it with
a safe log that only records non-sensitive data (e.g., request.url and
targetUrl) and either omits headers entirely or logs only header names with
values redacted. Update the code that references request.url, targetUrl,
initialHeaders and requestHeaders.entries() to avoid printing full header values
(filter out Authorization, Alpha-auth tokens, Cookie/Set-Cookie, and similar
keys) or drop header logging completely; if you must debug, use a controlled
debug logger and explicitly redact sensitive header values before logging.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
front_end/src/app/(api)/api-proxy/[...path]/route.tstest-file
🔇 Additional comments (1)
test-file (1)
1-1: Verify that this file should be committed.This file appears to be a test artifact with no clear purpose or documentation. If this was added accidentally during debugging, please remove it from the PR.
| const apiPath = url.pathname.replace("/api-proxy/", "/api/"); | ||
| const targetUrl = `${PUBLIC_API_BASE_URL}${apiPath}${url.search}`; | ||
|
|
||
| const initialHeaders = request.headers.entries(); |
There was a problem hiding this comment.
Iterator consumed issue: initialHeaders won't display correctly.
request.headers.entries() returns an iterator that can only be consumed once. When logged on line 88, it will display [object Iterator] rather than the actual header values.
🔧 Proposed fix
Convert the iterator to an array to make it reusable and loggable:
- const initialHeaders = request.headers.entries();
+ const initialHeaders = Array.from(request.headers.entries());📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const initialHeaders = request.headers.entries(); | |
| const initialHeaders = Array.from(request.headers.entries()); |
🤖 Prompt for AI Agents
In @front_end/src/app/(api)/api-proxy/[...path]/route.ts at line 45, The
variable initialHeaders is assigned the iterator from request.headers.entries(),
which is single-use and logs as [object Iterator]; replace that assignment to
capture a reusable, loggable array by converting the iterator to an array (e.g.,
via Array.from or spread) so subsequent uses and the log on line 88 show actual
header key/value pairs while keeping the same variable name (initialHeaders)
used elsewhere in route.ts.
🧹 Preview Environment Cleaned UpThe preview environment for this PR has been destroyed.
Cleanup triggered by PR close at 2026-01-07T13:16:24Z |
- Removed logging of initial headers to streamline the request processing. - Added additional scheme headers to the blocklist to prevent "Contradictory scheme headers" warnings on Fly.io. These changes enhance the efficiency and reliability of the API proxy functionality.
- Replaced the static X-Forwarded-Proto header with a dynamic mapping to use the incoming X-Forwarded-Proto from upstream proxies, improving compatibility with services like Fly.io. - Cleared conflicting scheme-related headers to prevent "Contradictory scheme headers" errors in Gunicorn. These changes improve the reliability and efficiency of the Nginx proxy setup.
- Added "*.fly.dev" to ALLOWED_HOSTS to support preview environments, with a note to remove after establishing a wildcard DNS entry. This change enhances the flexibility of the deployment configuration for preview environments.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @metaculus_web/settings.py:
- Line 399: ALLOWED_HOSTS contains an invalid wildcard string "*.fly.dev" which
Django treats literally; update the ALLOWED_HOSTS entry for preview environments
(the ALLOWED_HOSTS list) to use the leading-dot wildcard syntax ".fly.dev"
instead of "*.fly.dev" so subdomains of fly.dev are matched correctly.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
metaculus_web/settings.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build Docker Image
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…tain a tidy codebase by eliminating unnecessary files.
Summary by CodeRabbit
Bug Fixes
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.