In `magpie web`, iOS Safari (18.7) loaded none of a plugin page's
scripts: pagePolicy named the page's folder as a scheme-less host-source
(host/_magpie/plugin/<tok>/), a sandboxed frame's origin is opaque, and
that WebKit took the missing scheme from it, so the bridge never said
hello and the page was broken at 10s (orinsid; YangHonghang on v0.1.2681,
young02036 on Discord).
- pagePolicy: a browser's policy now names the folder under both
https:// and http:// (ownSources). Behind nginx or Cloudflare TLS ends
before magpie and nothing magpie trusts says which scheme the page came
over, so X-Forwarded-Proto is not read; both name the same host, port
and folder, and an https page can't load http:// files anyway. The
desktop window keeps its own transport alone (wails://, http:// on
Windows, #2501).
- The second layer (YangHonghang): a page's local service sends its own
policy, `connect-src 'self'`, and what it sends runs under magpie's
`sandbox allow-scripts`. In WebKit, 'self' there didn't match the
service page's own fetch of api/x. servePageService now names the
service's root (/_magpie/plugin/<tok>/_magpie/service/) under both
schemes after each 'self' in a CSP header the service sends, plus ws://
and wss:// in connect-src and default-src (serviceSelf). 'self' stays,
so nothing allowed before is taken away. A <meta> policy isn't
rewritten; the plugin docs (en, zh, ja) say to write whole sources.
Run at f0a723d4c's tree (rebased on c74b932c8), on mote:
- go test ./internal/gui/: every test ok but TestMainWindowCorners, red
the same at an origin/main e7185daeb copy (#3949, macOS 27). The real
WKWebView test TestPluginPageLoadsItsFilesInTheWindow (desktop
wails:// path) passes.
- gofmt -l, go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet:
clean.
- node --test plugin-page, plugin-panels, plugin-page-idle (chromium and
webkit): 14/14.
- win-run: TestPluginPage*, TestServiceSelf, TestPluginPanel* ok on
Windows 11 (the window's http:// scheme).
- A scratch test (not committed) served the real pluginPageRoutes(web)
and a fake service with "default-src 'self'; connect-src 'self'" over
http and https (httptest TLS), framed sandbox=allow-scripts, in
Playwright Chromium 151 and WebKit 26.5. At origin/main WebKit refused
the service's fetch ("Refused to connect to .../_magpie/service/api/x
because it does not appear in the connect-src directive", the
reporter's words); with this change it fetched, and Chromium did both
times. The page's bridge said hello in both engines both times.
Broken by hand: ownSources back to the scheme-less source and
serviceSelf skipped: TestPluginPageWebPolicyNamesItsScheme,
TestPluginPageServedShutIn, TestPluginPanelsServedShutIn,
TestPluginPageWindowPolicy and TestPluginPageServiceProxied go red.
Not tried: a real iPhone. Playwright's WebKit is not iOS Safari, and it
loads the scheme-less source fine, so the first layer is fixed on the
reporters' evidence and the CSP rule, not seen fail and pass here. Not
tried behind a real nginx or Cloudflare, nor a service WebSocket.