gui: a demo's made-up account is never blurred by Hide accounts (data-no-pii)

outloudvi on Discord (#feedback, 1564923315095732276): with Hide accounts
on, the masking demo's letter on Insights › Masking had its account
(yetone@example.com) blurred and its password (hunter2-prod) not. The
blur is hideAccounts, which masks every address in the window's body.
It isn't the demo's own masking. The demo's values are made up, and
showing them is the point of it.

An element marked data-no-pii, and everything inside it, is now skipped
by the text walker and the tooltip pass. The demo's section carries the
marker. The class: any illustration with made-up accounts takes the same
attribute. A search of the GUI assets found no other drawn one. The only
other fake address is ops@company.com, in input placeholders, which the
blur never touches. Text added later in a marked element stays unmasked
too: the observer's mask(e) passes through the same checks.

New test masking-demo-unblurred: Hide accounts on, an address elsewhere
on the page still masked, the demo played (reduced motion on and off),
its account and password slots both readable, and no .pii in #maskDemo.
A generic [data-no-pii] element with a title and text changed after
masking stays unmasked. It runs en and zh, in both engines.

Run on mote:
- masking-demo-unblurred and masking-demo at this tree: green.
- go test -tags nogui -run Budget ./internal/gui: ok (no budget raised).
- The 124-file GUI run in the commit before, at this tree: none of its
  reds in masking files (masking-records zh-TW was green when rerun).
Broken by hand:
- Marker removed from client.js: red, account slot "ilottn@aamital.cmd"
  in webkit (the reporter's blur).
- Walker and title checks removed from app.js: red.
Not tried: Linux and Windows.
This commit is contained in:
yetone
2026-10-28 17:58:50 +08:00
parent a6f6e86e80
commit 76218200af
3 changed files with 128 additions and 3 deletions
+4 -2
View File
@@ -24360,6 +24360,8 @@ window.noteAccounts = noteAccounts;
// itself watched, so it can't set itself off again
const OBS = { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ["title"] };
const SKIP = new Set(["SCRIPT", "STYLE", "OPTION", "TEXTAREA"]);
// a demo's made-up text (data-no-pii) is never hidden (outloudvi)
const KEEP = "[data-no-pii]";
// Usage's Sessions and Context are read from the agents' own logs, which
// name no account (their answers aren't looked through for one, see api):
// a project, a session or a prompt there that has an account's name in
@@ -24386,7 +24388,7 @@ window.noteAccounts = noteAccounts;
const all = finder(), reOf = (e) => e?.closest(NAMELESS) ? EMAIL : all;
const walk = document.createTreeWalker(root, NodeFilter.SHOW_TEXT), found = [];
for (let n; (n = walk.nextNode());) {
if (n.data.length < 2 || SKIP.has(n.parentElement?.tagName) || n.parentElement?.closest(".pii")) continue;
if (n.data.length < 2 || SKIP.has(n.parentElement?.tagName) || n.parentElement?.closest(".pii, " + KEEP)) continue;
const re = reOf(n.parentElement);
re.lastIndex = 0;
if (re.test(n.data)) found.push(n);
@@ -24410,7 +24412,7 @@ window.noteAccounts = noteAccounts;
}
for (const e of [root, ...root.querySelectorAll("[title]")]) {
// one masked already reads as an account too, its stars and all
if (!e.dataset || "piiTitle" in e.dataset || !e.title) continue;
if (!e.dataset || "piiTitle" in e.dataset || !e.title || e.closest(KEEP)) continue;
let out = "", last = 0;
for (const m of hits(e.title, reOf(e), e)) {
out += e.title.slice(last, m.index) + m[0].replace(m[0].includes("@") ? /[^@.]/g : /./gu, "•"); // a tooltip can't blur
+1 -1
View File
@@ -16,7 +16,7 @@ magpie.plugin("redact", (ctx) => {
title: "Masking",
html: `
<section class="msk-card" id="maskCard"></section>
<section class="msk-demo" id="maskDemo">
<section class="msk-demo" id="maskDemo" data-no-pii>
<button type="button" class="md-row" id="mdRow" aria-expanded="false" aria-controls="mdBody">
<span class="md-thumb" aria-hidden="true"></span>
<span class="md-words"><span class="md-name" data-t>How masking works</span><span class="md-sub" data-t>Little Magpie walks one request through: passwords become placeholders before it leaves, and come back on your computer with the answer</span></span>
@@ -0,0 +1,123 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The masking demo's letter is made up, and its account (an address) and
// password are the point of it: with Hide accounts on (outloudvi on
// Discord), the window's privacy blur leaves the demo whole, the account
// as the password. So does it any text marked data-no-pii, its tooltips
// too, while an address beside it is still hidden. Chromium and WebKit,
// en and zh, played through and resting on the last step.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const K = "1792987654321000001";
const record = { key: K, t: new Date(Date.now() - 60e3).toISOString(), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 1,
values: [{ p: "{{PERSON_bbbb2222}}", k: "PERSON", b: "model", h: "", l: 3, n: 1 }], snips: { "{{PERSON_bbbb2222}}": "ask {{PERSON_bbbb2222}} about it" } };
function serve(lang, theme, fetched, more, boot = {}) {
const settings = { theme, lang, tray: "panel", currency: "usd", redact: true, redactPersonal: true, ...more };
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang, theme, web: true, ...boot })};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", fields: [] }], profiles: [], settings });
if (url.pathname === "/api/settings") return json(settings);
if (url.pathname === "/api/providers") return json({ providers: [{ id: "anthropic", name: "Anthropic", icon: "anthropic", agents: [], models: [] }], presets: [], excluded: [], gateway: { running: true, window: true, mine: true, url: "http://127.0.0.1:3999", models: 0, groups: [], calls: [] } });
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/masking/summary") return json({ days: [], requests: 1, n: 1, distinct: 1, blocked: 0, hours: [], kinds: [{ name: "PERSON", n: 1, distinct: 1 }], by: { model: 1 }, agents: [{ name: "claude", n: 1, distinct: 1 }], providers: [{ name: "anthropic", n: 1, distinct: 1 }], values: [] });
if (url.pathname === "/api/masking/records") return json({ records: [record], more: false });
if (url.pathname === "/api/masking/record") return json(record);
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname), ext = path.extname(file);
if (ext === ".webm" || ext === ".jpg") fetched.push(path.basename(file));
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png", ".jpg": "image/jpeg", ".webm": "video/webm" }[ext];
let body;
try { body = await fs.readFile(file); } catch { return route.fulfill({ status: 404, body: "" }); }
// a video is served in ranges, as the gateway's file server does, or
// Chromium can't seek in it
const range = ext === ".webm" && /bytes=(\d+)-(\d*)/.exec(req.headers().range || "");
if (range) {
const from = +range[1], to = range[2] ? Math.min(+range[2], body.length - 1) : body.length - 1;
return route.fulfill({ status: 206, body: body.subarray(from, to + 1), contentType, headers: { "Accept-Ranges": "bytes", "Content-Range": `bytes ${from}-${to}/${body.length}` } });
}
await route.fulfill({ body, contentType, headers: ext === ".webm" ? { "Accept-Ranges": "bytes" } : {} });
};
}
async function open(engine, lang, width, opts = {}) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: opts.motion ? "no-preference" : "reduce" })).newPage();
page.setDefaultTimeout(8000);
const errors = [], fetched = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, opts.theme || "light", fetched, opts.settings, opts.boot));
await page.goto("http://magpie.test/?view=masking");
await page.locator("#mdRow").waitFor();
return { browser, page, errors, fetched };
}
const state = (page) => page.evaluate(() => document.querySelector(".xqd").__state());
// page, when given, adds the demo's state to the failure
async function until(ok, ms = 8000, page) {
for (const end = Date.now() + ms; !(await ok());) {
if (Date.now() > end) throw new Error("never happened: " + ok + (page ? " " + JSON.stringify(await state(page).catch(() => null)) : ""));
await new Promise((r) => setTimeout(r, 50));
}
}
const MAIL = "yetone@example.com", PASS = "hunter2-prod";
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
for (const motion of [false, true]) {
test(`${engine} ${lang}${motion ? " playing" : ""}: Hide accounts leaves the masking demo's letter whole`, async (t) => {
const { browser, page, errors } = await open(engine, lang, 1100, { motion });
t.after(() => browser.close());
// Hide accounts on, as the reporter had it, and an address on the
// page outside the demo, which it hides
await page.evaluate(() => hideAccounts.set(true));
await page.evaluate((mail) => {
const d = document.createElement("div");
d.id = "elsewhere";
d.textContent = "mail " + mail;
d.title = mail;
document.querySelector("#maskDemo").before(d);
}, MAIL);
await page.waitForFunction(() => document.querySelector("#elsewhere .pii"));
assert.ok(!(await page.locator("#elsewhere").getAttribute("title")).includes("yetone"), "a tooltip outside is hidden");
await page.locator("#mdRow").click();
await page.locator(".xqd .xq-stage").waitFor();
if (motion) await until(async () => (await state(page)).T > 12, 20000, page);
else await until(async () => Math.abs((await state(page)).T - 25.6) < .01, 8000, page);
// the letter's account and password, each as written, nothing blurred
const slot = (k) => page.locator(`.xq-stage [data-k="${k}"] .xq-real`);
assert.equal(await slot("s0").textContent(), MAIL);
assert.equal(await slot("s1").textContent(), PASS);
assert.equal(await page.locator("#maskDemo .pii").count(), 0, "something in the demo is blurred: " + await page.locator("#maskDemo .pii").evaluateAll((n) => n.map((x) => x.dataset.raw)));
assert.ok((await page.locator("#maskDemo").textContent()).includes(MAIL));
// the marker is the rule, not the demo: any illustration so marked,
// its tooltip too, drawn now or changed later
await page.evaluate((mail) => {
const d = document.createElement("div");
d.dataset.noPii = "";
d.id = "drawing";
d.innerHTML = `<span title="${mail}">sign in as ${mail}</span>`;
document.querySelector("#maskDemo").after(d);
}, MAIL);
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
await page.evaluate((mail) => { document.querySelector("#drawing span").textContent = "now " + mail; }, MAIL);
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
assert.equal(await page.locator("#drawing .pii").count(), 0);
assert.equal(await page.locator("#drawing span").textContent(), "now " + MAIL);
assert.equal(await page.locator("#drawing span").getAttribute("title"), MAIL);
assert.ok(await page.locator("#elsewhere .pii").count() > 0, "the address outside stays hidden");
assert.deepEqual(errors, []);
});
}
}
}