Skip to content

Conversation

@bonkboykz
Copy link

@bonkboykz bonkboykz commented May 15, 2025

Description

This PR addresses an issue with the generation of the redirect_url during the Google OAuth flow. Previously, the backend was generating URLs using the internal host (api.domain.internal), which resulted in misconfigured redirect URIs and subsequent OAuth errors.

According to docs this setting should help.

This change makes sure that when the backend receives a /auth/google request, it includes the X-Forwarded-Host header containing the proper web host (e.g., mydomain.com). As a result, the generated redirect_url now aligns with the expected domain provided by GodMod, avoiding any discrepancies and OAuth errors.

I have also attached screenshots of the OAuth error screens for reference, which illustrate the issues encountered due to the mismatched redirect URIs.

Mismatched google oauth url looks like this:
https://accounts.google.com/o/oauth2/v2/auth?client_id=<client_id>&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&redirect_uri=https%3A%2F%2Fapi.domain.internal%3A8000%2Fauth%2Fgoogle%2Fcallback%2F&response_type=code&access_type=offline&prompt=consent&state=<some_state>

─────────────────────────────

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

─────────────────────────────

Screenshots and Media (if applicable)

Screenshot 2025-05-15 at 22 26 50

─────────────────────────────

Test Scenarios

  1. Trigger the /auth/google request from the frontend and inspect the HTTP headers to confirm that X-Forwarded-Host correctly reflects the web host.
  2. Validate that the generated redirect_uri in the Google OAuth URL now uses the proper domain (e.g., https://mydomain.com/auth/google/callback), ensuring compliance with Google OAuth policies.
  3. Check the OAuth flow end-to-end for both development and production to ensure no internal host remains in the URL.

─────────────────────────────

References

Summary by CodeRabbit

  • New Features
    • Added a new configuration option to support the use of the X-Forwarded-Host header when the application is behind a proxy. This can be enabled via an environment variable.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 15, 2025

Walkthrough

A new configuration setting, USE_X_FORWARDED_HOST, was introduced in the Django settings file. This setting determines whether to use the X-Forwarded-Host header for host resolution, based on the corresponding environment variable. No other logic or control flow changes were made.

Changes

Cohort / File(s) Change Summary
Django Settings Update
apps/api/plane/settings/common.py
Added USE_X_FORWARDED_HOST boolean setting, determined by the USE_X_FORWARDED_HOST environment variable.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A setting hops in, light as air,
To check for headers, if you care.
With X-Forwarded-Host now in sight,
Proxies and hosts can work just right.
A single flag, a simple tweak—
Configuration rabbits love to seek! 🐇

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
@CLAassistant
Copy link

CLAassistant commented May 15, 2025

CLA assistant check
All committers have signed the CLA.

@bonkboykz bonkboykz marked this pull request as ready for review August 8, 2025 11:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (2)
apps/api/plane/settings/common.py (2)

475-476: Harden proxy handling to prevent header spoofing

USE_X_FORWARDED_HOST trusts the upstream proxy to supply X-Forwarded-Host. Ensure:

  • Your reverse proxy strips client-supplied X-Forwarded-Host and sets it explicitly (e.g., Nginx: proxy_set_header X-Forwarded-Host $host;).
  • ALLOWED_HOSTS includes only the expected external domains in production (current default "*" is permissive and may mask misconfigurations).

Would you like a short checklist/snippet for Nginx/Ingress to ensure these headers are set and sanitized?


475-476: Add a test to lock this behavior for the Google OAuth start endpoint

Recommend a test that:

  • Sets USE_X_FORWARDED_HOST=True (override_settings).
  • Calls the OAuth initiation endpoint with HTTP_X_FORWARDED_HOST set to the external domain and HTTP_X_FORWARDED_PROTO=https.
  • Asserts the redirect Location uses the external domain and https scheme.

I can draft the test tailored to your OAuth view if you share the URL name or view function.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9de5b1a and 136c96d.

📒 Files selected for processing (1)
  • apps/api/plane/settings/common.py (1 hunks)
🔇 Additional comments (1)
apps/api/plane/settings/common.py (1)

475-476: Enabling X-Forwarded-Host aligns with the OAuth redirect host fix

This directly addresses the host-mismatch by letting Django honor X-Forwarded-Host from your reverse proxy. Good change.

Comment on lines +475 to +476
# Use X-Forwarded-Host for get_host calls when behind proxy
USE_X_FORWARDED_HOST = int(os.environ.get("USE_X_FORWARDED_HOST", 0)) == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Also set SECURE_PROXY_SSL_HEADER to fix the scheme (https) behind a TLS-terminating proxy

Without this, build_absolute_uri may still generate http URLs even though the external URL is https, causing OAuth redirect mismatches. Tie it to the same flag to avoid surprising dev environments.

Apply this minimal diff after Line 476:

 USE_X_FORWARDED_HOST = int(os.environ.get("USE_X_FORWARDED_HOST", 0)) == 1
+
+# Honor X-Forwarded-Proto for correct scheme when behind a TLS-terminating proxy
+if USE_X_FORWARDED_HOST:
+    SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

If you terminate TLS at the proxy and forward requests over HTTP to Django, this ensures request.is_secure() is True and absolute URLs use https.

📝 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.

Suggested change
# Use X-Forwarded-Host for get_host calls when behind proxy
USE_X_FORWARDED_HOST = int(os.environ.get("USE_X_FORWARDED_HOST", 0)) == 1
# Use X-Forwarded-Host for get_host calls when behind proxy
USE_X_FORWARDED_HOST = int(os.environ.get("USE_X_FORWARDED_HOST", 0)) == 1
# Honor X-Forwarded-Proto for correct scheme when behind a TLS-terminating proxy
if USE_X_FORWARDED_HOST:
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
🤖 Prompt for AI Agents
In apps/api/plane/settings/common.py at lines 475-476, you need to set the
SECURE_PROXY_SSL_HEADER setting to ensure Django correctly identifies HTTPS
requests behind a TLS-terminating proxy. Add a line after line 476 that sets
SECURE_PROXY_SSL_HEADER to ('HTTP_X_FORWARDED_PROTO', 'https') when
USE_X_FORWARDED_HOST is True, so request.is_secure() returns True and
build_absolute_uri generates https URLs, preventing OAuth redirect mismatches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants