Skip to content

Tooling for custom runestone builds - #1643

Open
ascholerChemeketa wants to merge 2 commits into
RunestoneInteractive:mainfrom
ascholerChemeketa:custom-activecode
Open

ascholerChemeketa wants to merge 2 commits into
RunestoneInteractive:mainfrom
ascholerChemeketa:custom-activecode

Conversation

@ascholerChemeketa

Copy link
Copy Markdown
Contributor

Handle iframe resizing and add a proxy service for custom builds of runestone running in an interactive's iframe.


This pull request introduces a new allowlisted experiment API tunnel to the book server and adds support for automatic iframe resizing for experimental Runestone components. It also includes comprehensive tests for the new API tunnel.

Experiment API Tunnel

  • Added an allowlisted experiment API tunnel endpoint (/experiments/{service}/{path}) to rsproxy.py, with strict SSRF protections, response size limits, timeout handling, and error mapping. Only explicitly named APIs (currently rdaas/api/duck) are accessible, and responses are capped in size and not cached. [1] [2] [3]
  • Added tests to verify correct behavior of the experiment API tunnel, including allowlist enforcement, error relaying, redirect refusal, response size capping, and timeout handling.

Frontend: Iframe Resize Support

  • Added pretext-iframe-resize.js, a script that enables experimental Runestone components in iframes to automatically request resizing from the parent PreTeXt page when their content changes.
  • Registered the new resize script in the main interactive webpack entry (webpack.index.js) so it is loaded with other common JS assets.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The pooled upstream client can leak session cookies between students, and the new tests fail to exercise the streaming size-limit guard.

2 open issues
What changed in this PR

Adds support for custom Runestone components embedded in PreTeXt iframes, including automatic resizing and a book-server tunnel to an allowlisted experiment API.

Changes:

  • Adds an experiment API endpoint with redirect refusal, response-size limits, and timeout/error handling.
  • Reports iframe content-height changes to the parent page.
  • Adds proxy tests for allowlist enforcement, credential omission, and upstream failure handling.
File Description
test/​bases/​rsptx/​book_server_api/​test_rsproxy.py Tests experiment proxy behavior and safeguards.
bases/​rsptx/​interactives/​webpack.index.js Includes the iframe resize script in the interactive bundle.
bases/​rsptx/​interactives/​runestone/​common/​js/​pretext-iframe-resize.js Observes wrapper size and sends height updates to the parent.
bases/​rsptx/​book_server_api/​routers/​rsproxy.py Implements the allowlisted experiment API tunnel.

Review effort: Balanced


def experiment_client() -> httpx.AsyncClient:
"""Client for explicitly allowlisted experiment APIs."""
return _client("experiment", timeout=EXPERIMENT_TIMEOUT, follow_redirects=False)
Comment on lines +289 to +294
async def test_experiment_api_caps_response(monkeypatch):
monkeypatch.setattr(rsproxy, "MAX_EXPERIMENT_RESPONSE_BYTES", 10)
install_mock("experiment", lambda request: httpx.Response(200, content=b"x" * 11))
async with book_client() as client:
resp = await client.get("/rsproxy/experiments/rdaas/api/duck")
assert resp.status_code == 502
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants