Repository navigation
fix: harden local GraphServer with loopback bind, token auth, CORS, and kernel sessions - #66
Merged
Merged
Conversation
…nd kernel sessions
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.
Summary
Hardens the local Jupyter
GraphServeragainst unauthenticated network/cross-origin access and arbitrary database selector / query injection:127.0.0.1): BindThreadedTCPServerto127.0.0.1instead of""(0.0.0.0), and inheritGraphServerHandlerfromhttp.server.BaseHTTPRequestHandler(returning404for unknown paths instead of serving files from the working directory).Access-Control-Allow-Origin: *. Only echoOriginwithVary: Originwhen the origin is an explicit loopback origin (localhost,127.0.0.1, or[::1]), and handleOPTIONSpreflight (204for loopback origins,403otherwise). Same-origin/proxy/<port>environments (such as Vertex AI Workbench) continue working without requiring CORS headers.X-Graph-Server-Token): Generate a random 256-bit token onGraphServer.init(), pass it from the kernel into the rendered visualization HTML (generate_visualization_html(..., token=...)with an optional default""to preserve compatibility withbigquery-magics), send it fromfrontend/src/graph-server.js, and require a matching token (viahmac.compare_digest) on everyGET/POSTendpoint (returning401otherwise). Rebuiltthird_party/index.js.(selector, graph, query)on the Python kernel side keyed by an opaquesession_idinmagics.py:visualize().GraphServerHandler(and the Colab callbacks) resolve the kernel-side session bysession_idand ignore any client-suppliedselectororqueryin request payloads.Testing
pytest tests/): added regression tests intests/server_test.pyandtests/node_expansion_test.pycovering loopback binding,401rejection for unauthenticated requests, CORS preflight / origin enforcement,404on unknown GET paths, and rejection/ignoring of forged body selectors and queries.cd frontend && npm run test:unit): 10/10 suites, 165/165 tests passing (including new token-header unit tests infrontend/tests/unit/graph-server.test.ts).bigquery-magicscompatibility tests (test_graph_server.py,test_bigquery.py): 130 passed, 10 skipped.%%spanner_graph --mock): verifiedOPTIONSpreflight (204, loopbackACAO), authenticatedPOST /post_querywithX-Graph-Server-Tokenandsession_id(200), and graph canvas rendering with zero console errors.