Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: verify pinned navigation on service-worker-served documents (#3317)

[._.]/ Adam Eivy9cdf1d10cc80
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 9d562ff01a..ab37d97520 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -106,6 +106,7 @@
## Stacker News stewardship
- **[issue-3315] The Stacker News vision-model picker now only offers models that can actually see an image.** It listed every installed Ollama model — coder and embedding models included — and picking one was silently accepted, so a model that cannot read an image still produced a confident-looking "vision" verdict that fed the safety policy gating the account's actions. The picker now shows the same vision-capable list the rest of PortOS uses (the server's per-model capability report unioned with the id heuristic, so a brand-new multimodal family still shows up), the text picker is untouched, a model you configured earlier is preserved even if it no longer qualifies, and the form now says whether it is still checking capabilities or has confirmed you have no vision model installed.
+- **[issue-3317] Check browser identity now works on sites whose service worker serves the page.** The SSRF pin behind every browser handoff verifies the address Chrome actually dialled for the main document, and refuses anything it cannot verify — but a service-worker-mediated document carries no peer address even when the worker passed the fetch straight through to the network, so identity checks against any PWA failed 100% of the time with "Chrome connected to an unverifiable address". The pinned tab now bypasses the site's service worker so Chrome fetches the document itself and reports a real address to verify, cookies and the signed-in session being unaffected. The fail-closed rule is unchanged: an unexplained missing address is still a refusal, and only a hop Chrome explicitly reported as served from cache — with no connection to pin — is exempt, and only when another hop in the same navigation verified a real address. Refusals now name the delivery flags that caused them, so the next one is diagnosable from the message.
- **[issue-3302] Safe Stacker News community stewardship** — Add independent account rules and effective account/territory schedules, editable ownership-aware communities, removable encrypted credentials, constrained GraphQL reads and reviewed publishing, conservative local text/vision analysis with safe image normalization, fixed-origin identity-verified browser handoffs, target-bound Review Hub approvals, and an auditable action ledger in Comms.
## Goals
diff --git a/server/services/browserService.js b/server/services/browserService.js
index 687ca800e7..adefdadfd7 100644
--- a/server/services/browserService.js
+++ b/server/services/browserService.js
@@ -281,6 +281,44 @@ export async function navigateToUrl(url) {
// ---------- CDP pinned navigation (SSRF: verify Chrome's ACTUAL connect IP) ----------
+// `serviceWorkerResponseSource` values that mean the service worker answered
+// from a local store instead of dialing out: its own Cache Storage, the HTTP
+// cache, or the worker's synthesized fallback response. `'network'` — the SW
+// passed the request THROUGH — is deliberately absent: that hop did make a
+// connection, it just isn't annotated with the peer address.
+const NO_NETWORK_SW_SOURCES = new Set(['cache-storage', 'http-cache', 'fallback-code']);
+
+// One main-frame hop from a CDP `Network.Response` (a `responseReceived`
+// payload or the `redirectResponse` riding on the next request).
+const toHop = (r) => ({
+ url: r.url || null,
+ remoteIPAddress: r.remoteIPAddress || '',
+ status: r.status ?? null,
+ fromServiceWorker: r.fromServiceWorker === true,
+ fromDiskCache: r.fromDiskCache === true,
+ fromPrefetchCache: r.fromPrefetchCache === true,
+ serviceWorkerResponseSource: r.serviceWorkerResponseSource || null,
+});
+
+// True when Chrome explicitly reported that this hop was served WITHOUT opening
+// a connection (disk cache, prefetch cache, or a service worker answering from
+// its own store). Such a hop has no peer IP to pin because there is no peer —
+// distinct from an empty `remoteIPAddress` with no explanation, which stays a
+// refusal. Exported for testing.
+export function hopMadeNoConnection(hop) {
+ if (!hop) return false;
+ return hop.fromDiskCache === true
+ || hop.fromPrefetchCache === true
+ || NO_NETWORK_SW_SOURCES.has(hop.serviceWorkerResponseSource);
+}
+
+// Human-readable cause for an empty-IP refusal, so the next occurrence is
+// diagnosable from the thrown message without a manual CDP replay.
+const describeHopDelivery = (hop) => `no remoteIPAddress; fromServiceWorker=${hop.fromServiceWorker === true}`
+ + `, fromDiskCache=${hop.fromDiskCache === true}`
+ + `, fromPrefetchCache=${hop.fromPrefetchCache === true}`
+ + `, serviceWorkerResponseSource=${hop.serviceWorkerResponseSource || 'none'}`;
+
/**
* Extract EVERY main-frame document network hop (each top-level navigation's
* initial request + every HTTP redirect + final response) from a captured stream
@@ -299,8 +337,11 @@ export async function navigateToUrl(url) {
* know, because Chrome resolves DNS itself (the rebinding TOCTOU).
*
* Pure + exported so the SSRF-pin decision is unit-testable without a live
- * browser. Returns `{ hops: [{ url, remoteIPAddress, status }], finalUrl,
- * mainRequestIds: string[], pendingMainRequestIds: string[] }`.
+ * browser. Returns `{ hops: [{ url, remoteIPAddress, status, fromServiceWorker,
+ * fromDiskCache, fromPrefetchCache, serviceWorkerResponseSource }], finalUrl,
+ * mainRequestIds: string[], pendingMainRequestIds: string[] }`. The delivery
+ * flags ride along so the gate can tell "Chrome dialed somewhere we can't see"
+ * apart from "Chrome made no connection at all" (see `hopMadeNoConnection`).
* `pendingMainRequestIds` are top-level navigations that STARTED but produced no
* `responseReceived` in the captured window — i.e. a navigation still in flight
* whose final connection IP was never observed. The caller must fail closed on a
@@ -334,20 +375,12 @@ export function pickMainFrameHops(messages, topFrameId = null) {
mainRequestIds.add(p.requestId);
}
if (mainRequestIds.has(p.requestId) && p.redirectResponse) {
- hops.push({
- url: p.redirectResponse.url || null,
- remoteIPAddress: p.redirectResponse.remoteIPAddress || '',
- status: p.redirectResponse.status ?? null,
- });
+ hops.push(toHop(p.redirectResponse));
}
} else if (msg.method === 'Network.responseReceived') {
if (mainRequestIds.has(p.requestId) && p.response) {
respondedIds.add(p.requestId);
- hops.push({
- url: p.response.url || null,
- remoteIPAddress: p.response.remoteIPAddress || '',
- status: p.response.status ?? null,
- });
+ hops.push(toHop(p.response));
finalUrl = p.response.url || finalUrl;
}
}
@@ -406,9 +439,22 @@ export function ssrfPinRefusalReason(messages, verifyRemoteIp, url, topFrameId =
const { hops, pendingMainRequestIds } = pickMainFrameHops(messages, topFrameId);
if (!hops.length) return 'no main-frame document response was observed';
// The main document must have a verifiable (present) connection IP — an empty
- // one can't be checked, so fail closed.
+ // one can't be checked, so fail closed. The ONE exception is a hop Chrome
+ // explicitly flagged as served without a connection (disk/prefetch cache, or a
+ // service worker answering from its own store): there is no peer to pin, and
+ // refusing it false-positives every PWA. That exception only applies when
+ // another main-frame hop in the SAME navigation did verify a real IP — a
+ // navigation where nothing was ever verified is still a refusal, so a
+ // cache-flagged response can never stand in for a network check.
+ const anyHopVerified = hops.some((hop) => hop.remoteIPAddress);
for (const hop of hops) {
- if (!hop.remoteIPAddress) return `Chrome connected to an unverifiable address for ${hop.url || url}`;
+ if (hop.remoteIPAddress) continue;
+ const noConnection = hopMadeNoConnection(hop);
+ if (noConnection && anyHopVerified) continue;
+ const detail = noConnection
+ ? `${describeHopDelivery(hop)}; no other main-frame hop verified a network address`
+ : describeHopDelivery(hop);
+ return `Chrome connected to an unverifiable address for ${hop.url || url} (${detail})`;
}
// A top-level navigation that STARTED but produced no response was never
// pinned — Chrome could be mid-connect to a private/metadata target.
@@ -448,7 +494,9 @@ export function ssrfPinRefusalReason(messages, verifyRemoteIp, url, topFrameId =
* pre-navigation `dns.lookup` cannot — Chrome resolves DNS itself, so we open a
* BLANK tab, subscribe to CDP Network events, THEN drive `Page.navigate`, keep
* the subscription open across the settle window, and check the
- * `remoteIPAddress` Chrome actually dialed for each hop.
+ * `remoteIPAddress` Chrome actually dialed for each hop. The tab also bypasses
+ * the site's service worker so a PWA's main document is fetched by Chrome
+ * itself and therefore carries a pinnable peer IP.
*
* `verifyRemoteIp(ip)` returns false to refuse. On ANY refusal (unverifiable /
* empty IP, a navigation that never yields a document response, or a top-level
@@ -491,6 +539,7 @@ export async function navigateToUrlPinned(url, {
}
const READ_ID = 3;
+ const BYPASS_SW_ID = 4;
const { default: WebSocket } = await import('ws');
const messages = [];
const result = await new Promise((resolve) => {
@@ -539,6 +588,16 @@ export async function navigateToUrlPinned(url, {
ws.on('open', () => {
ws.send(JSON.stringify({ id: 1, method: 'Network.enable' }));
+ // Bypass the site's service worker for THIS tab. A SW-mediated main
+ // document carries no `remoteIPAddress` (Chrome can't annotate a response
+ // the SW handed it, even when the SW passed the fetch straight through to
+ // the network), which the empty-IP gate below rightly refuses — so every
+ // PWA was unreadable. With the SW bypassed Chrome fetches the document
+ // itself and reports the peer IP, and the fail-closed check verifies a real
+ // address instead of being relaxed. The tab is fresh and disposable, so
+ // this has no effect on the user's normal browsing; cookies are unaffected,
+ // so a signed-in session still applies.
+ ws.send(JSON.stringify({ id: BYPASS_SW_ID, method: 'Network.setBypassServiceWorker', params: { bypass: true } }));
ws.send(JSON.stringify({ id: 2, method: 'Page.navigate', params: { url } }));
});
ws.on('message', (data) => {
@@ -551,6 +610,13 @@ export async function navigateToUrlPinned(url, {
if (msg.result?.frameId) topFrameId = msg.result.frameId;
return;
}
+ if (msg.id === BYPASS_SW_ID) {
+ // Non-fatal: a Chrome that rejects the bypass just keeps its service
+ // worker in front of the document, and the empty-IP gate still fails
+ // closed — never under-verifies.
+ if (msg.error) console.warn(`⚠️ CDP setBypassServiceWorker rejected: ${msg.error.message || 'unknown error'}`);
+ return;
+ }
if (msg.id === READ_ID) {
// DOM read returned. RE-verify over ALL events captured up to now: any
// top-level navigation that committed during the read is in `messages`,
diff --git a/server/services/browserService.test.js b/server/services/browserService.test.js
index 2a279bd219..cdc741d78c 100644
--- a/server/services/browserService.test.js
+++ b/server/services/browserService.test.js
@@ -81,7 +81,43 @@ describe('pickMainFrameHops (SSRF pin — main-frame connection IPs)', () => {
]);
expect(mainRequestIds).toEqual(['R1']);
expect(finalUrl).toBe('https://ex.com/a');
- expect(hops).toEqual([{ url: 'https://ex.com/a', remoteIPAddress: '93.184.216.34', status: 200 }]);
+ expect(hops).toEqual([{
+ url: 'https://ex.com/a',
+ remoteIPAddress: '93.184.216.34',
+ status: 200,
+ fromServiceWorker: false,
+ fromDiskCache: false,
+ fromPrefetchCache: false,
+ serviceWorkerResponseSource: null,
+ }]);
+ });
+
+ it('threads the delivery flags of every hop through (redirect AND final response)', () => {
+ // The gate needs to tell "no peer IP, no explanation" from "Chrome reported it
+ // made no connection", so the raw CDP delivery fields ride on each hop.
+ const { hops } = pickMainFrameHops([
+ docRequest('R1', 'https://ex.com/a', ''),
+ {
+ method: 'Network.requestWillBeSent',
+ params: {
+ requestId: 'R1',
+ loaderId: 'R1',
+ type: 'Document',
+ request: { url: 'https://ex.com/b' },
+ redirectResponse: { url: 'https://ex.com/a', remoteIPAddress: '93.184.216.34', status: 302, fromPrefetchCache: true },
+ },
+ },
+ {
+ method: 'Network.responseReceived',
+ params: {
+ requestId: 'R1',
+ type: 'Document',
+ response: { url: 'https://ex.com/b', remoteIPAddress: '', status: 200, fromServiceWorker: true, serviceWorkerResponseSource: 'cache-storage' },
+ },
+ },
+ ]);
+ expect(hops[0]).toMatchObject({ fromPrefetchCache: true, fromServiceWorker: false, serviceWorkerResponseSource: null });
+ expect(hops[1]).toMatchObject({ fromServiceWorker: true, fromDiskCache: false, serviceWorkerResponseSource: 'cache-storage' });
});
it('captures EVERY redirect hop IP plus the final response (per-hop pin)', () => {
@@ -177,6 +213,28 @@ describe('pickMainFrameHops (SSRF pin — main-frame connection IPs)', () => {
});
});
+describe('hopMadeNoConnection (no-network delivery classifier)', () => {
+ let hopMadeNoConnection;
+ beforeEach(async () => {
+ vi.resetModules();
+ ({ hopMadeNoConnection } = await import('./browserService.js'));
+ });
+
+ it('classifies only explicitly no-network deliveries', () => {
+ expect(hopMadeNoConnection({ fromDiskCache: true })).toBe(true);
+ expect(hopMadeNoConnection({ fromPrefetchCache: true })).toBe(true);
+ expect(hopMadeNoConnection({ serviceWorkerResponseSource: 'cache-storage' })).toBe(true);
+ expect(hopMadeNoConnection({ serviceWorkerResponseSource: 'http-cache' })).toBe(true);
+ expect(hopMadeNoConnection({ serviceWorkerResponseSource: 'fallback-code' })).toBe(true);
+ // A service worker that passed the request THROUGH to the network did make a
+ // connection — it just isn't annotated with the peer IP. Not exempt.
+ expect(hopMadeNoConnection({ fromServiceWorker: true, serviceWorkerResponseSource: 'network' })).toBe(false);
+ expect(hopMadeNoConnection({ fromServiceWorker: true })).toBe(false);
+ expect(hopMadeNoConnection({})).toBe(false);
+ expect(hopMadeNoConnection(null)).toBe(false);
+ });
+});
+
describe('ssrfPinRefusalReason (SSRF pin gate)', () => {
let ssrfPinRefusalReason;
beforeEach(async () => {
@@ -189,9 +247,9 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {
method: 'Network.requestWillBeSent',
params: { requestId, loaderId: requestId, type: 'Document', request: { url }, ...(redirectResponse ? { redirectResponse } : {}) },
});
- const docResponse = (requestId, url, remoteIPAddress) => ({
+ const docResponse = (requestId, url, remoteIPAddress, delivery = {}) => ({
method: 'Network.responseReceived',
- params: { requestId, type: 'Document', response: { url, remoteIPAddress, status: 200 } },
+ params: { requestId, type: 'Document', response: { url, remoteIPAddress, status: 200, ...delivery } },
});
it('passes (null) when every main-frame hop dialed an allowed IP', () => {
@@ -229,6 +287,70 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {
docResponse('R1', 'https://ex.com/a', ''),
], allow, 'https://ex.com/a');
expect(reason).toMatch(/unverifiable address/);
+ // The refusal names the cause so the next occurrence is diagnosable.
+ expect(reason).toMatch(/no remoteIPAddress; fromServiceWorker=false, fromDiskCache=false, fromPrefetchCache=false, serviceWorkerResponseSource=none/);
+ });
+
+ it('refuses a service-worker main document that passed the fetch to the NETWORK (empty IP, no no-network flag)', () => {
+ // The exact shape that broke Stacker News: the SW mediated the document, so
+ // Chrome reports no peer IP even though a real h2 fetch happened. That is NOT
+ // a no-network delivery, so the fail-closed gate must still refuse — the fix
+ // is the `Network.setBypassServiceWorker` in navigateToUrlPinned, not a
+ // relaxation here.
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://pwa.example/'),
+ docResponse('R1', 'https://pwa.example/', '', { fromServiceWorker: true, serviceWorkerResponseSource: 'network' }),
+ ], allow, 'https://pwa.example/');
+ expect(reason).toMatch(/unverifiable address/);
+ expect(reason).toMatch(/fromServiceWorker=true/);
+ expect(reason).toMatch(/serviceWorkerResponseSource=network/);
+ });
+
+ it('allows a cache-served main-frame hop when another hop verified a real IP', () => {
+ // R1 loaded from the network and pinned a real address; a client-side nav
+ // (R2) was then answered from the disk cache — no connection was made, so
+ // there is nothing to pin and refusing would be a false positive.
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://ex.com/a'),
+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),
+ docRequest('R2', 'https://ex.com/b'),
+ docResponse('R2', 'https://ex.com/b', '', { fromDiskCache: true }),
+ ], allow, 'https://ex.com/a');
+ expect(reason).toBeNull();
+ });
+
+ it('allows a service-worker hop served from cache-storage when another hop verified a real IP', () => {
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://pwa.example/'),
+ docResponse('R1', 'https://pwa.example/', '93.184.216.34'),
+ docRequest('R2', 'https://pwa.example/offline'),
+ docResponse('R2', 'https://pwa.example/offline', '', { fromServiceWorker: true, serviceWorkerResponseSource: 'cache-storage' }),
+ ], allow, 'https://pwa.example/');
+ expect(reason).toBeNull();
+ });
+
+ it('refuses a cache-served main document when NO main-frame hop verified an IP', () => {
+ // A fully cache-served navigation pinned nothing at all — a cache flag can
+ // never stand in for a network check, so this still fails closed.
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://pwa.example/'),
+ docResponse('R1', 'https://pwa.example/', '', { fromServiceWorker: true, serviceWorkerResponseSource: 'cache-storage' }),
+ ], allow, 'https://pwa.example/');
+ expect(reason).toMatch(/unverifiable address/);
+ expect(reason).toMatch(/no other main-frame hop verified a network address/);
+ });
+
+ it('still refuses a disallowed sub-resource on a page whose main doc was cache-served', () => {
+ // The no-connection exception covers ONLY the main-frame empty-IP check;
+ // every real connection the page made is still verified by collectConnectedIps.
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://pwa.example/'),
+ docResponse('R1', 'https://pwa.example/', '93.184.216.34'),
+ docRequest('R2', 'https://pwa.example/app'),
+ docResponse('R2', 'https://pwa.example/app', '', { fromDiskCache: true }),
+ { method: 'Network.responseReceived', params: { requestId: 'R3', type: 'XHR', response: { url: 'https://pwa.example/latest/meta-data', remoteIPAddress: '169.254.169.254', status: 200 } } },
+ ], allow, 'https://pwa.example/');
+ expect(reason).toMatch(/disallowed address 169\.254\.169\.254/);
});
it('refuses a SUB-RESOURCE / fetch that dialed a blocked IP (rebind after page load)', () => {