Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
feat(relay): seal excluded board names to enrolled devices [H5,H17]
Corey Olson0b1699fac158
diff --git a/relay/browser-client.js b/relay/browser-client.jsindex df304433..1cd46693 100644--- a/relay/browser-client.js+++ b/relay/browser-client.js@@ -13,6 +13,7 @@ import { browserJSON, withBrowserDeadline } from './browser-deadline.js';import { phoneApprovalStatus, placePhoneApprovals, forgetPhoneApprovals } from './browser-approval-card.js';import { phoneSnapshotPages } from './browser-pages.js';import { createPhoneHistory } from './browser-history.js';+import { deviceExcludedBoards } from './browser-devices.js';const CHECKPOINT_WAIT_MS = 15_000;const KEYS = 'pullboard.relay.keys.v1';@@ -113,6 +114,8 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>const approvedBoards = new Set();let pendingLinks = [];let pendingLinksFailure = '';+ let exclusions = [];+ let exclusionsFailure = '';let warnings = [];let failure = '';let failureBoard = null;@@ -223,7 +226,7 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>entry.key = null;}paired.clear();- available = []; waitingBoards.clear(); pendingLinks = []; pendingLinksFailure = ''; warnings = []; pair = null;+ available = []; waitingBoards.clear(); pendingLinks = []; pendingLinksFailure = ''; exclusions = []; exclusionsFailure = ''; warnings = []; pair = null;for (const id of Object.keys(keys)) delete keys[id];document.querySelector('main')?.replaceChildren();if (error?.code !== 'DEVICE_REVOKED') { location.replace('/'); return; }@@ -259,8 +262,8 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>try { state = storedOwnedRequestState(localStorage, key, entry.state?.personRequests); } catch { /* Missing device storage can only hide this device's own notice. */ }ownedRequestIds.set(id, state.owned);}- const lines = noticeLines({ available, paired, ownedRequestIds, waitingBoards, approvedBoards, pendingLinks, warnings,- failure: failure || pendingLinksFailure });+ const lines = noticeLines({ available, paired, ownedRequestIds, waitingBoards, approvedBoards, pendingLinks, warnings, exclusions,+ failure: failure || pendingLinksFailure || exclusionsFailure });for (const text of lines) {const paragraph = document.createElement('p');paragraph.textContent = text;@@ -275,7 +278,7 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>// A phone has no local-view screen to fall back to: keep its shell and the real reason until a board is readable.const root = document.documentElement;const phoneWaiting = root.dataset.relayDevice === 'phone' && (!rendered || paired.size === 0);- const step = emptyBoardStep({ available, waitingBoards, approvedBoards, loaded: inventoryLoaded, browserPaired, failure });+ const step = emptyBoardStep({ available, waitingBoards, approvedBoards, loaded: inventoryLoaded, browserPaired, failure, exclusions });showRelayScreen(root, phoneWaiting || paired.size === 0 ? 'share' : null,phoneWaiting && (failure || waitingBoards.size || warnings.some(value => ['ACCOUNT_STORAGE_WARNING', 'ACCOUNT_STORAGE_LIMIT'].includes(value?.code))) ? lines.join(' ') : '', step);placePhoneApprovals(document);@@ -557,6 +560,14 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>if (accessLost) throw accessError;const device = await deviceBoardKeyState((path, options) => documentAt(path, denied, options));if (accessLost) throw accessError;+ exclusions = [];+ exclusionsFailure = '';+ try { exclusions = await deviceExcludedBoards((path, options) => documentAt(path, denied, options)); }+ catch {+ if (accessLost) throw accessError;+ exclusionsFailure = 'Excluded-board status could not be checked. Refresh to retry.';+ }+ if (accessLost) throw accessError;Object.assign(keys, stored(localStorage, KEYS, {}), device.keys);browserPaired = device.paired || Boolean(pair) || Object.values(keys).some(value => {try { decodeBoardKey(value); return true; } catch { return false; }diff --git a/relay/browser-devices.js b/relay/browser-devices.jsindex d4cd2b55..f379a24e 100644--- a/relay/browser-devices.js+++ b/relay/browser-devices.js@@ -7,6 +7,7 @@ import { approvalContext, openApproval, sealApproval, verifyApprovalIntent } froimport { devicePublicKey } from './device-keys.js';import { approvalCardText, approvalNames, deletedText, phoneApprovalStatus, forgetPhoneApprovals } from './browser-approval-card.js';import { withBrowserDeadline } from './browser-deadline.js';+import { readExcludedInventories } from './browser-excluded.js';const PENDING = 'pullboard.relay.device-pair.v1';@@ -143,6 +144,14 @@ export async function deviceBoardKeys(documentAt) {return (await deviceBoardKeyState(documentAt)).keys;}+/** Keep the private device key inside the device module while opening the optional excluded-board list. */+export async function deviceExcludedBoards(documentAt) {+ let device;+ try { device = await deviceStorage(); }+ catch (error) { if (error.code !== 'DEVICE_STORAGE') throw error; }+ return readExcludedInventories(documentAt, device);+}+/** Decode only bounded approval transport; keys and plaintext grants never enter device storage. */function approvalDocument(value) {if (typeof value !== 'string' || !/^[A-Za-z0-9_-]{1,32000}$/u.test(value)) throw new Refused('PHONE_APPROVAL_AUTH', 'Request a fresh native approval.');diff --git a/relay/browser-excluded.js b/relay/browser-excluded.jsnew file mode 100644index 00000000..e7313e7d--- /dev/null+++ b/relay/browser-excluded.js@@ -0,0 +1,61 @@+/** Decrypt excluded-board names only on an enrolled device; fresh browsers retain labels/counts [H5,H17]. */+import { unwrapDeviceBoardKey } from './device-keys.js';+import { unseal } from './seal.js';+import { Refused } from './refused.js';+import { ENGINE_VERSION } from './engine.js';+import { withBrowserDeadline } from './browser-deadline.js';++/** Decode only bounded canonical transport bytes before authenticating them on this device. */+function bytes(value, limit) {+ if (typeof value !== 'string' || !/^[A-Za-z0-9_-]+$/u.test(value) || value.length > limit) {+ throw new Refused('EXCLUDED_INVENTORY', 'Refresh this browser to read the excluded-board list.');+ }+ const binary = atob(value.replaceAll('-', '+').replaceAll('_', '/') + '='.repeat((4 - value.length % 4) % 4));+ return Uint8Array.from(binary, character => character.charCodeAt(0));+}++/** Read this signed-in account's metadata and, only with its active device key, its sealed names. */+export async function readExcludedInventories(documentAt, device) {+ const response = await documentAt('/api/v1/devices/exclusions');+ if (!Array.isArray(response.exclusions) || response.exclusions.length > 256) {+ throw new Refused('EXCLUDED_INVENTORY', 'Refresh this browser to read the excluded-board list.');+ }+ const exclusions = response.exclusions.map(entry => {+ if (!entry || !/^[A-Za-z0-9_.-]{1,128}$/u.test(entry.machine ?? '') || typeof entry.label !== 'string'+ || !entry.label.trim() || entry.label.length > 80 || /[\u0000-\u001f\u007f]/u.test(entry.label)+ || !Number.isInteger(entry.count) || entry.count < 1 || entry.count > 256) {+ throw new Refused('EXCLUDED_INVENTORY', 'Refresh this browser to read the excluded-board list.');+ }+ return { machine: entry.machine, label: entry.label, count: entry.count };+ });+ if (!device || !exclusions.length) return exclusions;+ const identity = await documentAt('/api/v1/devices/session');+ if (identity.account !== device.account) return exclusions;+ let wrapped;+ try { wrapped = await documentAt('/api/v1/devices/' + device.deviceId + '/exclusions'); }+ catch (error) { if (error.code === 'DEVICE_NOT_ENROLLED') return exclusions; throw error; }+ if (!Array.isArray(wrapped.exclusions) || wrapped.exclusions.length > 256) {+ throw new Refused('EXCLUDED_INVENTORY', 'Refresh this browser to read the excluded-board list.');+ }+ for (const row of wrapped.exclusions) {+ const entry = exclusions.find(entry => entry.machine === row.machine);+ if (!entry || row.engine !== ENGINE_VERSION || !/^[0-9a-f]{32}$/u.test(row.id ?? '')) {+ throw new Refused('EXCLUDED_INVENTORY', 'Upgrade this browser or refresh its excluded-board list.');+ }+ const envelope = JSON.parse(new TextDecoder().decode(bytes(row.wrapped, 6000)));+ const key = await withBrowserDeadline(() => unwrapDeviceBoardKey(device.privateKey, envelope,+ { board: row.id, device: device.deviceId, engine: row.engine }));+ const plain = await withBrowserDeadline(() => unseal(key, bytes(row.sealed, 131072),+ { boardId: row.id, kind: 'snapshot', sequence: 0 }));+ const value = JSON.parse(new TextDecoder().decode(plain));+ if (value.account !== identity.account || value.machine !== entry.machine || value.label !== entry.label || !Array.isArray(value.names)+ || value.names.length !== entry.count || value.names.some(name => typeof name !== 'string'+ || name.length > 256 || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(name)+ || name.split('/').some(part => part === '.' || part === '..'))) {+ throw new Refused('EXCLUDED_INVENTORY', 'Refresh this browser to read the authenticated excluded-board list.');+ }+ entry.names = value.names;+ }+ return exclusions;+}+diff --git a/relay/browser-notice.js b/relay/browser-notice.jsindex 4db4b773..6b48c92a 100644--- a/relay/browser-notice.js+++ b/relay/browser-notice.js@@ -1,4 +1,5 @@/** Attribute waiting requests to this device while keeping relay intent private [H17,H5]. */+import { excludedNoticeLines } from './excluded-notice.js';/** Match requests to device-owned ids, retaining only waiting receipts and observed final statuses. */export function reconcileOwnedRequests(requests, ownedIds) {const records = new Map((Array.isArray(requests) ? requests : []).filter(value => value && typeof value.id === 'string').map(value => [value.id, value]));@@ -32,7 +33,7 @@ export function storedOwnedRequestState(storage, key, requests) {}/** Build truthful device notices from authorized boards and their decrypted pending requests. */-export function noticeLines({ available, paired, ownedRequestIds = new Map(), waitingBoards = new Map(), approvedBoards = new Set(), pendingLinks = [], warnings = [], failure = '' }) {+export function noticeLines({ available, paired, ownedRequestIds = new Map(), waitingBoards = new Map(), approvedBoards = new Set(), pendingLinks = [], warnings = [], failure = '', exclusions = [] }) {const lines = [];const waiting = [...paired.entries()].reduce((count, [id, entry]) => {const owned = ownedRequestIds.get(id) ?? new Set();@@ -78,7 +79,8 @@ export function noticeLines({ available, paired, ownedRequestIds = new Map(), walines.push(warning.message);}if (failure) lines.push(failure);- if (!available.length) lines.push('No linked boards are available for this account.');+ lines.push(...excludedNoticeLines(exclusions));+ if (!available.length && !exclusions.length) lines.push('No linked boards are available for this account.');return lines;}@@ -92,10 +94,13 @@ export const RELAY_SCREEN_WORDS = Object.freeze({});/** Select guidance from observed inventory and key delivery, never infer why a computer has not uploaded. */-export function emptyBoardStep({ available = [], waitingBoards = new Map(), approvedBoards = new Set(), loaded = false, browserPaired = false, failure = '' } = {}) {+export function emptyBoardStep({ available = [], waitingBoards = new Map(), approvedBoards = new Set(), loaded = false, browserPaired = false, failure = '', exclusions = [] } = {}) {const pair = { command: 'pullboard relay pair --new-browser', ask: 'Help me pair this browser with my boards.',small: 'On the computer with the boards, run this, then open the link it prints here or scan its QR.' };if (!loaded) return { title: 'Checking your linked boards', say: failure || 'Waiting for this account’s board list.', command: '', ask: '', small: '', waiting: failure || 'Checking your boards' };+ if (!available.length && exclusions.length) return { title: 'Boards excluded from sharing',+ say: excludedNoticeLines(exclusions).join(' '), command: 'pullboard relay on', ask: 'Help me include my excluded boards.',+ small: 'On the named computer, open a terminal in each excluded board and run this command.', waiting: 'Waiting for you to include a board' };if (approvedBoards.size) return { title: 'Finishing this pairing', say: 'Approved; waiting for the computer to send this browser its board keys.',command: '', ask: '', small: 'Keep the setup command open on the computer with the boards.', waiting: failure || 'Waiting for this browser’s keys' };if (waitingBoards.size) return { title: 'Waiting for the first board copy',diff --git a/relay/browser-page.js b/relay/browser-page.jsindex b32cee3f..e361adba 100644--- a/relay/browser-page.js+++ b/relay/browser-page.js@@ -47,6 +47,8 @@ export function createRelayBrowserHandler({ authenticate }) {['/relay/device-keys.js', ['text/javascript', readFileSync(new URL('../src/relay-device-keys.js', import.meta.url), 'utf8')]],['/relay/relay-approval.js', ['text/javascript', readFileSync(new URL('../src/relay-approval.js', import.meta.url), 'utf8').replace("'./relay-device-keys.js'", "'./device-keys.js'")]],['/relay/browser-devices.js', ['text/javascript', readFileSync(new URL('./browser-devices.js', import.meta.url), 'utf8')]],+ ['/relay/browser-excluded.js', ['text/javascript', readFileSync(new URL('./browser-excluded.js', import.meta.url), 'utf8')]],+ ['/relay/excluded-notice.js', ['text/javascript', readFileSync(new URL('./excluded-notice.js', import.meta.url), 'utf8')]],['/relay/browser-approval-card.js', ['text/javascript', readFileSync(new URL('./browser-approval-card.js', import.meta.url), 'utf8')]],['/relay/client.js', ['text/javascript', readFileSync(new URL('./browser-client.js', import.meta.url), 'utf8')]],['/relay/relay-limits.js', ['text/javascript', readFileSync(new URL('../src/relay-limits.js', import.meta.url), 'utf8')]],diff --git a/relay/device-http.js b/relay/device-http.jsindex aee7bdac..a1d9dceb 100644--- a/relay/device-http.js+++ b/relay/device-http.js@@ -23,6 +23,19 @@ export function createDeviceHandler({ authenticate, authorizeBoard, boardsFor, dif (url.search) throw new Refused('BAD_REQUEST', 'Keep device action fields out of URL queries.');const who = await authenticate(req, !['GET', 'HEAD'].includes(req.method));const account = who.user.id;+ if (url.pathname === '/api/v1/devices/exclusions') {+ if (who.kind !== 'session') throw new Refused('HUMAN_REQUIRED', 'Sign in as the person to publish or read excluded-board metadata.');+ if (req.method === 'GET') { apiJson(res, 200, { exclusions: devices.exclusions.metadata(account) }); return true; }+ if (req.method === 'POST') { apiJson(res, 200, devices.exclusions.publish(account, await readApiBody(req, { maxBytes: 800000 }))); return true; }+ throw new Refused('NO_ENDPOINT', 'Read or replace this machine’s sealed excluded-board list.');+ }+ const excluded = /^\/api\/v1\/devices\/(device-[0-9a-f]{32})\/exclusions$/u.exec(url.pathname);+ if (excluded && req.method === 'GET') {+ if (who.kind !== 'session') throw new Refused('HUMAN_REQUIRED', 'Sign in on the enrolled device to read its excluded-board wrap.');+ const exclusions = devices.exclusions.forDevice(account, excluded[1]);+ devices.bindSession(who, excluded[1]);+ apiJson(res, 200, { exclusions }); return true;+ }if (await handlePersonEnrollment(req, res, { pathname: url.pathname, who, devices, authorizeBoard })) return true;if (url.pathname === '/api/v1/devices/approvals' && req.method === 'POST') {if (who.kind !== 'machine') throw new Refused('HUMAN_REQUIRED', 'request this approval with the linked board’s machine credential');diff --git a/relay/device-store.js b/relay/device-store.jsindex a69c852e..901ea63e 100644--- a/relay/device-store.js+++ b/relay/device-store.js@@ -5,6 +5,7 @@ import { DatabaseSync } from 'node:sqlite';import { Refused } from '../src/refused.js';import { approvalContext } from '../src/relay-approval.js';import { createPersonEnrollmentStore } from './person-enrollment-store.js';+import { createExcludedStore } from './excluded-store.js';/** Keep device revocations durable so an in-flight native wrap cannot recreate deleted grants. */export function createDeviceStore({ directory, now = Date.now }) {@@ -62,6 +63,7 @@ export function createDeviceStore({ directory, now = Date.now }) {}return {person: createPersonEnrollmentStore({ database, now }),+ exclusions: createExcludedStore({ database, active }),/** Bind the public session id that actually uploaded enrollment, never its bearer credential. */bindSession(principal, device, { enrollment = false } = {}) {if (principal.kind !== 'session') return;diff --git a/relay/excluded-notice.js b/relay/excluded-notice.jsnew file mode 100644index 00000000..eda48363--- /dev/null+++ b/relay/excluded-notice.js@@ -0,0 +1,8 @@+/** Privacy-preserving exclusion guidance shared by the relay shell and device client [H5,H17]. */++/** Name authenticated repositories, or only public machine counts when this browser has no wrap. */+export function excludedNoticeLines(exclusions) {+ return exclusions.flatMap(entry => entry.names+ ? entry.names.map(name => `${name}: excluded from sharing on ${entry.label}. On that computer, run pullboard relay on in this board.`)+ : [`${entry.label}: ${entry.count} board${entry.count === 1 ? '' : 's'} excluded from sharing. On that computer, run pullboard relay on in each excluded board.`]);+}diff --git a/relay/excluded-store.js b/relay/excluded-store.jsnew file mode 100644index 00000000..cd334122--- /dev/null+++ b/relay/excluded-store.js@@ -0,0 +1,76 @@+/** Account-scoped opaque excluded-board lists; only machine labels and counts are public [H5,H17]. */+import { createHash } from 'node:crypto';+import { Refused } from '../src/refused.js';++/** Bind one machine's encrypted inventory to a stable, non-path transport identifier. */+export function excludedInventoryId(machine, account) {+ return createHash('sha256').update('pullboard-exclusions-v1:' + account + ':' + machine).digest('hex').slice(0, 32);+}++/** Keep names sealed and disclose a wrap only after checking that account's active device. */+export function createExcludedStore({ database, active }) {+ /** Open the existing owner-only device database lazily, without creating it for unrelated reads. */+ function storage() {+ const db = database();+ db.exec(`CREATE TABLE IF NOT EXISTS excluded_inventory (+ account TEXT NOT NULL, machine TEXT NOT NULL, label TEXT NOT NULL, count INTEGER NOT NULL,+ engine INTEGER NOT NULL, sealed TEXT NOT NULL, PRIMARY KEY(account,machine));+ CREATE TABLE IF NOT EXISTS excluded_inventory_wrap (+ account TEXT NOT NULL, machine TEXT NOT NULL, device TEXT NOT NULL, wrapped TEXT NOT NULL,+ PRIMARY KEY(account,machine,device));`);+ return db;+ }+ return {+ /** Replace one exact machine publication atomically; inclusion clears the last stale entry. */+ publish(account, value) {+ if (!value || Object.keys(value).sort().join(',') !== 'count,engine,label,machine,sealed,wraps'+ || !/^[A-Za-z0-9_.-]{1,128}$/u.test(value.machine ?? '')+ || typeof value.label !== 'string' || !value.label.trim() || value.label.length > 80+ || /[\u0000-\u001f\u007f]/u.test(value.label)+ || !Number.isSafeInteger(value.count) || value.count < 0 || value.count > 256+ || !Number.isSafeInteger(value.engine) || value.engine < 1+ || typeof value.sealed !== 'string' || !Array.isArray(value.wraps) || value.wraps.length > 100+ || (value.count === 0 ? value.sealed !== '' || value.wraps.length !== 0+ : !/^[A-Za-z0-9_-]{39,131072}$/u.test(value.sealed))) {+ throw new Refused('EXCLUDED_INVENTORY', 'Publish a bounded sealed excluded-board list with a machine label and count.');+ }+ const ids = new Set();+ for (const wrap of value.wraps) {+ if (!wrap || Object.keys(wrap).sort().join(',') !== 'device,wrapped'+ || !/^device-[0-9a-f]{32}$/u.test(wrap.device ?? '')+ || typeof wrap.wrapped !== 'string' || !/^[A-Za-z0-9_-]{1,6000}$/u.test(wrap.wrapped)+ || ids.has(wrap.device)) throw new Refused('EXCLUDED_INVENTORY', 'Wrap this list once for each enrolled device.');+ ids.add(wrap.device);+ active(account, wrap.device);+ }+ const db = storage();+ db.exec('BEGIN IMMEDIATE');+ try {+ // Recheck under the write transaction: a concurrent revocation must win before publication.+ for (const wrap of value.wraps) active(account, wrap.device);+ db.prepare('DELETE FROM excluded_inventory_wrap WHERE account=? AND machine=?').run(account, value.machine);+ db.prepare('DELETE FROM excluded_inventory WHERE account=? AND machine=?').run(account, value.machine);+ if (value.count) {+ db.prepare('INSERT INTO excluded_inventory VALUES(?,?,?,?,?,?)')+ .run(account, value.machine, value.label, value.count, value.engine, value.sealed);+ const insert = db.prepare('INSERT INTO excluded_inventory_wrap VALUES(?,?,?,?)');+ for (const wrap of value.wraps) insert.run(account, value.machine, wrap.device, wrap.wrapped);+ }+ db.exec('COMMIT');+ } catch (error) { db.exec('ROLLBACK'); throw error; }+ return { recorded: true };+ },+ /** A signed-in browser without a key learns only this account's machine labels and counts. */+ metadata(account) {+ return storage().prepare('SELECT machine,label,count FROM excluded_inventory WHERE account=? ORDER BY machine').all(account);+ },+ /** Never return another device's wrap, including to a freshly signed-in revoked browser. */+ forDevice(account, device) {+ active(account, device);+ return storage().prepare(`SELECT i.machine,i.label,i.count,i.engine,i.sealed,w.wrapped+ FROM excluded_inventory AS i JOIN excluded_inventory_wrap AS w+ ON w.account=i.account AND w.machine=i.machine WHERE i.account=? AND w.device=? ORDER BY i.machine`)+ .all(account, device).map(row => ({ ...row, id: excludedInventoryId(row.machine, account) }));+ },+ };+}diff --git a/src/relay-excluded.js b/src/relay-excluded.jsnew file mode 100644index 00000000..562eb25c--- /dev/null+++ b/src/relay-excluded.js@@ -0,0 +1,44 @@+/** Publish explicit exclusion facts without sending repository names or paths to the relay [H5,H17]. */+import { createHash } from 'node:crypto';+import { hostname } from 'node:os';+import { originRepository } from './github-origin.js';+import { listApiProjects } from './projects.js';+import {+ readRelayMachine,+ updateRelayMachine,+ wrapForRecordedDevice,+} from './relay-machine.js';+import { ENGINE_VERSION } from './engine-metadata.js';+import {+ generateBoardKey,+ seal,+} from './seal.js';+import { Refused } from './refused.js';++/** Rebuild and seal this machine's current list using only its locally authenticated device roster. */+export async function publishExcludedBoards(session, io, request) {+ const machine = readRelayMachine();+ if (machine.owner?.account !== session.account || machine.owner?.url !== session.url) return;+ if (!/^ps_[A-Za-z0-9_-]{43}$/u.test(session.token ?? '')) return;+ const names = listApiProjects().filter(project => machine.excluded.includes(project.root)).map(project => {+ const repository = originRepository(project.root, { optional: true });+ if (!repository) throw new Refused('EXCLUDED_REPOSITORY', 'Restore a GitHub origin for each excluded project, then run pullboard relay on --all.');+ return repository;+ });+ if (names.length > 256) throw new Refused('EXCLUDED_INVENTORY', 'Publish at most 256 excluded boards from one machine.');+ if (!names.length && (machine.exclusionsPublished?.account !== session.account || machine.exclusionsPublished?.url !== session.url)) return;+ const label = hostname().replace(/[\u0000-\u001f\u007f]/gu, '').trim().slice(0, 80) || 'Your computer';+ const publication = { machine: machine.machine, label, count: names.length, engine: ENGINE_VERSION, sealed: '', wraps: [] };+ if (names.length) {+ const id = createHash('sha256').update('pullboard-exclusions-v1:' + session.account + ':' + machine.machine).digest('hex').slice(0, 32);+ const key = await generateBoardKey();+ const plain = new TextEncoder().encode(JSON.stringify({ account: session.account, machine: machine.machine, label, names }));+ publication.sealed = Buffer.from(await seal(key, plain, { boardId: id, kind: 'snapshot', sequence: 0 })).toString('base64url');+ for (const device of machine.devices.filter(device => device.account === session.account && device.url === session.url)) {+ const wrapped = await wrapForRecordedDevice(key, { board: id, device: device.deviceId, engine: ENGINE_VERSION }, session);+ publication.wraps.push({ device: device.deviceId, wrapped: Buffer.from(JSON.stringify(wrapped)).toString('base64url') });+ }+ }+ await request(session, '/api/v1/devices/exclusions', { method: 'POST', body: publication }, io);+ updateRelayMachine(state => { state.exclusionsPublished = names.length ? { account: session.account, url: session.url } : null; });+}diff --git a/src/relay-setup.js b/src/relay-setup.jsindex 888735ce..2f398e18 100644--- a/src/relay-setup.js+++ b/src/relay-setup.js@@ -46,6 +46,7 @@ import {} from './init.js';import { relayOfferEnabled } from './settings.js';import { Refused } from './refused.js';+import { publishExcludedBoards } from './relay-excluded.js';/** Say which paired phone must approve a new board's link, and when the request ends in this computer's time. */function approvalWait(name, pending, devices) {@@ -433,6 +434,7 @@ export async function relayOnAll(address, io, { signal, onPairingURL, onSignIn,const approved = await waitForLinkApprovals(waiting, io, { signal });result.linked.push(...approved.linked);result.failed.push(...approved.failed);+ await publishExcludedBoards(session, io, relayDeviceRequest);return { ...result, ...pairing, autoLink: true };}diff --git a/src/relay.js b/src/relay.jsindex 1422651a..d71812a5 100644--- a/src/relay.js+++ b/src/relay.js@@ -1,4 +1,5 @@import { recordedMoveRefusal } from './recorded-move.js';+import { publishExcludedBoards } from './relay-excluded.js';import {recoverySummary,unlinkedRelayStatus,@@ -1653,6 +1654,7 @@ export async function relayOn(root, address, io, { session, credential, quiet =await catchUp(root, file, state, io);await deliverDeviceWraps(root, io);updateRelayMachine(machine => { machine.excluded = machine.excluded.filter(entry => entry !== repoInfo(root).root); });+ if (reusableSession === undefined) await publishExcludedBoards({ ...signed, account, url }, io, request);}result = summary(root, state, { pairing: !quiet });}diff --git a/test/relay-device-http.test.js b/test/relay-device-http.test.jsindex 4ae4e353..6406faf5 100644--- a/test/relay-device-http.test.js+++ b/test/relay-device-http.test.js@@ -23,6 +23,69 @@ import {wrapDeviceBoardKey,} from '../src/relay-device-keys.js';import { githubFixture } from './relay-fixture.js';+import { excludedInventoryId } from '../relay/excluded-store.js';+import {+ seal,+ unseal,+} from '../src/seal.js';++test('excluded inventories keep names sealed, isolate accounts and refuse revoked devices [H5,H15,H17]', async t => {+ const box = await relayDeviceFixture(t);+ const owner = await browserSession(box);+ const phone = await createDeviceKeys();+ const registered = await deviceRequest(box, '/api/v1/devices/' + phone.deviceId, {+ method: 'POST', cookie: owner, origin: box.origin, body: {},+ });+ assert.equal(registered.response.status, 200);+ const machine = 'machine-excluded-fixture';+ const label = 'Fixture computer';+ const id = excludedInventoryId(machine, '7');+ const key = new Uint8Array(randomBytes(32));+ const plain = new TextEncoder().encode(JSON.stringify({ account: '7', machine, label, names: ['fixture/private-excluded'] }));+ const sealed = Buffer.from(await seal(key, plain, { boardId: id, kind: 'snapshot', sequence: 0 })).toString('base64url');+ const envelope = await wrapDeviceBoardKey(key, phone.publicKey, { board: id, device: phone.deviceId, engine: ENGINE_VERSION });+ const body = { machine, label, count: 1, engine: ENGINE_VERSION, sealed,+ wraps: [{ device: phone.deviceId, wrapped: Buffer.from(JSON.stringify(envelope)).toString('base64url') }] };+ const path = '/api/v1/devices/exclusions';+ const denied = await deviceRequest(box, path);+ assert.equal(denied.document.error?.code, 'AUTH_REQUIRED');+ const foreignOrigin = await deviceRequest(box, path, { method: 'POST', cookie: owner, origin: 'https://foreign.invalid', body });+ assert.equal(foreignOrigin.document.error?.code, 'BAD_ORIGIN');+ assert.deepEqual((await deviceRequest(box, path, { cookie: owner })).document.exclusions, []);+ const extra = await deviceRequest(box, path, { method: 'POST', cookie: owner, origin: box.origin, body: { ...body, names: ['forbidden'] } });+ assert.equal(extra.document.error?.code, 'EXCLUDED_INVENTORY', 'plaintext name fields are refused');+ assert.equal((await deviceRequest(box, path, { method: 'POST', cookie: owner, origin: box.origin, body })).response.status, 200);+ box.restart();+ const metadata = await deviceRequest(box, path, { cookie: owner });+ assert.deepEqual(metadata.document.exclusions, [{ machine, label, count: 1 }], 'durable public metadata has no name, key or wrap');+ box.state.accountID = 8;+ const other = await browserSession(box);+ assert.deepEqual((await deviceRequest(box, path, { cookie: other })).document.exclusions, []);+ const devicePath = '/api/v1/devices/' + phone.deviceId + '/exclusions';+ assert.equal((await deviceRequest(box, devicePath, { cookie: other })).document.error?.code, 'DEVICE_NOT_ENROLLED');+ box.state.accountID = 7;+ const delivered = await deviceRequest(box, devicePath, { cookie: owner });+ assert.equal(delivered.response.status, 200);+ const row = delivered.document.exclusions[0];+ const openedKey = await unwrapDeviceBoardKey(phone.privateKey,+ JSON.parse(Buffer.from(row.wrapped, 'base64url').toString('utf8')), { board: row.id, device: phone.deviceId, engine: row.engine });+ assert.deepEqual(await unseal(openedKey, new Uint8Array(Buffer.from(row.sealed, 'base64url')),+ { boardId: row.id, kind: 'snapshot', sequence: 0 }), plain);+ const stored = readFileSync(join(box.relayDirectory, 'devices.sqlite'));+ assert.equal(stored.includes('fixture/private-excluded'), false, 'the relay database has no repository plaintext');+ assert.equal(stored.includes(Buffer.from(key)), false, 'the relay database has no raw list key');+ assert.equal(stored.includes(Buffer.from(key).toString('base64url')), false, 'the relay database has no transport key');+ const freshOwner = await browserSession(box);+ assert.equal((await deviceRequest(box, '/api/v1/devices/' + phone.deviceId, {+ method: 'DELETE', cookie: freshOwner, origin: box.origin,+ })).response.status, 200);+ assert.equal((await deviceRequest(box, devicePath, { cookie: freshOwner })).document.error?.code, 'DEVICE_REVOKED',+ 'a fresh sign-in cannot use the removed device’s old private key to fetch a new wrap');+ const cleared = await deviceRequest(box, path, { method: 'POST', cookie: freshOwner, origin: box.origin,+ body: { ...body, count: 0, sealed: '', wraps: [] } });+ assert.equal(cleared.response.status, 200);+ assert.deepEqual((await deviceRequest(box, path, { cookie: freshOwner })).document.exclusions, [], 'including the last board removes the publication');+});/** Start actual relay/auth HTTP handlers with private SQLite and a real GitHub protocol fixture. */async function relayDeviceFixture(t) {