From 55dff77b4d96a5197eef072003f8224b5e5658e0 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 19:05:01 +0800 Subject: [PATCH] gui: plugin pages load behind a proxy that signs in by cookie (xuanwo on X) A plugin page's frame is sandboxed (opaque origin), so its stylesheet and scripts are cross-site requests that carry no SameSite=Lax cookie. Behind Cloudflare Access they were redirected to the sign-in page and the page said it "didn't answer" (Day card). index.html's manifest link also fetched without credentials. In magpie web the page's HTML now comes as one document (pageinline.go): classic scripts (bridge included) and url()-free stylesheets are written in, scripts allowed by sha256 in the policy, deferred ones moved to the end of body. A script the page adds later is fetched by the window (asset call, folder-checked, window carries the cookie) and loaded from a data: address (WebKit finds no blob made in a sandboxed frame). The manifest link has crossorigin="use-credentials". Modules, url() stylesheets, images and fonts loaded by the page itself still ask the proxy. Run on mote at this tree: go test -run PluginPage ./internal/gui; node --test plugin-page, plugin-page-idle, plugin-page-cookie-proxy in chromium and webkit; gofmt; vet. Broken by hand: inlining off turns TestPluginPageWebComesAsOneDocument red, the bridge shim off turns the cookie-proxy test red in both engines. Not tried: a real Cloudflare Access tunnel; images/fonts behind a proxy. --- docs/subsystems/plugin-runtime.md | 12 ++ internal/gui/assets/index.html | 2 +- internal/gui/assets/pluginpages.js | 11 ++ internal/gui/pagebridge.js | 30 ++++ internal/gui/pageinline.go | 134 ++++++++++++++++++ internal/gui/pluginpage.go | 29 +++- internal/gui/pluginpage_test.go | 52 +++++++ .../tests/plugin-page-cookie-proxy.test.cjs | 74 ++++++++++ 8 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 internal/gui/pageinline.go create mode 100644 internal/gui/tests/plugin-page-cookie-proxy.test.cjs diff --git a/docs/subsystems/plugin-runtime.md b/docs/subsystems/plugin-runtime.md index a7a746c63..81aca50f7 100644 --- a/docs/subsystems/plugin-runtime.md +++ b/docs/subsystems/plugin-runtime.md @@ -339,6 +339,18 @@ starts a Bun host. `TestServiceSelf` and `TestPluginPageServiceProxied` check the policies, and `TestPluginPageLoadsItsFilesInTheWindow` loads a page through `ownWindow` in a real WKWebView; Playwright, on http, can't see it. + Behind a proxy that signs readers in by a SameSite=Lax cookie (Cloudflare + Access) the sandboxed frame's files carried none and were redirected to + the sign-in (xuanwo on X, Day card). In `magpie web` the page's HTML comes + as one document (`inlinePage`, pageinline.go): its classic scripts (the + bridge included) and url()-free stylesheets are written in, the scripts + allowed by hash, and a script the page adds later is fetched by the window + (`asset` in pluginpages.js, under the page's folder only) and loaded from + a `data:` address (`data:` in script-src; WebKit finds no blob made in a + sandboxed frame). Left as they were: modules, stylesheets with url(), + images and fonts the page loads itself. index.html's manifest link asks + with `crossorigin="use-credentials"`. `TestPluginPageWebComesAsOneDocument`, + `plugin-page-cookie-proxy.test.cjs`. - **Slots.** A page names a slot with `