Repository navigation
fix(auth): stabilize oauth redirect/session handling and api origin #131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
743aba6
fix(auth): stabilize oauth redirect uri and e2e selectors
LucasSantana-Dev 576de71
fix(auth): adapt redis sessions and enforce same-origin api base
LucasSantana-Dev 7953206
fix(frontend): reduce sonar duplication and harden browser redirect c…
LucasSantana-Dev 22e7867
fix(auth): harden callback canonicalization and proxy/session middleware
LucasSantana-Dev 09d6a4d
fix(ci): address sonar hotspot and duplication in auth/session changes
LucasSantana-Dev 74f9336
test(auth): increase coverage for session fallback and api client
LucasSantana-Dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
nginx best practices X-Forwarded-Proto security trusted proxy💡 Result:
Core rule
Treat
X-Forwarded-Proto(and allX-Forwarded-*) as untrusted client input unless the request arrived from a proxy/load balancer you explicitly trust.X-Forwarded-Protois only a de-facto convention indicating the client↔proxy scheme. [1]NGINX best practices (secure “trusted proxy” setup)
Only trust known proxy IPs (never
0.0.0.0/0)set_real_ip_from, select the header, and enable recursive parsing so NGINX finds the last non-trusted address in the chain. [2]Overwrite (don’t forward) spoofable headers to your upstream
proxy_set_header(don’t rely on what the client sent). [3]X-Forwarded-Protospecifically:$scheme.X-Forwarded-Proto, and ensure NGINX only accepts traffic from the LB (network policy / firewall / private listener), otherwise clients can spoof it.Prefer the standardized
Forwardedheader when possibleForwarded: ...; proto=httpsand is explicit that these fields cannot be relied upon unless proxies are trusted, and that intermediaries should handle/replace existing forwarded info carefully. [4]Assume attackers will try header-based bypasses
X-Forwarded-For/X-Forwarded-Protoas common header-manipulation targets. [5]SECURE_PROXY_SSL_HEADER)—only enable that if only trusted proxies can reach the app/NGINX, otherwise the app may incorrectly treat an HTTP request as HTTPS. [6]Minimal safe NGINX pattern (example)
Key decision: if TLS is terminated before NGINX, then
$schemewill behttpbetween LB→NGINX; in that case you should (a) restrict who can reach NGINX to the LB, and (b) pass the LB’sX-Forwarded-Protoonward only because it’s coming from a trusted source.Sources: MDN on
X-Forwarded-Proto[1]; NGINX Real IP module (set_real_ip_from,real_ip_header,real_ip_recursive) [2]; NGINX proxy module (proxy_set_header,$proxy_add_x_forwarded_for) [3]; RFC 7239 and its security considerations [4]; OWASP testing guide mentioningX-Forwarded-*header manipulation targets [5]; Django docs on trustingX-Forwarded-Protoonly when it comes from your proxy [6].🏁 Script executed:
Repository: LucasSantana-Dev/Lucky
Length of output: 2125
Configure trusted proxy validation or use
$schemeinstead of client-suppliedX-Forwarded-Proto.This configuration preserves client-provided
X-Forwarded-Protoheaders without validation. Since nginx.conf lacksset_real_ip_fromdirectives to declare trusted proxies, any client can inject this header. The backend uses it to construct OAuth redirect URIs—an attacker injectingX-Forwarded-Proto: httpcould force insecure redirects.Replace the map with:
Or, if nginx sits behind a trusted proxy (Cloudflare, AWS ALB, etc.), add trusted proxy validation:
Then configure the app/backend to only trust
X-Forwarded-Protowhen coming from nginx.🤖 Prompt for AI Agents