diff --git a/apps/pwa/package.json b/apps/pwa/package.json index a7352cb2..91ac69ff 100644 --- a/apps/pwa/package.json +++ b/apps/pwa/package.json @@ -11,7 +11,7 @@ "test": "node --test" }, "dependencies": { - "@profullstack/footer": "latest", + "@profullstack/footer": "0.5.0", "@profullstack/libsql-pg": "^0.1.4", "@profullstack/profile": "0.1.6", "@simplewebauthn/browser": "^14.0.0", diff --git a/apps/pwa/public/app.js b/apps/pwa/public/app.js new file mode 100644 index 00000000..7d6ab2d9 --- /dev/null +++ b/apps/pwa/public/app.js @@ -0,0 +1,8 @@ +// Page-wide behaviour that used to be inline script (the CSP now allows none): +// the service worker, and confirm() before destructive forms (data-confirm="…"). +if ("serviceWorker" in navigator) navigator.serviceWorker.register("/sw.js").catch(() => {}); +document.addEventListener("submit", (event) => { + const form = event.target; + const question = form instanceof HTMLFormElement ? form.dataset.confirm : null; + if (question && !window.confirm(question)) event.preventDefault(); +}, true); diff --git a/apps/pwa/public/pins.js b/apps/pwa/public/pins.js new file mode 100644 index 00000000..47fb4056 --- /dev/null +++ b/apps/pwa/public/pins.js @@ -0,0 +1,44 @@ +// Trust-on-first-use pins for teammates' identity keys, in this browser. +// +// The dashboard shows each member's key fingerprint (sha256 of the public key). +// The first time this browser sees a member's fingerprint it is pinned; if the +// server later shows a DIFFERENT one, the row is flagged until you accept it. +// A changed key is normal after `logicsrc teams rotate-identity` or a reset, and +// exactly what a swapped-in attacker key looks like: confirm with the person +// out of band before granting them anything. The CLI keeps its own pins +// (~/.config/logicsrc/known-keys.json) and refuses to seal to a changed key. +(function () { + const STORE = "logicsrc.keyPins.v1"; + let pins = {}; + try { pins = JSON.parse(localStorage.getItem(STORE) || "{}") || {}; } catch (_) { pins = {}; } + const save = () => { try { localStorage.setItem(STORE, JSON.stringify(pins)); } catch (_) { /* storage blocked: pins last this page only */ } }; + + for (const el of document.querySelectorAll("code.fp[data-fp-email][data-fp]")) { + const id = `${el.dataset.fpTeam || ""}/${el.dataset.fpEmail}`; + const fp = el.dataset.fp; + const known = pins[id]; + if (!known) { + pins[id] = { fp, firstSeen: Date.now() }; + continue; + } + if (known.fp === fp) continue; + el.style.color = "var(--danger)"; + const note = document.createElement("div"); + note.className = "mono"; + note.style.cssText = "font-size:.72rem;color:var(--danger);margin-top:4px"; + note.textContent = `KEY CHANGED since this browser last saw it (was ${known.fp}). Confirm with ${el.dataset.fpEmail} before granting anything. `; + const accept = document.createElement("button"); + accept.type = "button"; + accept.className = "btn compact"; + accept.textContent = "I checked: accept"; + accept.addEventListener("click", () => { + pins[id] = { fp, firstSeen: Date.now(), acceptedChangeFrom: known.fp }; + save(); + note.remove(); + el.style.color = ""; + }); + note.appendChild(accept); + el.insertAdjacentElement("afterend", note); + } + save(); +})(); diff --git a/apps/pwa/src/lib/html.mjs b/apps/pwa/src/lib/html.mjs index 56c867b5..0383068e 100644 --- a/apps/pwa/src/lib/html.mjs +++ b/apps/pwa/src/lib/html.mjs @@ -120,7 +120,7 @@ export function page({ title = "LogicSRC ▸ credentials", body = "", head = "" ${head}
${body} - +