Q2 (IAWL idea 16): Payload locks a staff account after 5 wrong passwords from anybody, so a stranger kept the owner out without a password. Failed sign-ins are now counted per client IP and typed address (folded: NFKC, lower case, trim): 5 in 15 min, then 429 for that IP and address only; only failures count (a place taken before the compare, given back on success or refusal; "try again in a moment" while others are being checked). Payload's own lock stays as the net at 50 failures for an hour where the project set none. The mail service's account-mail limit now counts per address per visitor (5) with 20 per address in all, so one stranger no longer blocks the owner's own reset mail. Q3 (idea 7): staff login, forgot and reset password refuse a request a browser marks as coming from another origin (403 before anything is counted or sent); visitor collections untouched. Q5 (idea 29): an account that changes its own e-mail, username or password must send its current password (panel field on the account page via the plugin's MaskedField, no import-map change; REST and GraphQL). Admins changing others, server code and API keys are not asked; wrong ones count like failed sign-ins. Options accounts.signInLimit / signInSameOrigin / confirmOwnChanges, all validated at start. Tests: 15 HTTP tests (2FA on/off, all off), fail before on 1.17.1; built-site spec own-account.spec.ts in e2e:built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
85 lines
5.2 KiB
TypeScript
85 lines
5.2 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
import { randomUUID } from 'node:crypto'
|
|
|
|
import { totp } from './totp'
|
|
|
|
/**
|
|
* On the BUILT site (pnpm e2e:built, webpack and Turbopack), what 1.18.0 changed for one's own account and the
|
|
* sign-in of staff:
|
|
* - the account page has a "Current password" field; saving a new e-mail without it is refused on that field,
|
|
* with it the e-mail changes (accounts.confirmOwnChanges);
|
|
* - five failed sign-ins from one place for an address answer 429 there, the owner elsewhere still signs in
|
|
* (accounts.signInLimit); a staff sign-in from another origin gets 403 (accounts.signInSameOrigin).
|
|
* The accounts are fresh ones made here (the test admins are never touched). Needs the E2E_* test admin.
|
|
*/
|
|
const { E2E_ADMIN_EMAIL: adminEmail, E2E_ADMIN_PASSWORD: adminPassword, E2E_TOTP_SECRET: secret } = process.env
|
|
const SECRET = 'JPURUZNWYTZX2L42MT4SS7736WWNQWBM'
|
|
|
|
test('own account: a new e-mail needs the current password, in the panel', async ({ baseURL, browser, playwright }) => {
|
|
test.skip(!adminEmail || !adminPassword || !secret, 'E2E_* test admin not configured')
|
|
test.setTimeout(120_000)
|
|
const email = `own-${randomUUID().slice(0, 8)}@example.com`
|
|
const password = `O-${randomUUID()}`
|
|
// made by the test admin; its TOTP set up over the API with a secret of our own
|
|
const admin = await playwright.request.newContext({ baseURL, extraHTTPHeaders: { origin: baseURL! } })
|
|
expect((await admin.post('/api/users/login', { data: { email: adminEmail, password: adminPassword } })).status()).toBe(200)
|
|
expect((await (await admin.post('/api/verify-totp', { data: { token: totp(secret!) } })).json()).ok).toBe(true)
|
|
expect((await admin.post('/api/users', { data: { email, password, roles: ['editor'] } })).status()).toBe(201)
|
|
await admin.dispose()
|
|
const own = await playwright.request.newContext({ baseURL, extraHTTPHeaders: { origin: baseURL! } })
|
|
expect((await own.post('/api/users/login', { data: { email, password } })).status()).toBe(200)
|
|
expect((await (await own.post('/api/setup-totp', { data: { secret: SECRET, token: totp(SECRET) } })).json()).ok).toBe(true)
|
|
await own.dispose()
|
|
|
|
const context = await browser.newContext({ baseURL })
|
|
const page = await context.newPage()
|
|
await page.goto('/admin/login')
|
|
await page.fill('#field-email', email)
|
|
await page.fill('#field-password', password)
|
|
await page.click('.form-submit button')
|
|
await page.waitForURL(/verify-totp/, { waitUntil: 'commit' })
|
|
await page.getByRole('textbox').first().click()
|
|
await page.keyboard.type(totp(SECRET))
|
|
await expect(page).toHaveTitle(/Dashboard|Pulpit/, { timeout: 20_000 })
|
|
|
|
await page.goto('/admin/account')
|
|
const current = page.locator('#field-currentPassword')
|
|
await expect(current).toBeVisible({ timeout: 20_000 })
|
|
await expect(current).toHaveAttribute('type', 'password')
|
|
const renamed = `renamed-${randomUUID().slice(0, 8)}@example.com`
|
|
await page.fill('#field-email', renamed)
|
|
await page.click('#action-save')
|
|
await expect(page.getByText(/Enter your current password|Wpisz obecne hasło/).first()).toBeVisible({ timeout: 20_000 })
|
|
await current.fill(password)
|
|
await page.click('#action-save')
|
|
await expect.poll(async () => {
|
|
const check = await playwright.request.newContext({ baseURL })
|
|
const status = (await check.post('/api/users/login', { data: { email: renamed, password } })).status()
|
|
await check.dispose()
|
|
return status
|
|
}, { timeout: 20_000 }).toBe(200)
|
|
await context.close()
|
|
})
|
|
|
|
test('staff sign-in: five failures from one place answer 429 there, not elsewhere; another origin gets 403', async ({ baseURL, playwright }) => {
|
|
test.skip(!adminEmail || !adminPassword || !secret, 'E2E_* test admin not configured')
|
|
const email = `limit-${randomUUID().slice(0, 8)}@example.com`
|
|
const password = `S-${randomUUID()}`
|
|
const admin = await playwright.request.newContext({ baseURL, extraHTTPHeaders: { origin: baseURL! } })
|
|
expect((await admin.post('/api/users/login', { data: { email: adminEmail, password: adminPassword } })).status()).toBe(200)
|
|
expect((await (await admin.post('/api/verify-totp', { data: { token: totp(secret!) } })).json()).ok).toBe(true)
|
|
expect((await admin.post('/api/users', { data: { email, password, roles: ['editor'] } })).status()).toBe(201)
|
|
await admin.dispose()
|
|
// the site reads the client address from IAPL_IP_HEADER (reference/.env: x-forwarded-for, one proxy)
|
|
const from = async (ip: string) => playwright.request.newContext({ baseURL, extraHTTPHeaders: { 'x-forwarded-for': ip } })
|
|
const stranger = await from('198.51.100.123')
|
|
for (let i = 0; i < 5; i++) {expect((await stranger.post('/api/users/login', { data: { email, password: 'a-wrong-password' } })).status()).toBe(401)}
|
|
expect((await stranger.post('/api/users/login', { data: { email, password } })).status()).toBe(429)
|
|
const owner = await from('203.0.113.123')
|
|
expect((await owner.post('/api/users/login', { data: { email, password } })).status()).toBe(200)
|
|
const foreign = await owner.post('/api/users/login', { data: { email, password }, headers: { origin: 'https://blog.example.test', 'sec-fetch-site': 'same-site' } })
|
|
expect(foreign.status()).toBe(403)
|
|
await stranger.dispose()
|
|
await owner.dispose()
|
|
})
|