layerfs 0.10.3: the trajectory page opens from another computer (#1228)

ccyin found it (#1228): opened through `magpie web` from another
computer (magpie in Docker), the LayerFS page was blank with
"127.0.0.1:43717 refused to connect". The page entry had no
magpie.page.service, so the bridge gave no forward and boot.js jumped
to 127.0.0.1, which is the viewing computer there. page-chat and
page-fingerprint declare it and worked in the same window.

- package.json: page.service {port: 43717, option: "pagePort"}.
- boot.js goes to magpie.service when it is an http(s) address, with
  the language query; otherwise to 127.0.0.1:<pagePort> as before.
- The service is unchanged: magpie's forward (internal/gui/
  pageservice.go) sends Host 127.0.0.1:<port>, drops the cookie, and a
  navigation carries no Origin, so its guards pass as they are.

Run (mote, HOME=$(mktemp -d)):
- bun test in packages/layerfs: 72 pass, 0 fail.
- bun scripts/check.mjs layerfs: ok.

Broken by hand: origin/main's page/boot.js with the new tests: the
forward test fails (the frame still goes to 127.0.0.1).

Not tried: a real magpie web in Docker opened from a second computer.
This commit is contained in:
yetone
2026-11-16 23:24:05 +08:00
parent d5a4a0ca52
commit e271eb644a
5 changed files with 74 additions and 3 deletions
+15 -1
View File
@@ -177,7 +177,9 @@ serves its chat page:
- **The installed page only jumps.** `page/index.html` does one
thing: it reads the port from the plugin's options
(`pagePort`, default 43717) and `location.replace`s its frame to
`http://127.0.0.1:<port>/`. The install's folder is never
`http://127.0.0.1:<port>/`, or, when magpie forwards the service
on its own address (`magpie.page.service`; a browser on another
computer, magpie in Docker), to that forward. The install's folder is never
renamed, linked, or written into. The service starts when the
host loads, store or no store; a user with no store gets the
page's empty state and nothing written anywhere.
@@ -237,6 +239,18 @@ node tools/gen-trajectory.mjs # regenerate the page's bundled sample trajector
Zero runtime dependencies; the arguments are JSON Schema, like the other
tools packages. MIT.
## Changes in 0.10.3
The page now opens in a browser on another computer (`magpie web`,
magpie in Docker). It used to send its frame to `127.0.0.1:43717`,
which there is the viewing computer, so the frame said "refused to
connect" (#1228). The package now declares `magpie.page.service`
(port 43717, moved by `pagePort`), and the page goes to the forward
magpie gives it on its own address. The service still listens on
127.0.0.1 only, and its Host and Origin checks are unchanged: the
forward sends the service's own Host and no Origin. With an older
magpie that gives no forward, the page jumps to 127.0.0.1 as before.
## Changes in 0.10.2
The page no longer hangs on "Connecting to the local trajectory
+11
View File
@@ -752,6 +752,17 @@ test("0.10.0: the service refuses cross-origin reads, foreign hosts, and non-roo
}
}, 30000)
test("#1228: the request magpie's page forward sends (the service's own Host, no Origin, the language query) is served", async () => {
const { call, url, port } = await simTools()
await call("provision", { project: "website" })
await serviceData(url, (x) => !!x.projects.find((p) => p.name === "website"))
// internal/gui/pageservice.go: Host is 127.0.0.1:<port>, the cookie is
// taken off, and a navigation from the page's frame carries no Origin
const r = await rawRequest(port, `127.0.0.1:${port}`, "/?lang=zh")
expect(r).toMatch(/^HTTP\/1\.1 200/)
expect(r).toContain('id="graph"')
}, 30000)
test("0.10.0: a commit message cannot break out of the embedded data script", async () => {
const { call, url } = await simTools()
const evil = "x</script><script>alert(1)</script>y"
+5 -1
View File
@@ -33,6 +33,10 @@
"page": {
"file": "page/index.html",
"icon": "page/icon.svg",
"service": {
"port": 43717,
"option": "pagePort"
},
"title": "LayerFS trajectory",
"titles": {
"ja": "LayerFS の軌跡",
@@ -49,5 +53,5 @@
"directory": "packages/layerfs"
},
"type": "module",
"version": "0.10.2"
"version": "0.10.3"
}
+26
View File
@@ -412,3 +412,29 @@ test("0.10.2: the empty state reloads itself, so the first project appears witho
const empty = app.slice(app.indexOf("if (!projects.length) {"), app.indexOf("$(\"stamp\")"))
expect(empty).toContain("location.reload()")
})
// boot.js run as the page runs it, with the bridge and location stubbed:
// where does the frame go?
async function bootTarget(magpie) {
let target = null
const window = { magpie }
const location = { replace: (u) => { target = u } }
await new Function("window", "location", `return (${read("boot.js").trim().replace(/;?\s*$/, "")})`)(window, location)
return target
}
test("#1228: with magpie's forward of the service, the frame goes there, not to 127.0.0.1", async () => {
expect(pkg.magpie.page.service).toEqual({ port: 43717, option: "pagePort" })
expect(pkg.magpie.options.pagePort).toBe(pkg.magpie.page.service.port)
const service = "http://nas.lan:3430/_magpie/plugin/tok/_magpie/service/"
expect(await bootTarget({ ready: Promise.resolve({ lang: "zh" }), service, options: { get: async () => ({ pagePort: 43800 }) } }))
.toBe(`${service}?lang=zh`)
expect(await bootTarget({ ready: Promise.resolve({}), service })).toBe(service)
})
test("#1228: an older magpie without a forward, or a value that isn't a web address, keeps the jump to 127.0.0.1", async () => {
expect(await bootTarget({ ready: Promise.resolve({ lang: "ja" }), options: { get: async () => ({ pagePort: 43800 }) } }))
.toBe("http://127.0.0.1:43800/?lang=ja")
expect(await bootTarget({ ready: Promise.resolve({}), service: "javascript:alert(1)" })).toBe("http://127.0.0.1:43717/")
expect(await bootTarget(undefined)).toBe("http://127.0.0.1:43717/")
})
+17 -1
View File
@@ -15,6 +15,15 @@
// leaves its page pointing at the first host's service, which serves
// the same store — the same behaviour page-chat relies on.
//
// In a browser on another computer (`magpie web`, or magpie in Docker),
// 127.0.0.1 is that computer, not the one running the service, and the
// frame showed "127.0.0.1 refused to connect" (#1228). package.json's
// magpie.page.service lets magpie forward the service on its own
// address, under the page's token; the bridge names it magpie.service.
// When it is there the frame goes to it; when it isn't (an older
// magpie), to 127.0.0.1 as before. magpie sends the service's own Host
// and no Origin for a navigation, so the service's guards still hold.
//
// The language rides along as a query: the served page is no longer
// inside magpie, so it cannot ask magpie.ready for it. The service
// hands it to the UI as LayerfsTheme; the theme itself stays with the
@@ -23,12 +32,18 @@
const DEFAULT_PORT = 43717
let port = DEFAULT_PORT
let lang = ""
let service = ""
try {
const t = await window.magpie?.ready
if (t && typeof t.lang === "string") lang = t.lang
} catch { /* no bridge: the service falls back to English */ }
try {
const s = window.magpie?.service
if (typeof s === "string" && /^https?:\/\//.test(s)) service = s
} catch { /* an older magpie names no service */ }
try {
const o = await window.magpie?.options?.get?.()
const n = Number(o?.pagePort)
@@ -38,5 +53,6 @@
const q = new URLSearchParams()
if (lang) q.set("lang", lang)
const qs = q.toString()
location.replace(`http://127.0.0.1:${port}/${qs ? `?${qs}` : ""}`)
const base = service || `http://127.0.0.1:${port}/`
location.replace(`${base}${qs ? `?${qs}` : ""}`)
})()