Spaces:
Running
Running
Revert "fix(fingerprint): refine history management and prevent data leakage"
Browse filesFiles changed (5)
459 unmodified lines460461462463464465466115 unmodified lines582583584585586587588589590591459 unmodified lines// Include quota threshold settingsquotaThreshold: a.quotaThreshold,modelQuotaThresholds: a.modelQuotaThresholds || {},hasFingerprint: !!a.fingerprint}))};}115 unmodified linesaccount.fingerprintHistory.unshift(historyEntry);}// Remove the restored entry from history (shifted by 1 if we just unshifted)const removeIndex = account.fingerprint ? historyIndex + 1 : historyIndex;account.fingerprintHistory.splice(removeIndex, 1);// Restoreaccount.fingerprint = { ...restoredEntry.fingerprint, createdAt: Date.now() };459 unmodified lines460461462463464465466115 unmodified lines582583584585586587459 unmodified lines// Include quota threshold settingsquotaThreshold: a.quotaThreshold,modelQuotaThresholds: a.modelQuotaThresholds || {},fingerprint: a.fingerprint}))};}115 unmodified linesaccount.fingerprintHistory.unshift(historyEntry);}// Restoreaccount.fingerprint = { ...restoredEntry.fingerprint, createdAt: Date.now() };
83 unmodified lines848586878889909183 unmodified linesemail: authData.email || 'default@antigravity',source: 'database',lastUsed: null,modelRateLimits: {},fingerprint: generateFingerprint()};const tokenCache = new Map();83 unmodified lines8485868788899083 unmodified linesemail: authData.email || 'default@antigravity',source: 'database',lastUsed: null,modelRateLimits: {}};const tokenCache = new Map();
575 unmodified lines576577578579580581582583575 unmodified lines// Quota threshold settingsquotaThreshold: metadata.quotaThreshold,modelQuotaThresholds: metadata.modelQuotaThresholds || {},// Include fingerprint existence (details via /api/accounts/:email/fingerprint)hasFingerprint: !!metadata.fingerprint,// Subscription data (new)subscription: acc.subscription || metadata.subscription || { tier: 'unknown', projectId: null },// Quota limits575 unmodified lines576577578579580581582583575 unmodified lines// Quota threshold settingsquotaThreshold: metadata.quotaThreshold,modelQuotaThresholds: metadata.modelQuotaThresholds || {},// Include fingerprintfingerprint: metadata.fingerprint,// Subscription data (new)subscription: acc.subscription || metadata.subscription || { tier: 'unknown', projectId: null },// Quota limits
120 unmodified lines121122123124125126127120 unmodified linesexport function updateFingerprintVersion(fingerprint) {if (!fingerprint || !fingerprint.userAgent) return fingerprint;const match = fingerprint.userAgent.match(/^antigravity\/\S+ (.+)$/);if (match) {const platformArch = match[1];const expectedUserAgent = `antigravity/${ANTIGRAVITY_VERSION} ${platformArch}`;120 unmodified lines121122123124125126127120 unmodified linesexport function updateFingerprintVersion(fingerprint) {if (!fingerprint || !fingerprint.userAgent) return fingerprint;const match = fingerprint.userAgent.match(/^antigravity\/[\d.]+ (.+)$/);if (match) {const platformArch = match[1];const expectedUserAgent = `antigravity/${ANTIGRAVITY_VERSION} ${platformArch}`;
130 unmodified lines131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168109 unmodified lines278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392130 unmodified linesassert(updatedFp.userAgent.includes('darwin/x64'), 'Should preserve platform/arch');});test('updateFingerprintVersion handles non-numeric versions (e.g. beta)', () => {const fp = generateFingerprint();const betaFp = { ...fp, userAgent: 'antigravity/1.0.0-beta.2 linux/arm64' };const updatedFp = updateFingerprintVersion(betaFp);assertEqual(updatedFp.userAgent, `antigravity/${ANTIGRAVITY_VERSION} linux/arm64`, 'Should update beta version');});test('updateFingerprintVersion handles pre-release suffixes', () => {const fp = generateFingerprint();const rcFp = { ...fp, userAgent: 'antigravity/2.0.0-rc1+build.123 win32/x64' };const updatedFp = updateFingerprintVersion(rcFp);assertEqual(updatedFp.userAgent, `antigravity/${ANTIGRAVITY_VERSION} win32/x64`, 'Should update rc version');});test('updateFingerprintVersion returns same fingerprint when already current', () => {const fp = generateFingerprint();const updatedFp = updateFingerprintVersion(fp);assertEqual(updatedFp.userAgent, fp.userAgent, 'Should not change current version');// Should return the exact same object reference when no update neededassert(updatedFp === fp, 'Should return same object when no change needed');});test('buildFingerprintHeaders returns empty object for null/undefined', () => {const headers1 = buildFingerprintHeaders(null);assertEqual(Object.keys(headers1).length, 0, 'null should return empty headers');const headers2 = buildFingerprintHeaders(undefined);assertEqual(Object.keys(headers2).length, 0, 'undefined should return empty headers');});// ==========================================================================// 2. ACCOUNT MANAGER INTEGRATION// ==========================================================================109 unmodified linesassertEqual(historyAfter[0].reason, 'restored', 'Reason should be "restored"');});await asyncTest('restoreFingerprint removes restored entry from history (no duplicates)', async (configPath) => {const initialConfig = {accounts: [{email: 'test@example.com',source: 'manual',apiKey: 'key',enabled: true}],settings: {}};fs.writeFileSync(configPath, JSON.stringify(initialConfig));const manager = new AccountManager(configPath);await manager.initialize();const email = 'test@example.com';// Initial fingerprint = FP0const fp0 = manager.getAllAccounts()[0].fingerprint;// Regenerate: current=FP1, history=[FP0]manager.regenerateFingerprint(email);const fp1 = manager.getAllAccounts()[0].fingerprint;// Regenerate: current=FP2, history=[FP1, FP0]manager.regenerateFingerprint(email);const fp2 = manager.getAllAccounts()[0].fingerprint;// Restore index 1 (FP0): current=FP0, history should=[FP2, FP1] (FP0 removed from history)manager.restoreFingerprint(email, 1);const currentAfter = manager.getAllAccounts()[0].fingerprint;const historyAfter = manager.getFingerprintHistory(email);assertEqual(currentAfter.deviceId, fp0.deviceId, 'Should restore FP0 as current');// The restored entry (FP0) should NOT appear in historyconst fp0InHistory = historyAfter.filter(h => h.fingerprint.deviceId === fp0.deviceId);assertEqual(fp0InHistory.length, 0, 'Restored fingerprint should be removed from history');// FP2 (the pre-restore current) should be in historyconst fp2InHistory = historyAfter.filter(h => h.fingerprint.deviceId === fp2.deviceId);assertEqual(fp2InHistory.length, 1, 'Pre-restore current (FP2) should be in history');// FP1 should still be in historyconst fp1InHistory = historyAfter.filter(h => h.fingerprint.deviceId === fp1.deviceId);assertEqual(fp1InHistory.length, 1, 'FP1 should still be in history');});await asyncTest('restoreFingerprint with index 0 removes correctly', async (configPath) => {const initialConfig = {accounts: [{email: 'test@example.com',source: 'manual',apiKey: 'key',enabled: true}],settings: {}};fs.writeFileSync(configPath, JSON.stringify(initialConfig));const manager = new AccountManager(configPath);await manager.initialize();const email = 'test@example.com';// current=FP0const fp0 = manager.getAllAccounts()[0].fingerprint;// Regenerate: current=FP1, history=[FP0]manager.regenerateFingerprint(email);const fp1 = manager.getAllAccounts()[0].fingerprint;// Restore index 0 (FP0): current=FP0, history should=[FP1]manager.restoreFingerprint(email, 0);const currentAfter = manager.getAllAccounts()[0].fingerprint;const historyAfter = manager.getFingerprintHistory(email);assertEqual(currentAfter.deviceId, fp0.deviceId, 'Should restore FP0');assertEqual(historyAfter.length, 1, 'History should have exactly 1 entry');assertEqual(historyAfter[0].fingerprint.deviceId, fp1.deviceId, 'History should contain FP1');});await asyncTest('getStatus exposes hasFingerprint boolean, not full fingerprint', async (configPath) => {const initialConfig = {accounts: [{email: 'test@example.com',source: 'manual',apiKey: 'key',enabled: true}],settings: {}};fs.writeFileSync(configPath, JSON.stringify(initialConfig));const manager = new AccountManager(configPath);await manager.initialize();const status = manager.getStatus();const acc = status.accounts[0];// Should have hasFingerprint booleanassertEqual(acc.hasFingerprint, true, 'hasFingerprint should be true');// Should NOT have full fingerprint objectassertEqual(acc.fingerprint, undefined, 'Full fingerprint should not be in status');// Verify it does NOT expose deviceId, sessionToken, quotaUserassertEqual(acc.deviceId, undefined, 'deviceId should not leak into status');assertEqual(acc.sessionToken, undefined, 'sessionToken should not leak into status');});// ==========================================================================// 3. PERSISTENCE & CLI COMPATIBILITY// ==========================================================================130 unmodified lines131132133134135136109 unmodified lines246247248249250251130 unmodified linesassert(updatedFp.userAgent.includes('darwin/x64'), 'Should preserve platform/arch');});// ==========================================================================// 2. ACCOUNT MANAGER INTEGRATION// ==========================================================================109 unmodified linesassertEqual(historyAfter[0].reason, 'restored', 'Reason should be "restored"');});// ==========================================================================// 3. PERSISTENCE & CLI COMPATIBILITY// ==========================================================================
src/account-manager/index.js+1-5
src/account-manager/storage.js+1-2
src/server.js+2-2
src/utils/fingerprint.js+1-1
tests/test-fingerprint.cjs-141