Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: login route trailing slash (#7116)

Myles Scolnickd7532bba15cb
diff --git a/marimo/_server/api/endpoints/login.py b/marimo/_server/api/endpoints/login.py
index aa5e623ce9..6c9000f4cd 100644
--- a/marimo/_server/api/endpoints/login.py
+++ b/marimo/_server/api/endpoints/login.py
@@ -128,7 +128,7 @@ async def login_submit(request: Request) -> Response:
elif request.user.is_authenticated:
return RedirectResponse(redirect_url, 302)
- base_url = AppState(request).base_url
+ base_url = _with_trailing_slash(AppState(request).base_url or "/")
html = LOGIN_PAGE.format(error=error, base_url=base_url)
return HTMLResponse(
content=html,
diff --git a/tests/_server/api/endpoints/test_login.py b/tests/_server/api/endpoints/test_login.py
index b32383c4fa..8977ff56e4 100644
--- a/tests/_server/api/endpoints/test_login.py
+++ b/tests/_server/api/endpoints/test_login.py
@@ -159,3 +159,41 @@ def test_login_submit_with_malformed_data(client: TestClient):
def test_login_page_method_not_allowed(client: TestClient):
response = client.put("/login")
assert response.status_code == 405
+
+
+def test_login_submit_multiple_invalid_attempts(client: TestClient):
+ """Test that multiple failed login attempts still show the login form correctly."""
+ # First invalid attempt
+ response = client.post("/login", data={"password": "wrong_password"})
+ assert response.status_code == 200
+ assert "Invalid password" in response.text
+ assert 'action="/auth/login"' in response.text
+
+ # Second invalid attempt - this should still work
+ response = client.post("/login", data={"password": "wrong_password2"})
+ assert response.status_code == 200
+ assert "Invalid password" in response.text
+ assert 'action="/auth/login"' in response.text
+
+ # Third attempt with correct password should succeed
+ response = client.post("/login", data={"password": str(AUTH_TOKEN)})
+ assert response.status_code == 302
+ assert response.headers["location"] == "/"
+
+
+def test_login_submit_invalid_password_with_base_url():
+ """Test that invalid login with base_url shows correct form action."""
+ app = create_app(base_url="/app")
+ client = TestClient(app, follow_redirects=False)
+
+ # First invalid attempt
+ response = client.post("/app/login", data={"password": "wrong_password"})
+ assert response.status_code == 200
+ assert "Invalid password" in response.text
+ assert 'action="/app/auth/login"' in response.text
+
+ # Second invalid attempt
+ response = client.post("/app/login", data={"password": "wrong_password2"})
+ assert response.status_code == 200
+ assert "Invalid password" in response.text
+ assert 'action="/app/auth/login"' in response.text