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(view): relative cookie redirect; tests read clean links [N39,N26]

Corey Olsond2edbff828a0
diff --git a/src/serve.js b/src/serve.js
index c4bf933e..12cfab94 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -706,8 +706,10 @@ export async function serveView({ port = 0, secret = randomBytes(18).toString('b
}
if (req.method === 'GET' && url.searchParams.has('k')) {
url.searchParams.delete('k');
+ // A relative address keeps the browser on whatever origin it opened, so a page reached through a proxy stays
+ // behind it; collapsing leading slashes keeps "//elsewhere" from reading as another host.
return reply(res, 303, 'text/plain; charset=utf-8', '', {
- location: `http://${req.headers.host}${url.pathname}${url.search}`,
+ location: `/${url.pathname.replace(/^[/\\]+/u, '')}${url.search}`,
...(validKey ? { 'set-cookie': `${cookieName}=${session}; Path=/; HttpOnly; SameSite=Strict` } : {}),
});
}
diff --git a/test/cockpit/activity.test.js b/test/cockpit/activity.test.js
index 2a2a18a5..91f70b40 100644
--- a/test/cockpit/activity.test.js
+++ b/test/cockpit/activity.test.js
@@ -535,7 +535,7 @@ export async function createTransport({ onUpdate }) {
if (url.pathname === '/') return response.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }).end(cockpitPage('', { readOnly: true, transportModule: '/transport.js', stylesheet: '/view.css' }));
if (url.pathname === '/transport.js') return response.writeHead(200, { 'content-type': 'text/javascript' }).end(moduleSource);
// The stylesheet and board reads come from the real view, so the case reads no source file itself.
- const forward = url.pathname === '/view.css' ? '/view.css?k=' + encodeURIComponent(live.key) : url.pathname.slice('/fixture'.length) + url.search;
+ const forward = url.pathname === '/view.css' ? '/view.css' : url.pathname.slice('/fixture'.length) + url.search;
if ((url.pathname !== '/view.css' && !url.pathname.startsWith('/fixture/')) || request.method !== 'GET') return response.writeHead(404).end();
reads.push(url.pathname);
fetchLive(live.base + forward, { headers: { 'x-pullboard-key': live.key } })
diff --git a/test/cockpit/auth.test.js b/test/cockpit/auth.test.js
index c0a3f0a1..7948729f 100644
--- a/test/cockpit/auth.test.js
+++ b/test/cockpit/auth.test.js
@@ -94,6 +94,12 @@ test('[N39,N26] the view key becomes a cookie', async (t) => {
const routed = await exchange(port, `/roadmap?q=launch&k=${encodeURIComponent(key)}`, key);
assert.equal(routed.landed.pathname + routed.landed.search, '/roadmap?q=launch', 'any address keeps its path and other parameters');
assert.equal(routed.pair, pair, 'one session, one cookie');
+ const opened = await get(port, `/roadmap?k=${encodeURIComponent(key)}`);
+ assert.equal(opened.headers.location, '/roadmap', 'the redirect is relative, so a page opened through a proxy stays behind it');
+ for (const path of [`//pullboard.example/?k=${encodeURIComponent(key)}`, `/\\pullboard.example/?k=${encodeURIComponent(key)}`]) {
+ const elsewhere = await get(port, path);
+ assert.ok(!/^[/\\]{2}|^[a-z]+:/iu.test(String(elsewhere.headers.location ?? '/')), `${path.split('?')[0]}: the redirect never names another host`);
+ }
// The clean address works with the cookie alone: the page, its stylesheet and its API.
const page = await get(port, '/', { cookie: pair });
diff --git a/test/cockpit/fixture.js b/test/cockpit/fixture.js
index 791e4244..245729ef 100644
--- a/test/cockpit/fixture.js
+++ b/test/cockpit/fixture.js
@@ -248,6 +248,19 @@ async function styleOf(view) {
return (await fetchLive(`${view.base}/view.css`, { headers: { 'x-pullboard-key': view.key } })).text();
}
+/**
+ * Fetch one of the view's own pages at its clean address, as the browser does once the printed link has
+ * traded its key for the session cookie (N39).
+ *
+ * @param {{ base: string, cookie?: string }} view
+ * @param {string} [path]
+ * @param {RequestInit} [init]
+ * @returns {Promise<Response>}
+ */
+function fetchPage(view, path = '/', init = {}) {
+ return fetchLive(`${view.base}${path}`, { ...init, headers: { ...init.headers, ...(view.cookie ? { cookie: view.cookie } : {}) } });
+}
+
/**
* An element as the page's script uses one: what it writes, how often it rewrote its markup, its
* classes and attributes, the listeners it adds, and how often it was scrolled into view.
@@ -1262,4 +1275,4 @@ async function searchFor(chrome, words, timeoutMs) {
}
}
-export { BIN, scratch, chooseFilter, tapTarget, SPEC, machine, project, build, sendBack, fetchReason, fetchView, fetchLive, startView, styleOf, element, ageNodes, target, settle, storage, daysOn, openPage, projectRows, productEntries, timelineRows, agentEntries, drawing, textBoxes, meet, accept, needEntries, itemRow, boardId, boardOf, assertObservationAges, withoutObservationAges, assertObservationsEqual, shoutNameText, chromeExecutable, browserPause, startSnapshotChrome, openSnapshotChrome, stopOwnedChrome, closeSnapshotChrome, watchSpecDecisionWait, earlier, shoutsAt, press, tapTouch, pickProject, travel, pressedInto, settled, roadmapRow, showing, readRoadmap, openRoadmapParts, tabBar, serveFolder, proofShot, searchFor, allowLiveHold, holdLive };
+export { BIN, scratch, chooseFilter, tapTarget, SPEC, machine, project, build, sendBack, fetchReason, fetchView, fetchLive, fetchPage, startView, styleOf, element, ageNodes, target, settle, storage, daysOn, openPage, projectRows, productEntries, timelineRows, agentEntries, drawing, textBoxes, meet, accept, needEntries, itemRow, boardId, boardOf, assertObservationAges, withoutObservationAges, assertObservationsEqual, shoutNameText, chromeExecutable, browserPause, startSnapshotChrome, openSnapshotChrome, stopOwnedChrome, closeSnapshotChrome, watchSpecDecisionWait, earlier, shoutsAt, press, tapTouch, pickProject, travel, pressedInto, settled, roadmapRow, showing, readRoadmap, openRoadmapParts, tabBar, serveFolder, proofShot, searchFor, allowLiveHold, holdLive };
diff --git a/test/cockpit/home.test.js b/test/cockpit/home.test.js
index 8d9558cb..a5cb3ec0 100644
--- a/test/cockpit/home.test.js
+++ b/test/cockpit/home.test.js
@@ -2,7 +2,7 @@
/** The view opens on whether the rules hold, then what needs the person; Items stay one click away [N26,U91]. */
import assert from 'node:assert/strict';
import { test } from 'node:test';
-import { fetchLive, machine, openPage, project, startView, storage } from './fixture.js';
+import { fetchPage, machine, openPage, project, startView, storage } from './fixture.js';
/** Two gated rows, one approved aim with no gate, and an open question for the person. */
const SPEC = `# Home spec
@@ -24,7 +24,7 @@ test('the first screen shows the rules and their proof before the work queue [N2
const alpha = project(box, 'alpha', SPEC);
const view = await startView(box);
try {
- const html = await (await fetchLive(view.link)).text();
+ const html = await (await fetchPage(view)).text();
const before = (first, then) => html.includes(first) && html.indexOf(first) < html.indexOf(then);
assert.ok(before('data-tab="home"', 'data-tab="items"'), 'Home is the first tab, Items the next');
assert.ok(before('data-pane="home"', 'data-pane="items"'), 'the rules come before the work queue');
diff --git a/test/cockpit/items.test.js b/test/cockpit/items.test.js
index dccd43cb..3fcf363d 100644
--- a/test/cockpit/items.test.js
+++ b/test/cockpit/items.test.js
@@ -132,7 +132,7 @@ test('each row says what it waits on [N26]', async () => {
}]));
assert.deepEqual(rows['1'], { chip: 'free: unclaimed', edge: false, waits: [] }, 'free to claim');
assert.deepEqual(rows['2'], { chip: 'busy: web-1 (Test Model)', edge: false, waits: [] }, 'a claim names its holder');
- assert.deepEqual(rows['3'], { chip: 'gate: gated', edge: true, waits: [`<span class="wait-unit">waits on <a class="ref" href="/items/2?k=${view.key}" data-go="item:2">#2</a>`] }, 'gated on #2, which is still being built');
+ assert.deepEqual(rows['3'], { chip: 'gate: gated', edge: true, waits: [`<span class="wait-unit">waits on <a class="ref" href="/items/2" data-go="item:2">#2</a>`] }, 'gated on #2, which is still being built');
assert.deepEqual(rows['4'], { chip: 'gate: lane held', edge: true, waits: ['lane held: API &lt;freeze&gt; until Friday'] });
assert.deepEqual(rows['5'], { chip: 'warn: to verify', edge: false, waits: [] });
assert.deepEqual(rows['6'], { chip: 'no: sent back', edge: false, waits: [] });
@@ -648,10 +648,10 @@ test('shout ids, search and narrow windows reach the item [N26]', async () => {
await page.type('q', '');
const feed = page.show('feed');
- assert.ok(feed.includes(`<a class="ref" href="/items/1?k=${view.key}" data-go="item:1" title="Greeting">#1</a> is next;`), feed);
- assert.ok(feed.includes(`<a class="ref" href="/items/2?k=${view.key}" data-go="item:2" title="Farewell banner">#2</a> shipped`));
- assert.ok(feed.includes(`(<a class="ref" href="/items/99?k=${view.key}" data-go="item:99">#99</a> is not an item) and it&#39;s done`), 'an unknown item still has its address, and the apostrophe stays intact');
- const ref = (id, title) => `<a class="ref" href="/items/${id}?k=${view.key}" data-go="item:${id}" title="${title}">#${id}</a>`;
+ assert.ok(feed.includes(`<a class="ref" href="/items/1" data-go="item:1" title="Greeting">#1</a> is next;`), feed);
+ assert.ok(feed.includes(`<a class="ref" href="/items/2" data-go="item:2" title="Farewell banner">#2</a> shipped`));
+ assert.ok(feed.includes(`(<a class="ref" href="/items/99" data-go="item:99">#99</a> is not an item) and it&#39;s done`), 'an unknown item still has its address, and the apostrophe stays intact');
+ const ref = (id, title) => `<a class="ref" href="/items/${id}" data-go="item:${id}" title="${title}">#${id}</a>`;
assert.ok(feed.includes(`${ref(7, 'Filler 7')}, see${ref(7, 'Filler 7')} and ${ref(7, 'Filler 7')}${ref(8, 'Filler 8')}: it&#39;s 5 o&#39;clock`), 'every #id links, whatever stands next to it');
assert.equal(feed.match(/class="ref"/g).length, 7);
await page.click({ go: 'item:2', classes: 'ref' });
diff --git a/test/cockpit/layout.test.js b/test/cockpit/layout.test.js
index 5cb4f24d..221f8766 100644
--- a/test/cockpit/layout.test.js
+++ b/test/cockpit/layout.test.js
@@ -7,7 +7,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { test } from 'node:test';
-import { SPEC, machine, project, build, sendBack, fetchLive, startView, styleOf, element, settle, storage, openPage, accept, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, press } from './fixture.js';
+import { SPEC, machine, project, build, sendBack, fetchLive, fetchPage, startView, styleOf, element, settle, storage, openPage, accept, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, press } from './fixture.js';
test('the view never scrolls sideways at 320px [N26]', { timeout: 120_000 }, async (t) => {
@@ -59,7 +59,7 @@ test('the view never scrolls sideways at 320px [N26]', { timeout: 120_000 }, asy
test('the tabs fit one row on a phone [N26]', async () => {
const view = await startView(machine());
try {
- const html = await (await fetchLive(view.link)).text();
+ const html = await (await fetchPage(view)).text();
const style = await styleOf(view);
const phone = /@media \(width < 480px\) \{\n([^@]*?)\n\}/.exec(style)?.[1] ?? '';
assert.doesNotMatch(style, /max-width: 480px/, 'at 480px itself the tabs keep their row');
@@ -141,8 +141,9 @@ test("the view's styles live in their own file [N26]", async () => {
try {
const page = await openPage(view);
assert.doesNotMatch(page.html, /<style|style=/, 'the page holds no styles');
- assert.match(page.html, new RegExp(`\n<link rel="stylesheet" href="/view\\.css\\?k=${view.key}">\n`), 'it links its own, with the secret');
- const css = await fetchLive(`${view.base}/view.css?k=${view.key}`);
+ assert.match(page.html, /\n<link rel="stylesheet" href="\/view\.css">\n/, 'it links its own, at a clean address the session cookie opens');
+ assert.ok(!page.html.includes(view.key), 'the page holds no secret');
+ const css = await fetchPage(view, '/view.css');
assert.equal(css.status, 200);
assert.equal(css.headers.get('content-type'), 'text/css; charset=utf-8');
assert.equal(await css.text(), readFileSync(new URL('../../src/view.css', import.meta.url), 'utf8'), 'src/view.css, as it is');
@@ -151,7 +152,7 @@ test("the view's styles live in their own file [N26]", async () => {
request({ host: '127.0.0.1', port: view.link.port, path: `/view.css?k=${view.key}`, headers: { host: 'pullboard.example' } }, (res) => done(res.statusCode)).on('error', fail).end();
});
assert.equal(stranger, 403, 'nor under another Host');
- const policy = (await fetchLive(view.link)).headers.get('content-security-policy');
+ const policy = (await fetchPage(view)).headers.get('content-security-policy');
assert.equal(/(?:^|; )style-src ([^;]*)/.exec(policy)?.[1], "'self'", 'styles come from the view alone, never inline');
// Nothing the script draws carries a style either: products, the list, a picked item, a spec row.
diff --git a/test/cockpit/roadmap.test.js b/test/cockpit/roadmap.test.js
index f0a891c4..9154af6c 100644
--- a/test/cockpit/roadmap.test.js
+++ b/test/cockpit/roadmap.test.js
@@ -7,7 +7,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
import { generateStressBoard, removeStressBoard } from './perf/generate.mjs';
-import { BIN, tapTarget, SPEC, machine, project, build, sendBack, fetchLive, startView, target, accept, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, press, travel, pressedInto, settled, roadmapRow, showing, readRoadmap, openRoadmapParts, tabBar, proofShot, pickProject, chooseFilter } from './fixture.js';
+import { BIN, tapTarget, SPEC, machine, project, build, sendBack, fetchLive, fetchPage, startView, target, accept, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, press, travel, pressedInto, settled, roadmapRow, showing, readRoadmap, openRoadmapParts, tabBar, proofShot, pickProject, chooseFilter } from './fixture.js';
/** The roadmap state a failed wait saw: its tab, rows, row ids and expansion, dots and open detail (#938). */
@@ -196,8 +196,8 @@ test('the roadmap reads every item as the Items tab does, opens each one, anothe
const profile = mkdtempSync(join(tmpdir(), 'pullboard-roadmap-chrome-'));
let chrome;
try {
- const direct = await fetchLive(new URL(roadmap, view.link));
- assert.equal(direct.status, 200, 'the view serves its page at /roadmap, behind its secret');
+ const direct = await fetchPage(view, roadmapPath);
+ assert.equal(direct.status, 200, 'the view serves its page at /roadmap, behind its session cookie');
assert.equal((await fetchLive(new URL('/roadmap', view.link))).status, 403, 'and nothing there without the secret');
chrome = await openRoadmapChrome(executable, new URL(roadmap, view.link).href, profile);
const consoleErrors = [];
@@ -244,13 +244,13 @@ test('the roadmap reads every item as the Items tab does, opens each one, anothe
// An item opens on the Items tab; Back shows the Roadmap at its address again, Forward the item.
await openRoadmapItem(chrome, '#3');
await pressedInto(chrome, `${showing('items', '/roadmap-demo/items/3')} && document.querySelector('#detail h2')?.innerText.includes('Session timeout banner')`);
- assert.equal(await chrome.stable('location.search'), view.link.search, `${width}: the address keeps the rest of itself`);
+ assert.equal(await chrome.stable('location.search'), '', `${width}: the address keeps the rest of itself, which holds no key`);
await travel(chrome, -1);
await settled(chrome, `${showing('roadmap', roadmapPath)} && document.querySelector('.tab.on')?.dataset.tab === 'roadmap'`);
await travel(chrome, 1);
await settled(chrome, `${showing('items', '/roadmap-demo/items/3')} && document.querySelector('.tab.on')?.dataset.tab === 'items' && document.querySelector('#detail h2')?.innerText.includes('Session timeout banner')`);
await press(chrome, `document.querySelector('[data-tab="roadmap"]')`);
- await pressedInto(chrome, `${showing('roadmap', roadmapPath)} && location.search === ${JSON.stringify(view.link.search)}`);
+ await pressedInto(chrome, `${showing('roadmap', roadmapPath)} && location.search === ''`);
}
// Another repo's item opens on its own board, and Back and Forward move between the two boards.
diff --git a/test/cockpit/scope.test.js b/test/cockpit/scope.test.js
index c03bca23..b915801a 100644
--- a/test/cockpit/scope.test.js
+++ b/test/cockpit/scope.test.js
@@ -29,8 +29,9 @@ async function startProjectView(box, repo) {
child.once('error', () => reject(new Error('the scoped view process could not start')));
child.once('exit', () => reject(new Error('the scoped view exited before printing its link')));
});
- const ready = await fetchLive(link.href, { signal: AbortSignal.timeout(30_000) });
- assert.equal(ready.status, 200, 'the scoped view answers before its pages are read');
+ // The printed link trades its key for the session cookie (N39); its answer shows the view is serving.
+ const ready = await fetchLive(link.href, { redirect: 'manual', signal: AbortSignal.timeout(30_000) });
+ assert.equal(ready.status, 303, 'the scoped view answers before its pages are read');
await ready.arrayBuffer();
return {
link,
diff --git a/test/cockpit/shouts.test.js b/test/cockpit/shouts.test.js
index 8da1dd63..54144ad6 100644
--- a/test/cockpit/shouts.test.js
+++ b/test/cockpit/shouts.test.js
@@ -103,7 +103,7 @@ test('a shout shows the evidence it carries [B22]', async () => {
const view = await startView(box);
try {
const feed = (await openPage(view)).show('feed');
- const card = (kind, outcome) => `<div class="receipt"><div><span class="badge">${kind}</span> <span class="outcome">${outcome}</span></div><div class="receipt-foot"><a class="ref" href="/items/1?k=${view.key}" data-go="item:1" title="Greeting">#1</a> · web-1 (Test Model) · <code class="inline sha" title="${head}">${head.slice(0, 10)}</code></div></div>`;
+ const card = (kind, outcome) => `<div class="receipt"><div><span class="badge">${kind}</span> <span class="outcome">${outcome}</span></div><div class="receipt-foot"><a class="ref" href="/items/1" data-go="item:1" title="Greeting">#1</a> · web-1 (Test Model) · <code class="inline sha" title="${head}">${head.slice(0, 10)}</code></div></div>`;
const after = (text) => feed.slice(feed.indexOf(text + '</div>') + text.length + 6).replace(/^<button class="more" data-more type="button">more<\/button>/, '');
assert.ok(after('the page loads in 80ms').startsWith(card('receipt', 'measured &lt;fast&gt;')), `what was measured, for which item, by whom, at which commit: ${after('the page loads in 80ms').slice(0, 400)}`);
assert.ok(after('tried a cache').startsWith(card('attempt', 'failed')), 'and what was tried');