Login UX: 7s failure delay, spinner on sign-in button

This commit is contained in:
Clay 2026-12-03 15:57:44 -05:00
parent 7cf684c133
commit 70b902d6d9
5 changed files with 31 additions and 7 deletions

View file

@ -104,7 +104,7 @@ Against local open-oscar-server 0.25.0 with `DISABLE_AUTH=true`, TOC listener 98
2. **UI polish follow-up:** unread indicators, chat room membership/invite-send UI, better mobile layout. (Tab close/leave for PMs and chat rooms added 2026-12-03.) 2. **UI polish follow-up:** unread indicators, chat room membership/invite-send UI, better mobile layout. (Tab close/leave for PMs and chat rooms added 2026-12-03.)
3. **Harden TOC client:** handle reconnect/backoff, keepalive timeout, parse CONFIG2 buddy list properly, handle TOC1/TOC2 variants, handle chat errors/room not found. 3. **Harden TOC client:** handle reconnect/backoff, keepalive timeout, parse CONFIG2 buddy list properly, handle TOC1/TOC2 variants, handle chat errors/room not found.
4. **Chat UX:** show chat room membership, leave button, invite-send UI, better system messages, error states. 4. **Chat UX:** show chat room membership, leave button, invite-send UI, better system messages, error states.
5. **Security follow-up:** login target host/ports are validated: localhost/private/reserved IPs and hostnames resolving to them are blocked (`isDisallowedHost`), and Web API/TOC ports must be within +/-5 of configured default ports (`isAllowedPort`) to limit port scanning. Login failures always return generic `login failed` after a minimum 15s delay to reduce timing/oracle abuse. Bot check is basic (scriptable); rely on rate limits and consider stronger CAPTCHA if abuse appears. 5. **Security follow-up:** login target host/ports are validated: localhost/private/reserved IPs and hostnames resolving to them are blocked (`isDisallowedHost`), and Web API/TOC ports must be within +/-5 of configured default ports (`isAllowedPort`) to limit port scanning. Login failures always return generic `login failed` after a minimum 7s delay to reduce timing/oracle abuse. Bot check is basic (scriptable); rely on rate limits and consider stronger CAPTCHA if abuse appears.
## Files of interest ## Files of interest

View file

@ -6,9 +6,9 @@
// - Dedupe matters because TOC/Web API paths and SSE replay can surface the same message; // - Dedupe matters because TOC/Web API paths and SSE replay can surface the same message;
// we use msgId when present, otherwise a short recent text/from/mine heuristic. // we use msgId when present, otherwise a short recent text/from/mine heuristic.
// - UI rendering is delegated to js/ui.js; API calls to js/api.js; SSE to js/stream.js. // - UI rendering is delegated to js/ui.js; API calls to js/api.js; SSE to js/stream.js.
import { api } from './js/api.js?v=35'; import { api } from './js/api.js?v=36';
import { createStream } from './js/stream.js?v=35'; import { createStream } from './js/stream.js?v=36';
import * as ui from './js/ui.js?v=35'; import * as ui from './js/ui.js?v=36';
window.addEventListener('error', (e) => { window.addEventListener('error', (e) => {
console.error('[ui] error', e.error || e.message); console.error('[ui] error', e.error || e.message);
@ -341,6 +341,12 @@ async function loadChallenge() {
document.getElementById('loginForm').addEventListener('submit', async (e) => { document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault(); e.preventDefault();
ui.setLoginError(''); ui.setLoginError('');
const submitBtn = e.currentTarget.querySelector('.login-submit');
const originalBtnHtml = submitBtn ? submitBtn.innerHTML : '';
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.innerHTML = '<span class="spinner" aria-hidden="true"></span>Signing in...';
}
const screenName = document.getElementById('screenName').value.trim(); const screenName = document.getElementById('screenName').value.trim();
const password = document.getElementById('password').value; const password = document.getElementById('password').value;
const host = document.getElementById('serverHost').value.trim(); const host = document.getElementById('serverHost').value.trim();
@ -353,6 +359,11 @@ document.getElementById('loginForm').addEventListener('submit', async (e) => {
} catch (err) { } catch (err) {
ui.setLoginError(err.message); ui.setLoginError(err.message);
loadChallenge().catch(() => {}); loadChallenge().catch(() => {});
} finally {
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.innerHTML = originalBtnHtml || 'Sign in';
}
} }
}); });

View file

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web OSCAR Chat</title> <title>Web OSCAR Chat</title>
<link rel="stylesheet" href="/style.css?v=35"> <link rel="stylesheet" href="/style.css?v=36">
</head> </head>
<body> <body>
<div id="app"> <div id="app">
@ -98,6 +98,6 @@
</main> </main>
</div> </div>
<script type="module" src="/app.js?v=35"></script> <script type="module" src="/app.js?v=36"></script>
</body> </body>
</html> </html>

View file

@ -101,6 +101,19 @@ main { padding: 1rem; max-width: 1600px; margin: 0 auto; }
.captcha-label { min-width: 0; } .captcha-label { min-width: 0; }
.captcha-q { color: var(--text); font-weight: 600; margin-left: 0.35rem; font-family: var(--mono); font-size: 0.9rem; } .captcha-q { color: var(--text); font-weight: 600; margin-left: 0.35rem; font-family: var(--mono); font-size: 0.9rem; }
.login-submit { min-width: 120px; height: 2.5rem; } .login-submit { min-width: 120px; height: 2.5rem; }
.login-submit[disabled] { opacity: 0.8; cursor: wait; }
.spinner {
display: inline-block;
width: 0.95em;
height: 0.95em;
border: 2px solid rgba(255,255,255,0.35);
border-top-color: currentColor;
border-radius: 50%;
animation: spin 0.8s linear infinite;
vertical-align: -0.15em;
margin-right: 0.45em;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 560px) { @media (max-width: 560px) {
.login-grid, .login-grid-server, .login-grid-captcha { grid-template-columns: 1fr; } .login-grid, .login-grid-server, .login-grid-captcha { grid-template-columns: 1fr; }
.login-submit { width: 100%; } .login-submit { width: 100%; }

View file

@ -123,7 +123,7 @@ async function tryTocLogin(rec, { screenName, host, tocPort, password, webapiBas
return next; return next;
} }
const LOGIN_FAIL_DELAY_MS = 15_000; const LOGIN_FAIL_DELAY_MS = 7_000;
async function failLogin(res, startedAt) { async function failLogin(res, startedAt) {
const elapsed = Date.now() - startedAt; const elapsed = Date.now() - startedAt;