pages: a read of storage the sandbox has none of no longer breaks a plugin page (nivekxft on X)
nivekxft opened Day card in magpie web and got "This page stopped
working" with "Failed to read the 'localStorage' property from 'Window':
The document is sandboxed and lacks the 'allow-same-origin' flag", often,
until a refresh. Neither magpie nor Day card's files read storage (grep of
both), so the SecurityError comes from a script put in the frame (an
extension's, on some loads), and pagebridge.js reported it as the page's.
a3900e46f let go of the "Blocked a frame" kind and extension stacks; this
one's message is the storage kind, which foreign() did not match.
foreign() now also lets go of a SecurityError that names storage or
cookies with "sandboxed"/"allow-same-origin" (Chromium) or WebKit's "The
operation is insecure". The page's own errors still break it.
Run (wsl-run, magpie-desktop): plugin-page-foreign-error.test.cjs with two
new cases (localStorage read uncaught, sessionStorage read rejected), both
engines green; red on the old pagebridge.js (storage and storageRejected,
via MAGPIE_BRIDGE). plugin-page and plugin-page-idle: 10 of 10 green in
chromium and webkit. Not confirmed: which script reads the storage (the
reporter gave a screenshot, no stack; extension is inferred). Not tried: a
real extension, Go tests, vet (JS-only change).
This commit is contained in:
@@ -101,7 +101,8 @@
|
||||
// reach its error handlers are not that: a script the browser put in
|
||||
// the frame (a wallet's or a translator's extension, whose stack names
|
||||
// chrome-extension://…), and a read of the window or another frame the
|
||||
// sandbox shuts out ("Blocked a frame with origin "null" from accessing
|
||||
// sandbox shuts out (its storage, "The document is sandboxed and lacks the
|
||||
// 'allow-same-origin' flag"; "Blocked a frame with origin "null" from accessing
|
||||
// a cross-origin frame" in Chromium, "Sandbox access violation" in
|
||||
// WebKit; a SecurityError). The page goes on without
|
||||
// either, and the window's "stopped working" over it was a page that
|
||||
@@ -109,7 +110,13 @@
|
||||
function foreign(err, file) {
|
||||
const where = String(file || "") + "\n" + String(err?.stack || "");
|
||||
if (/(?:chrome|moz|safari-web)-extension:\/\//i.test(where)) return true;
|
||||
return err?.name === "SecurityError" && /Blocked a frame (?:with origin|at )/.test(String(err?.message));
|
||||
// storage the sandbox has none of: "Failed to read the 'localStorage'
|
||||
// property from 'Window': The document is sandboxed and lacks the
|
||||
// 'allow-same-origin' flag" (Chromium; WebKit says "The operation is
|
||||
// insecure"), read by a script that isn't the page's (nivekxft on X)
|
||||
const why = String(err?.message);
|
||||
if (err?.name === "SecurityError" && (/The operation is insecure/.test(why) || (/(?:local|session)Storage|\bstorage\b|cookie/i.test(why) && /sandboxed|allow-same-origin/i.test(why)))) return true;
|
||||
return err?.name === "SecurityError" && /Blocked a frame (?:with origin|at )/.test(why);
|
||||
}
|
||||
function report(err) {
|
||||
parent.postMessage({ magpie: 1, method: "error", params: { message: String(err?.message || err) } }, "*");
|
||||
|
||||
@@ -26,6 +26,10 @@ const CASES = {
|
||||
rejected: { c: "c", broken: false, js: `Promise.resolve().then(() => parent.location.origin);` },
|
||||
extension: { masked: true, c: "d", broken: false, js: `setTimeout(() => { const e = new Error("inpage"); e.stack = "Error: inpage\\n at chrome-extension://abcdef/inpage.js:1:1"; throw e; });` },
|
||||
extensionRejected: { c: "e", broken: false, js: `{ const e = new Error("inpage"); e.stack = "Error: inpage\\n at moz-extension://abcdef/inpage.js:1:1"; Promise.reject(e); }` },
|
||||
// the storage the sandbox has none of (nivekxft: "Failed to read the
|
||||
// 'localStorage' property from 'Window': The document is sandboxed ...")
|
||||
storage: { masked: true, c: "1", broken: false, js: `setTimeout(() => { void localStorage.length; });` },
|
||||
storageRejected: { c: "2", broken: false, js: `Promise.resolve().then(() => sessionStorage.getItem("x"));` },
|
||||
// the page's own mistakes still break it
|
||||
own: { masked: true, c: "f", broken: true, js: `setTimeout(() => { throw new Error("the page's own bug"); });` },
|
||||
ownRejected: { c: "0", broken: true, js: `Promise.reject(new Error("the page's own bug"));` },
|
||||
|
||||
Reference in New Issue
Block a user