Skip to content

Commit 79707b4

Browse files
Add secure cookie warnings for HTTP development login issues (#1181)
* added warning for secure cookies Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * Rebase Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Shoumi <shoumimukherjee@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
1 parent 8f46c14 commit 79707b4

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

mcpgateway/admin.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2441,8 +2441,13 @@ async def admin_login_page(request: Request) -> Response:
24412441

24422442
root_path = settings.app_root_path
24432443

2444+
# Only show secure cookie warning if there's a login error AND problematic config
2445+
secure_cookie_warning = None
2446+
if settings.secure_cookies and settings.environment == "development":
2447+
secure_cookie_warning = "Serving over HTTP with secure cookies enabled. If you have login issues, try disabling secure cookies in your configuration."
2448+
24442449
# Use external template file
2445-
return request.app.state.templates.TemplateResponse("login.html", {"request": request, "root_path": root_path})
2450+
return request.app.state.templates.TemplateResponse("login.html", {"request": request, "root_path": root_path, "secure_cookie_warning": secure_cookie_warning})
24462451

24472452

24482453
@admin_router.post("/login")
@@ -2537,6 +2542,10 @@ async def admin_login_handler(request: Request, db: Session = Depends(get_db)) -
25372542

25382543
except Exception as e:
25392544
LOGGER.warning(f"Login failed for {email}: {e}")
2545+
2546+
if settings.secure_cookies and settings.environment == "development":
2547+
LOGGER.warning("Login failed - set SECURE_COOKIES to false in config for HTTP development")
2548+
25402549
root_path = request.scope.get("root_path", "")
25412550
return RedirectResponse(url=f"{root_path}/admin/login?error=invalid_credentials", status_code=303)
25422551

mcpgateway/static/admin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,4 @@
215215
/* Modal z-index to prevent sticky header overlap */
216216
.fixed.z-10 {
217217
z-index: 9999 !important;
218-
}
218+
}

mcpgateway/templates/login.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@
9595
</div>
9696
</div>
9797

98+
{% if secure_cookie_warning %}
99+
<div class="mb-6 p-4 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 text-amber-700 dark:text-amber-400 rounded-xl text-sm">
100+
<div class="flex items-start">
101+
<i class="fas fa-exclamation-triangle mr-2 mt-0.5 flex-shrink-0"></i>
102+
<div class="text-sm">{{ secure_cookie_warning }}</div>
103+
</div>
104+
</div>
105+
{% endif %}
106+
98107
<!-- SSO Providers Section -->
99108
<div id="sso-section" class="mb-6">
100109
<div class="text-center mb-6">

0 commit comments

Comments
 (0)