fix(auth): detect HTTPS behind TLS-terminating reverse proxy#331
fix(auth): detect HTTPS behind TLS-terminating reverse proxy#331EnjoyBacon7 merged 3 commits intodevfrom
Conversation
When OpenRAG runs behind Traefik/Nginx that terminates TLS, the internal request arrives as HTTP. This causes the OIDC state cookie to be set without the Secure flag, which prevents the browser from sending it back on the HTTPS callback — breaking the OIDC flow. Fix: _is_request_secure() now checks: 1. PREFERRED_URL_SCHEME env var (explicit config) 2. X-Forwarded-Proto header (set by reverse proxies) 3. request.url.scheme (existing check) Without this fix, OIDC login fails with "OIDC code exchange failed" when deployed behind any TLS-terminating proxy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 35 minutes and 27 seconds. ⌛ 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. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openrag/routers/auth.py (1)
1-1:⚠️ Potential issue | 🟡 MinorCI lint failure:
ruff format --checkreports this file needs reformatting.Run
uv run ruff format openrag/routers/auth.pybefore pushing so the Linting job passes.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openrag/routers/auth.py` at line 1, The file openrag.routers.auth.py fails ruff formatting; run the formatter and commit the changes so CI passes: run the project command (e.g., uv run ruff format openrag/routers/auth.py) or apply ruff/black formatting to the module openrag.routers.auth (the module-level docstring and any functions/classes in that file such as the OIDC route handlers) and re-run `ruff format --check` to ensure the file is properly reformatted before pushing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openrag/routers/auth.py`:
- Around line 118-131: Remove the redundant local "import os" and update
_is_request_secure to handle comma-separated X-Forwarded-Proto values by
splitting request.headers.get("x-forwarded-proto", "") on commas, trimming and
lowercasing, and checking the first non-empty token for "https"; retain the
existing check of os.environ.get("PREFERRED_URL_SCHEME") and the fallback check
of request.url.scheme == "https" so the function uses the module-level os and
correctly detects client-facing HTTPS when proxies append values.
---
Outside diff comments:
In `@openrag/routers/auth.py`:
- Line 1: The file openrag.routers.auth.py fails ruff formatting; run the
formatter and commit the changes so CI passes: run the project command (e.g., uv
run ruff format openrag/routers/auth.py) or apply ruff/black formatting to the
module openrag.routers.auth (the module-level docstring and any
functions/classes in that file such as the OIDC route handlers) and re-run `ruff
format --check` to ensure the file is properly reformatted before pushing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 820f5e57-80bf-4661-a7ae-e63200968915
📒 Files selected for processing (1)
openrag/routers/auth.py
os is already imported at module scope. When a request traverses multiple proxies the header can be a comma-separated list like "https, http"; take the first (client-most) entry before comparing.
|
Thank you @etiquet ! |
deploy/.env.example.vm — template .env adapté au déploiement openrag-01-et (51.159.184.192) : - LLM/Embedder/Reranker pointant sur LiteLLM Mirai (mistral-small-24b + bge-multilingual-gemma2) - Transcriber commenté en attendant le token audio - OIDC Keycloak Mirai (sso.mirai.interieur.gouv.fr) avec placeholders pour les secrets (jamais commités) - URLs publiques sur api/indexer.openrag-mirai.fake-domain.name - VLM vide (aucun VLM exposé par le hub) deploy/Caddyfile.example — reverse proxy TLS Let's Encrypt : - 3 vhosts api/indexer/chat -> ports internes 8080/3042/8080 - X-Forwarded-Proto pour la détection HTTPS derrière proxy (cohérent avec PR linagora#331 upstream) - transport http keepalive long pour les WebSocket Chainlit - catch-all *.openrag-mirai.fake-domain.name -> 404 (le wildcard DNS résout tout vers la VM, le proxy sert de garde-fou) - logs JSON structurés pour ingestion ultérieure Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Narrow-scope revival of #313: extracts only the OIDC cookie fix (9 lines) from that PR, leaving the unrelated feature bundle behind.
When OpenRag runs behind a TLS-terminating reverse proxy (Traefik/Nginx),
request.url.schemeishttpbecause TLS is terminated by the proxy. As a result, the OIDC state cookie is set without theSecureflag, the browser drops it on the HTTPS callback, and the Authorization Code + PKCE exchange fails withOIDC code exchange failed.Fix
_is_request_secure()now checks three indicators:PREFERRED_URL_SCHEME=httpsenv var (explicit config; already used elsewhere in OpenRag)X-Forwarded-Proto: httpsheader (standard reverse-proxy header)request.url.scheme(existing fallback)Relation to #313
Credit to @etiquet — commit is cherry-picked from #313 with authorship preserved. The other ~3,300 lines in #313 (parallel JWT OIDC module, Drive connector, notifications subsystem, 990-line admin router, two non-idempotent migrations, Linagora-internal deployment notes) are out of scope for this fix and should be discussed separately.
Test plan
openrag_sessioncookie hasSecureflag whenX-Forwarded-Proto: httpsis setSummary by CodeRabbit