From 1f7ec835db8a481717190471fb08f9be8b1505f9 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Thu, 16 Jul 2026 18:52:36 +0200 Subject: [PATCH] fix(oauth): force https on Google redirect_uri for public hosts Proxy-header trust alone wasn't enough in prod (still built http://). Build the redirect_uri and force https for non-localhost hosts so it matches the registered Google URI regardless of how the reverse proxy forwards the scheme. --- cloud/oauth.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cloud/oauth.py b/cloud/oauth.py index 0b30f06..49249bf 100644 --- a/cloud/oauth.py +++ b/cloud/oauth.py @@ -48,6 +48,14 @@ async def google_login(request: Request): if oauth is None: raise HTTPException(status_code=404, detail="Google login not configured") redirect_uri = str(request.url_for("google_callback")) + # Behind a TLS-terminating reverse proxy the app sees the request as http, so + # url_for builds an http:// redirect_uri — but Google requires the exact + # registered https URI for public hosts (→ redirect_uri_mismatch otherwise). + # Force https except on localhost (where there's no proxy and http is used). + if redirect_uri.startswith("http://") and not any( + h in redirect_uri for h in ("localhost", "127.0.0.1") + ): + redirect_uri = "https://" + redirect_uri[len("http://"):] return await oauth.google.authorize_redirect(request, redirect_uri)