Repository navigation
fix(server): answer only same-origin pages and loopback host names - #131
Merged
Merged
Conversation
jvdd
marked this pull request as ready for review
September 29, 2026 13:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Only the pages the server renders itself may read its answers.
Change
CORSMiddlewarewithallow_origins=["*"]is removed, together with its comment, which named aCORS_ORIGINSsetting that did not exist.show()in a notebook displayed adata:page in its iframe. That page has an opaque origin and called the server cross-origin, which was the only reason for the open CORS. Now the notebook and the browser both post the spec to/shareand show the returned/viewURL (_share_url), in an iframe or in the browser (_deliver_notebook(url, height),_deliver_browser(url, block)).run_server(host, port)(server.py) is now the one place whereshow()andflexviz servestart uvicorn. A bind is loopback when every address it resolves to is loopback (is_loopback_bind), so127.1,127.0.0.2and0:0:0:0:0:0:0:1count too. On a loopback bind it serves only a plainname[:port]Hostwhose name islocalhost, a loopback IP literal, or the bind host; a DNS rebinding page gets 400. Starlette'sTrustedHostMiddlewareis not used: it splitsHostat the first colon and so cannot accept[::1]:port. A non-loopback bind serves everyHost: it is a deliberate network exposure with unknown names, andflexviz servealready warns about it (now also decided by address). An app you run yourself or mount withmount_intogets neither check; the embedding guide says so.show(notebook=False)inside a notebook opened the browser and then waited for Ctrl-C, which held the cell, although the docstrings sayblockis ignored in a notebook._deliver_browsernow waits only outside a running event loop, so the documented remote workaround works.show_serveris removed (separate commit). It was a third, unused start path (no caller, not exported) that would have skipped the Host check.docs/index.md(notebooks on a remote kernel),Architecture.md(new "Origin" section, adapter tree, CLI line, a tech-debt row that called the/sharestep a debt),SECURITY.md,docs/guides/ai-agents.md,docs/guides/embedding.md,CHANGELOG.md.Impact
Access-Control-Allow-Origin: *. Measured in Chromium: a page onhttp://localhost:<port>readhttp://127.0.0.1:<port>/sources. Pages on a public origin may additionally meet Chromium's Local Network Access prompt; that was not measured.Host(DNS rebinding) was served. Now it gets 400 on a loopback bind.heightnow sets only the iframe height, as in the browser path.Review fixes
An external review found four gaps, all confirmed and fixed in separate commits:
127.1,127.0.0.2or0:0:0:0:0:0:0:1skipped the Host check (measured: a foreignHostgot 200, against 400 for127.0.0.1).Hostparser acceptedlocalhost:bad,evil@localhostandlocalhost/evil(not exploitable from a browser, but not the stated rule).show(notebook=False)in a notebook blocked the cell, so the documented remote workaround hung.SECURITY.md,Architecture.mdand theserver.pydocstring said only the server's own pages read its answers; that holds among browser pages, not for scripts or the CLI.Manual checks
show()renders and all interactions work.show(notebook=True)stays blank, because VS Code does not forward the port for a notebook output (not even after a wait, or after a click on a127.0.0.1link in the output). This is not a regression: before this PR thedata:page showed the dashboard shell, but its requests to127.0.0.1:<port>failed for the same reason.show(notebook=False)works, because VS Code forwards the port when it opens the browser, and after thatshow(notebook=True)on the same port works too.docs/index.mddocuments this. A notebook transport that needs no port is Notebook show() on a remote kernel needs a forwarded port #132.Tests
TestSameOriginServer(tests/test_integration.py): noAccess-Control-Allow-Originfor another origin, also on a preflight;run_serverrefuses a foreign or malformedHost([,localhost:bad,evil@localhost,localhost/evil) on every loopback spelling (127.0.0.1,localhost,::1,127.1,127.0.0.2,0:0:0:0:0:0:0:1), acceptslocalhost(any case),[::1]and loopback IP literals, and serves everyHoston0.0.0.0. Each case fails before its fix. The127.1case is skipped on Windows, which does not resolve that short form (there it cannot be bound at all).test_serve_warns_only_for_a_network_bind(tests/test_cli.py): no network warning for0:0:0:0:0:0:0:1or::1, a warning for0.0.0.0.TestBrowserDelivery(tests/test_adapters.py): inside a running event loop_deliver_browseropens the page and does not wait; outside it still waits.TestNotebookDelivery(tests/test_adapters.py, plotly and echarts): against a live server, the notebook iframesrcis the server's/viewURL. Fails before the fix (data:text/html;base64,...).TestSameOriginBrowser(tests/test_browser.py): a page on another loopback origin cannotfetchthe server (fails before the fix:'read'); a dashboard renders inside an iframe on a page of another origin, the shape a notebook uses.main,pytest tests flexviz_polars/tests: 2452 passed, 2 skipped.main,pytest -m browser tests: 354 passed, 16 skipped.mkdocs build --strictpasses.