fix(editor): salt the session record's fingerprint with its tag

This commit is contained in:
bchanot committed 2026-11-14 18:49:09 +01:00
1 parent 2ad720b34e
commit 7ecaf1998e
3 files changed
+64 -26

No files matched your search

@@ -6,6 +6,7 @@ import {
startSessionTagSync,
useSessionTagStore,
} from '@/editor/history/sessionTag'
import { fingerprintOf } from '@/editor/history/fingerprint'
import { leftDraftKey } from '@/editor/leftDraft'
import { useAuthStore } from '@/state/authStore'
@@ -100,6 +101,29 @@ describe('resolveSessionTag', () => {
})
})
describe('the fingerprint of the record (security LOW, rev 4)', () => {
it('is salted with its own tag: two tags of one account differ', () => {
resolveSessionTag('account-a')
const first = stored()!
forgetSessionTag()
reload()
resolveSessionTag('account-a')
const second = stored()!
expect(second.tag).not.toBe(first.tag)
expect(second.account).not.toBe(first.account)
expect(first.account).toBe(fingerprintOf(`${first.tag}:account-a`))
})
it('reads an unsalted record of the older shape as none, and rotates', () => {
const tag = 'a'.repeat(32)
const account = fingerprintOf('account-a')
sessionStorage.setItem(STORAGE_KEY, JSON.stringify({ tag, account }))
expect(resolveSessionTag('account-a')).not.toBe(tag)
reload()
expect(resolveSessionTag('account-a')).toBe(stored()!.tag)
})
})
describe('the sweep of flags keyed by an account id (older shape)', () => {
it('removes them on start and keeps the flags of a tag', () => {
const older = 'faunosteo:editor:left-draft:S:account-a'