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: prevent open redirect via protocol-relative URLs (#9112)

Myles Scolnick45f32dfc07ea
diff --git a/marimo/_server/api/endpoints/login.py b/marimo/_server/api/endpoints/login.py
index 0e1d0ae16c..596eafae00 100644
--- a/marimo/_server/api/endpoints/login.py
+++ b/marimo/_server/api/endpoints/login.py
@@ -109,10 +109,11 @@ async def login_submit(request: Request) -> Response:
redirect_url = request.query_params.get("next", base_url)
# Validate redirect URL to prevent open redirect vulnerabilities
+ # Reject protocol-relative URLs (e.g. //evil.com) which browsers
+ # interpret as absolute URLs, bypassing scheme-based checks.
parsed = urlparse(redirect_url)
- if parsed.scheme and parsed.netloc:
+ if parsed.netloc:
if parsed.netloc != request.url.netloc:
- # Fall back to base URL if external redirect
redirect_url = base_url
if request.method == "POST":
diff --git a/tests/_server/api/endpoints/test_login.py b/tests/_server/api/endpoints/test_login.py
index 7aeafdf9ee..577241ea0a 100644
--- a/tests/_server/api/endpoints/test_login.py
+++ b/tests/_server/api/endpoints/test_login.py
@@ -145,6 +145,16 @@ def test_login_submit_with_external_redirect(client: TestClient):
assert response.headers["location"] == "/"
+def test_login_submit_with_protocol_relative_redirect(client: TestClient):
+ """Protocol-relative URLs (//evil.com) must not bypass open redirect protection."""
+ response = client.post(
+ "/login?next=//evil.com",
+ data={"password": str(AUTH_TOKEN)},
+ )
+ assert response.status_code == 302
+ assert response.headers["location"] == "/"
+
+
def test_login_submit_with_malformed_data(client: TestClient):
response = client.post(
"/login",