feat(launch-Ф4): анти-бот регистрации — SmartCaptcha + disposable-блок + IP-лимит (фичефлаги)

- antibot.py: disposable-домены (вендор 8k, github disposable-email-domains, обновление curl);
  validate_captcha (только при SMARTCAPTCHA_SERVER_KEY; API лёг → fail-open, режим
  CAPTCHA_FAIL_MODE=closed для активной атаки); per-IP 5 регистраций/час
- /api/register: порядок дешёвое→дорогое (IP → disposable → капча), каждая причина в audit
- /api/captcha-config + условный виджет в register.html; CSP расширяется на
  smartcaptcha.yandexcloud.net ТОЛЬКО при заданном ключе (иначе строгий self)
- 8 red-green тестов; без env-ключей поведение регистрации НЕ меняется (фичефлаг спит)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-07-20 23:49:30 +10:00
co-authored by Claude Opus 4.8
parent 1142770c94
commit 3fafa80191
5 changed files with 8329 additions and 4 deletions
+18 -1
View File
@@ -58,6 +58,7 @@ document.addEventListener('DOMContentLoaded',applyThemeIcon);
<input type="password" id="reg-pass" placeholder="Минимум 6 символов">
<label>Повторите пароль</label>
<input type="password" id="reg-pass2" placeholder="Повторите пароль">
<div id="captcha-container" style="margin:.6rem 0"></div>
<button onclick="doRegister()">Зарегистрироваться</button>
<p style="margin-top:1rem;text-align:center"><a class="link" href="/">Уже есть аккаунт? Войти</a></p>
</div>
@@ -86,6 +87,20 @@ const params = new URLSearchParams(window.location.search);
const inviteToken = params.get('invite') || '';
let regEmail = '';
// SmartCaptcha (Ф4): виджет рендерится ТОЛЬКО если сервер отдал sitekey
// (иначе капча выключена и блок пуст — поведение как раньше).
let captchaWidgetId = null;
fetch('/api/captcha-config').then(r => r.json()).then(cfg => {
if (!cfg.sitekey) return;
const s = document.createElement('script');
s.src = 'https://smartcaptcha.yandexcloud.net/captcha.js?render=onload&onload=onCaptchaReady';
s.defer = true;
window.onCaptchaReady = () => {
captchaWidgetId = window.smartCaptcha.render('captcha-container', {sitekey: cfg.sitekey});
};
document.head.appendChild(s);
}).catch(() => {});
function showStep(n) {
document.querySelectorAll('.step').forEach(s => s.classList.remove('active'));
document.getElementById('step' + n).classList.add('active');
@@ -107,7 +122,9 @@ async function doRegister() {
const r = await fetch('/api/register', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({email, password: pass, invite: inviteToken}),
body: JSON.stringify({email, password: pass, invite: inviteToken,
captcha_token: (captchaWidgetId !== null && window.smartCaptcha)
? window.smartCaptcha.getResponse(captchaWidgetId) : ''}),
});
const data = await r.json();
if (!r.ok) { err.textContent = data.detail || 'Ошибка регистрации'; err.style.display = 'block'; return; }