Skip to content

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.

fix(relay): carry SSH relink replacement through confirmation [E12,H5]

Corey Olson879f20cf87d9
diff --git a/relay/auth-http.js b/relay/auth-http.js
index e864a90f..cd45c8e8 100644
--- a/relay/auth-http.js
+++ b/relay/auth-http.js
@@ -48,7 +48,7 @@ function deviceConfirmationPage() {
'if(value.confirmed){stopPolling();status.textContent="The board is linked. You can return to the terminal.";return;}' +
'if(!value.ready){status.textContent="Finish GitHub sign-in in the other tab, then this page will ask you to confirm.";return;}' +
'status.textContent="Signed in as @"+value.account+". Confirm only if this is the board and machine you intended.";' +
- 'intent.textContent="Link "+value.intent.boardName+" from "+value.intent.host+"?";confirmButton.hidden=false;declineButton.hidden=false;' +
+ 'intent.textContent="Link "+value.intent.boardName+" from "+value.intent.host+(value.intent.replaces?", replacing board "+value.intent.replaces:"")+"?";confirmButton.hidden=false;declineButton.hidden=false;' +
'}catch(error){if(terminal)return;status.textContent=error.message;confirmButton.hidden=true;declineButton.hidden=true;}}' +
'/** Send an exact-origin, cookie-bound confirmation decision. */ async function decide(decision){confirmButton.disabled=true;declineButton.disabled=true;try{' +
'const response=await fetch("/auth/device/confirmation",{method:"POST",credentials:"same-origin",headers:{"content-type":"application/json"},' +
diff --git a/relay/auth.js b/relay/auth.js
index f4a8e2af..afe23f2f 100644
--- a/relay/auth.js
+++ b/relay/auth.js
@@ -293,16 +293,19 @@ export function createRelayAuth({ database, github, now = Date.now, sessionTTL =
}
let pendingIntent;
if (intent !== undefined) {
- if (Object.keys(intent).sort().join(',') !== 'board,boardName,host,repository') {
+ const expected = Object.hasOwn(intent, 'replaces') ? 'board,boardName,host,replaces,repository' : 'board,boardName,host,repository';
+ if (Object.keys(intent).sort().join(',') !== expected) {
throw new Refused('BAD_REQUEST', 'start a relay sign-in with exactly one board confirmation');
}
identifier(intent.board, 'BAD_BOARD');
+ if (Object.hasOwn(intent, 'replaces')) identifier(intent.replaces, 'BAD_BOARD');
const repository = repositoryName(intent.repository);
if (typeof intent.host !== 'string' || !intent.host || intent.host.length > 255 || /[\u0000-\u001f\u007f]/u.test(intent.host) ||
typeof intent.boardName !== 'string' || !intent.boardName.trim() || intent.boardName.length > 200 || /[\u0000-\u001f\u007f]/u.test(intent.boardName)) {
throw new Refused('BAD_REQUEST', 'start a relay sign-in with a valid board name and machine host');
}
- pendingIntent = Object.freeze({ board: intent.board, repository, host: intent.host, boardName: intent.boardName });
+ pendingIntent = Object.freeze({ board: intent.board, repository, host: intent.host, boardName: intent.boardName,
+ ...(Object.hasOwn(intent, 'replaces') ? { replaces: intent.replaces } : {}) });
}
const grant = await github.startDevice();
pruneFlows();
@@ -479,7 +482,7 @@ export function createRelayAuth({ database, github, now = Date.now, sessionTTL =
if (flow.confirming) throw new Refused('OAUTH_PENDING', 'the board link is being confirmed; wait for the relay page');
flow.confirming = true;
try {
- await auth.linkBoard(flow.session.token, flow.intent.board, flow.intent.repository, flow.expires);
+ await auth.linkBoard(flow.session.token, flow.intent.board, flow.intent.repository, flow.expires, flow.intent.replaces ?? null);
flow.confirmed = true;
flow.deliveryExpires = now() + 10 * 60_000;
} finally { flow.confirming = false; }
diff --git a/src/relay.js b/src/relay.js
index a28d404d..a2cf1440 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -1592,8 +1592,9 @@ export async function relayOn(root, address, io, { session, credential, quiet =
const key = state ? readBoardKey(state.board) : await generateBoardKey();
const nextBoard = state?.board ?? plannedRelayBoard(root, localRecords(root, store.boardId));
const relink = state ? null : relayRelink(root);
+ const replacement = state?.replaces ?? relink?.previous;
const intent = remoteShell ? { board: nextBoard, repository,
- host: hostname(), boardName: basename(root) } : undefined;
+ host: hostname(), boardName: basename(root), ...(replacement ? { replaces: replacement } : {}) } : undefined;
const signed = remoteShell ? await deviceSignIn(url, io, { intent }) : reusableCredential ?? reusableSession ?? await deviceSignIn(url, io);
if (reusableSession && reusableSession.url !== url) throw new Refused('RELAY_SESSION', 'Sign in again to this relay with pullboard relay on --all.');
// Every clone finds its board in pullboard.json [E12], written before the snapshot so its presentation carries it.
diff --git a/test/relay-ssh-relink.test.js b/test/relay-ssh-relink.test.js
index db8811ce..ed2f77b4 100644
--- a/test/relay-ssh-relink.test.js
+++ b/test/relay-ssh-relink.test.js
@@ -37,6 +37,8 @@ test('SSH relay off then on confirms replacement and retains the old-board off r
if (!ready.value.ready) await new Promise(done => setTimeout(done, 20));
} while (!ready.value.ready && Date.now() < deadline);
assert.equal(ready.value.ready, true, 'real GitHub device grant reaches browser confirmation');
+ assert.equal(ready.value.intent.replaces, previous, 'the person confirms the immutable previous board, not an unbound request field');
+ assert.equal(box.auth.boardOff(previous), null, 'opening and reading confirmation never retires the old link');
const result = await confirmation(box, '', { ticket, decision: 'confirm' }, opened.cookie);
assert.equal(result.status, 200, JSON.stringify(result.value));
assert.equal(result.value.confirmed, true);
@@ -55,3 +57,56 @@ test('SSH relay off then on confirms replacement and retains the old-board off r
}
}
});
+
+
+/** Complete only the existing public device-grant protocol, without minting authority outside it. */
+async function publicIntent(box, intent) {
+ const start = await fetch(box.origin + '/auth/device/start', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ intent }) });
+ assert.equal(start.status, 200);
+ const grant = await start.json();
+ const ticket = decodeURIComponent(new URL(grant.confirmationURL).hash.slice(1));
+ const opened = await confirmation(box, '/open', { ticket });
+ assert.equal(opened.status, 200);
+ let status;
+ const deadline = Date.now() + 30_000; // budget: real private OAuth polling hang ceiling, not a speed assertion.
+ do {
+ const poll = await fetch(box.origin + '/auth/device/poll', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ ticket: grant.ticket }) });
+ assert.equal(poll.status, 200);
+ status = await confirmation(box, '/status', { ticket }, opened.cookie);
+ if (!status.value.ready) await new Promise(done => setTimeout(done, 20));
+ } while (!status.value.ready && Date.now() < deadline);
+ assert.equal(status.value.ready, true);
+ return { ticket, cookie: opened.cookie, status: status.value };
+}
+
+test('SSH replacement requires the active board and an exact authenticated confirmation [E12,H5,H16]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const previous = JSON.parse(readFileSync(box.linkFile, 'utf8')).board;
+ const next = 'b'.repeat(32);
+ const intent = { board: next, repository: 'fixture/repository', host: 'private-host', boardName: 'private-board' };
+ const missing = await publicIntent(box, intent);
+ const denied = await confirmation(box, '', { ticket: missing.ticket, decision: 'confirm' }, missing.cookie);
+ assert.equal(denied.value.error.code, 'BOARD_REPO_LINKED', 'omitting a replacement never creates a second active link');
+ const stale = await publicIntent(box, { ...intent, replaces: 'a'.repeat(32) });
+ const invalid = await confirmation(box, '', { ticket: stale.ticket, decision: 'confirm' }, stale.cookie);
+ assert.equal(invalid.value.error.code, 'BOARD_REPLACE', 'a merely well-formed unrelated id grants no replacement authority');
+ assert.equal(box.auth.boardOff(previous), null);
+ assert.deepEqual(box.auth.linkedBoards().map(row => row.id), [previous]);
+ for (const replaces of [null, {}, '../old-board']) {
+ const response = await fetch(box.origin + '/auth/device/start', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ intent: { ...intent, replaces } }) });
+ assert.equal(response.status, 400, 'malformed replacement intent is refused before device sign-in');
+ }
+ const valid = await publicIntent(box, { ...intent, replaces: previous });
+ const foreign = await fetch(box.origin + '/auth/device/confirmation', { method: 'POST', headers: { origin: 'https://foreign.invalid', 'content-type': 'application/json', cookie: valid.cookie }, body: JSON.stringify({ ticket: valid.ticket, decision: 'confirm' }) });
+ assert.equal(foreign.status, 403, 'replacement keeps the existing same-origin person confirmation boundary');
+ assert.equal(box.auth.boardOff(previous), null);
+ const granted = await confirmation(box, '', { ticket: valid.ticket, decision: 'confirm' }, valid.cookie);
+ assert.equal(granted.status, 200);
+ const receipt = box.auth.boardOff(previous);
+ assert.equal(receipt.replacedBy, next);
+ assert.equal(receipt.userId, '7');
+ const repeated = await confirmation(box, '', { ticket: valid.ticket, decision: 'confirm' }, valid.cookie);
+ assert.equal(repeated.status, 200, 'same confirmed flow is idempotent');
+ assert.deepEqual(box.auth.boardOff(previous), receipt, 'a repeated confirmation never replaces its durable off receipt');
+});