diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-14 01:53:04 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-14 01:53:04 +0200 |
| commit | 392b5e4a53aace725794c7bbabf9e95fb4e1b9c5 (patch) | |
| tree | 0d31021b8558833a822bb906ec59d95abeb3f860 /packages/meshbay-hub/src/meshbay_hub/static/admin-page.js | |
| parent | 413837a0845240241ed7e9d9ac1f3b1dc45a2f40 (diff) | |
| download | meshbay-392b5e4a53aace725794c7bbabf9e95fb4e1b9c5.tar.gz | |
fix(hub): a per-account sign-in lockout, and a reviewed unauthenticated surface
Passphrase sign-in locks per username: after `login.max_failures` wrong
passphrases (default 4) the name is refused with `429 account_locked` and a
`Retry-After` for `login.lockout_minutes` (default 60), without the passphrase
being checked. Both numbers are instance policy an admin sets from the panel;
zero failures turns it off. The per-IP limit bounds one address, and IPv6
gives every subscriber a /64 of them — an online guess targets an account, so
the account is what is counted.
- Counted by the name as typed, existing or not, so `login` stays uniform (M1).
The key is a hash: people type passphrases into the username field.
- The attempt is taken before the check in one `INSERT … ON CONFLICT DO UPDATE
… WHERE … RETURNING`, so a concurrent burst gets no more than the limit.
- Sign-in, passphrase change and account deletion count on the same row; the
last had no rate limit at all.
- A lockout refuses passphrase sign-in and nothing else: sessions, renewal and
device sign-in continue, and a reset code clears it (AV26). A session learns
its own lockout from `/v1/users/me`, and the passphrase change checks it
before re-wrapping any node's bundle — the hub accepts the new passphrase
only after the nodes have it.
The SPA now shows what the hub said. `loginAndRecover` threw "Login failed:
{json}", so `email_verification_required` never matched and was never shown;
the passphrase-change form rendered no error at all in its first phase.
The unauthenticated surface, reviewed route by route:
- No `/docs`, `/redoc` or `/openapi.json`, in the code. The Caddyfile hid them
on meshbay.org only; a packaged hub behind any other proxy published all three.
- The node socket's first message must arrive within ten seconds. It is
accepted before anyone is known, and an unbounded read is a connection any
stranger holds for free.
- `/v1/relays` answers 503 behind `relay.RELAYS_ENABLED`, as federation does:
nothing in the tree calls it and two of its routes take no account.
- `test_unauthenticated_surface.py` walks every route and fails on one without
an authentication dependency that is not listed with its reason.
Verified in Chrome against a local hub: the lockout and wrong-passphrase
messages, the admin section saving both lockout and mail limits, and the
passphrase change refused while locked. Not verified in Firefox (a running
instance blocks the headless one), nor the upsert's concurrency on PostgreSQL.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LcF3QKWii7uQ2kSyXErzCt
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/admin-page.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/admin-page.js | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/admin-page.js b/packages/meshbay-hub/src/meshbay_hub/static/admin-page.js index 8800615..c40d240 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/admin-page.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/admin-page.js @@ -16,6 +16,7 @@ export function AdminPage({ token, role }) { // Edited values live here until Save, so a half-typed number is never sent // and a rejected one never looks applied. const [mailDraft, setMailDraft] = useState(null); + const [loginDraft, setLoginDraft] = useState(null); const [users, setUsers] = useState([]); const [usersTotal, setUsersTotal] = useState(0); const [userSearch, setUserSearch] = useState(''); @@ -43,6 +44,7 @@ export function AdminPage({ token, role }) { const data = await hubFetch('/v1/admin/settings', { token }); setSettings(data); setMailDraft({ ...data.mail }); + setLoginDraft({ ...data.login }); } catch (e) { setError(e.message); } try { setMailStatus(await hubFetch('/v1/admin/mail', { token })); @@ -61,6 +63,7 @@ export function AdminPage({ token, role }) { // The hub clamps what it was given, so the draft is reset from the // answer rather than left showing a number that was not stored. setMailDraft({ ...data.mail }); + setLoginDraft({ ...data.login }); if (patch.mail) { try { setMailStatus(await hubFetch('/v1/admin/mail', { token })); @@ -193,6 +196,14 @@ const MAIL_FIELDS = [ 'email_change_cooldown', ]; +const LOGIN_FIELDS = ['max_failures', 'lockout_minutes']; + +// Only what changed, and only what is a number: an empty field is someone +// mid-edit, not a request to set zero. +const changedNumbers = (fields, draft, stored) => Object.fromEntries(fields + .filter(k => draft[k] !== '' && draft[k] !== null && Number(draft[k]) !== stored[k]) + .map(k => [k, Number(draft[k])])); + const TABS = ['general', 'stats', 'users', 'groups', 'nodes', 'logs', 'blocklist']; const canEditSettings = role === 'admin'; @@ -247,12 +258,7 @@ const TABS = ['general', 'stats', 'users', 'groups', 'nodes', 'logs', 'blocklist <div class="settings-row"> <button class="btn" disabled=${settingsSaving} onClick=${() => saveSettings({ - mail: Object.fromEntries(MAIL_FIELDS - // Only what changed, and only what is a number: an empty - // field is someone mid-edit, not a request to set zero. - .filter(k => mailDraft[k] !== '' && mailDraft[k] !== null - && Number(mailDraft[k]) !== settings.mail[k]) - .map(k => [k, Number(mailDraft[k])])), + mail: changedNumbers(MAIL_FIELDS, mailDraft, settings.mail), })}>${t('admin.mail_save')}</button> <button class="btn btn-secondary" disabled=${settingsSaving} onClick=${() => setMailDraft({ ...settings.mail_defaults })} @@ -260,6 +266,37 @@ const TABS = ['general', 'stats', 'users', 'groups', 'nodes', 'logs', 'blocklist </div> `} </div> + + ${settings.login && html` + <div class="settings-section"> + <h3 class="settings-heading">${t('admin.login_heading')}</h3> + <p class="settings-hint">${t('admin.login_hint')}</p> + + ${loginDraft && LOGIN_FIELDS.map(key => html` + <div class="settings-row" key=${key}> + <span class="settings-label">${t('admin.login_' + key)}</span> + <input type="number" class="settings-number" + min=${(settings.login_bounds?.[key] || [0])[0]} + max=${(settings.login_bounds?.[key] || [0, 0])[1]} + value=${loginDraft[key]} + disabled=${!canEditSettings || settingsSaving} + onInput=${e => setLoginDraft(d => ({ ...d, [key]: e.target.value }))} /> + </div> + `)} + + ${canEditSettings && loginDraft && html` + <div class="settings-row"> + <button class="btn" disabled=${settingsSaving} + onClick=${() => saveSettings({ + login: changedNumbers(LOGIN_FIELDS, loginDraft, settings.login), + })}>${t('admin.login_save')}</button> + <button class="btn btn-secondary" disabled=${settingsSaving} + onClick=${() => setLoginDraft({ ...settings.login_defaults })} + >${t('admin.mail_reset_defaults')}</button> + </div> + `} + </div> + `} `} ${tab === 'stats' && stats && html` @@ -436,7 +473,7 @@ const TABS = ['general', 'stats', 'users', 'groups', 'nodes', 'logs', 'blocklist loadLogs(e.target.value, 0); }}> <option value="">${t('admin.filter_all')}</option> - ${['login', 'login_fail', 'account_create', 'token_refresh', 'group_create', + ${['login', 'login_fail', 'login_locked', 'account_create', 'token_refresh', 'group_create', 'group_join', 'group_leave', 'node_announce', 'revoke_user', 'revoke_group', 'admin_user_update', 'admin_group_update'].map(ev => html` <option key=${ev} value=${ev}>${ev}</option> |