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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: require both user IDs before certifying Stacker News territory ownership (#3318)
[._.]/ Adam Eivy0fdfcfd2efc8
diff --git a/server/services/stackerNews.js b/server/services/stackerNews.jsindex 926892e381..20c96d9a69 100644--- a/server/services/stackerNews.js+++ b/server/services/stackerNews.js@@ -420,7 +420,11 @@ async function syncAccountUnlocked(accountId, { force = false } = {}) {const monitored = territory.monitoringEnabled ?? account.monitoring_enabled;if (!force && !monitored) continue;const remote = (await read('sub', { name: territory.slug }))?.sub;- const ownershipVerified = Boolean(remote && String(remote.userId) === String(me.id));+ // BOTH IDs must be present: `String(null) === String(null)` would otherwise+ // certify ownership from two absences, and the browser identity extractor's+ // profile-link fallback legitimately has no user ID. Ownership evidence+ // gates territory-settings execution, so it fails closed.+ const ownershipVerified = Boolean(remote && remote.userId != null && me.id != null && String(remote.userId) === String(me.id));await query('UPDATE stacker_news_territories SET remote_settings=$2,remote_refreshed_at=NOW(),updated_at=NOW() WHERE id=$1',[territory.id, { ...(remote || {}), ownershipVerified }],diff --git a/server/services/stackerNewsSync.test.js b/server/services/stackerNewsSync.test.jsindex 070428904a..4811e39599 100644--- a/server/services/stackerNewsSync.test.js+++ b/server/services/stackerNewsSync.test.js@@ -20,11 +20,12 @@ const executeStackerNewsOperation = vi.fn(async (name, input) => {if (name === 'sub') return { sub: { name: 'art', userId: 'owner-1' } };return itemsPage(input.cursor);});-const executeStackerNewsBrowserRead = vi.fn(async (name, input = {}) => {+const browserRead = async (name, input = {}) => {if (name === 'me') return { me: { id: 'owner-1', name: 'example_user' } };if (name === 'sub') return { sub: { name: 'art', userId: 'owner-1' } };return itemsPage(input.cursor);-});+};+const executeStackerNewsBrowserRead = vi.fn(browserRead);vi.mock('../lib/db.js', () => ({ query, withTransaction: vi.fn() }));vi.mock('../lib/vaultCrypto.js', () => ({ decryptValue: () => 'api-key', encryptValue: vi.fn(), ensureVaultKey: vi.fn() }));vi.mock('../integrations/stackerNews/index.js', () => ({ executeStackerNewsOperation, executeStackerNewsBrowserRead, stackerNewsCapabilities: {} }));@@ -36,7 +37,7 @@ describe('Stacker News sync', () => {beforeEach(() => {query.mockClear();executeStackerNewsOperation.mockClear();- executeStackerNewsBrowserRead.mockClear();+ executeStackerNewsBrowserRead.mockReset().mockImplementation(browserRead);accountRow = { ...baseAccount, read_transport: 'api' };credentialRows = [{ api_key_enc: 'ciphertext' }];});@@ -66,6 +67,20 @@ describe('Stacker News sync', () => {expect(itemCalls.map(([, input]) => input.cursor)).toEqual([null, 'page-2']);});+ // The browser identity extractor's profile-link fallback has no user ID, and a+ // territory page can omit one too — two absences must not certify ownership.+ it('refuses to verify ownership when either side has no user ID', async () => {+ accountRow = { ...baseAccount };+ credentialRows = [];+ executeStackerNewsBrowserRead.mockImplementation(async (name, input = {}) => {+ if (name === 'me') return { me: { id: null, name: 'example_user' } };+ if (name === 'sub') return { sub: { name: 'art', userId: null } };+ return itemsPage(input.cursor);+ });+ await syncAccount(accountId, { force: true });+ expect(query.mock.calls.some(([sql, params]) => sql.startsWith('UPDATE stacker_news_territories') && params[1].ownershipVerified === false)).toBe(true);+ });+it('still refuses an API-transport account with no key', async () => {credentialRows = [];await expect(syncAccount(accountId, { force: true })).rejects.toThrow('Stacker News API key is not configured');