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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: send origin referrer on cross-origin requests from notebook pages (#11015)
Kiran Gadhave1485868e922a
diff --git a/marimo/_server/api/endpoints/assets.py b/marimo/_server/api/endpoints/assets.pyindex 3ed8bc653f..d7ac82ce6a 100644--- a/marimo/_server/api/endpoints/assets.py+++ b/marimo/_server/api/endpoints/assets.py@@ -124,19 +124,14 @@ except RuntimeError:FILE_QUERY_PARAM_KEY = "file"-# Hardening headers for HTML page responses in edit/home mode. These-# supplement the token-stripping redirect below by preventing any outbound-# fetch from the HTML page from leaking a transiently-present access_token-# via `Referer`, and by disabling MIME sniffing on the HTML response.+# Hardening headers for HTML page responses. They supplement the+# token-stripping redirect below and disable MIME sniffing.#-# Use "same-origin" instead of "no-referrer" to avoid Chrome 147+ on macOS-# treating localhost pages as private-network requests without a valid-# referrer, which triggers Local Network Access checks and "Error code 5".-# "same-origin" still prevents cross-origin referrer leakage while-# preserving the referrer for same-origin navigations.-# See: https://github.com/marimo-team/marimo/issues/9455+# Preserve same-origin referrers. Limit cross-origin referrers to the+# origin so services that gate on Referer, such as map tile servers, can+# identify the source without receiving notebook paths or query parameters._HTML_SECURITY_HEADERS: dict[str, str] = {- "Referrer-Policy": "same-origin",+ "Referrer-Policy": "strict-origin-when-cross-origin","X-Content-Type-Options": "nosniff",}diff --git a/tests/_server/api/endpoints/test_assets.py b/tests/_server/api/endpoints/test_assets.pyindex 87fbd7e5de..6a4e6129ca 100644--- a/tests/_server/api/endpoints/test_assets.py+++ b/tests/_server/api/endpoints/test_assets.py@@ -127,7 +127,10 @@ def test_index_strips_access_token_query_param(client: TestClient) -> None:response = client.get("/?access_token=fake-token", follow_redirects=False)assert response.status_code == 303, response.textassert response.headers["location"] == "/"- assert response.headers.get("referrer-policy") == "same-origin"+ assert (+ response.headers.get("referrer-policy")+ == "strict-origin-when-cross-origin"+ )assert response.headers.get("x-content-type-options") == "nosniff"# The session cookie must be set so the redirect target is authenticated# without the query param.@@ -211,7 +214,10 @@ def test_index_unauthenticated_redirect_preserves_next(def test_index_response_has_security_headers(client: TestClient) -> None:response = client.get("/", headers=token_header())assert response.status_code == 200, response.text- assert response.headers.get("referrer-policy") == "same-origin"+ assert (+ response.headers.get("referrer-policy")+ == "strict-origin-when-cross-origin"+ )assert response.headers.get("x-content-type-options") == "nosniff"