Files
KomediruzeckiandGitHub 820c8f68be fix(auth): confirming an address clears what was set up before it, and email links finish after sign-in (#610)
- Google sign-in, an emailed sign-in code and a reset link confirm an account's address. On an
  account whose address was never confirmed, each first clears what was set up on it (sessions,
  password, passkeys, two-factor, API tokens, unused links) in the same D1 batch, and the app says
  once what went.
- A new session or credential is written only while the account's token_version is still the one
  its check read.
- Confirm and change-of-address links take effect only with their own account's session. Opened
  elsewhere, they finish after signing in there. A browser that starts local-first opens the
  sign-in for them, and the reset page works there too.
- Google sign-in keeps and matches addresses in lower case. A reset link is refused once it has
  expired. An expired API token stops counting against the plan's limit. Deleting an account
  deletes its sessions.
2026-10-09 17:14:15 +02:00

48 lines
1.8 KiB
TypeScript

import { env, SELF } from 'cloudflare:test';
import { beforeEach, describe, expect, it } from 'vitest';
import { sessionCookie } from './helpers/session';
// CSV export: the formula-injection guard must quote attacker-shaped STRINGS but leave
// plain numbers alone — it used to turn every negative balance into text ("'-2392.21").
let cookie = '';
beforeEach(async () => {
for (const t of ['accounts', 'profiles', 'users']) {
await env.DB.prepare(`DELETE FROM ${t}`).run();
}
await env.DB.batch([
env.DB.prepare(
"INSERT INTO users (id, email, auth_provider, token_version) VALUES (60, 'csv@example.com', 'password', 1)"
),
env.DB.prepare("INSERT INTO profiles (id, user_id, name) VALUES (600, 60, 'Main')"),
env.DB.prepare(
"INSERT INTO accounts (profile_id, name, type, currency, balance) VALUES (600, 'WRev', 'giro', 'USD', -2392.21)"
),
env.DB.prepare(
"INSERT INTO accounts (profile_id, name, type, currency, balance) VALUES (600, '=HYPERLINK(\"http://evil\")', 'giro', 'USD', 10)"
),
]);
cookie = (await sessionCookie(60, 'password', env)).split(';')[0];
});
describe('GET /api/export/accounts (CSV)', () => {
it('exports negative balances as plain numbers, not quoted text', async () => {
const res = await SELF.fetch('https://example.com/api/export/accounts?format=csv', {
headers: { Cookie: cookie },
});
expect(res.status).toBe(200);
const csv = await res.text();
expect(csv).toContain('-2392.21');
expect(csv).not.toContain("'-2392.21");
});
it('still quotes formula-shaped strings', async () => {
const res = await SELF.fetch('https://example.com/api/export/accounts?format=csv', {
headers: { Cookie: cookie },
});
const csv = await res.text();
expect(csv).toContain("'=HYPERLINK");
});
});