Harden login, sessions, and media access before the dev deploy.
Deploy Development / deploy (push) Successful in 49s
Test Suite / pytest-backend (push) Successful in 47s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 5m43s
Deploy Development / deploy (push) Successful in 49s
Test Suite / pytest-backend (push) Successful in 47s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 5m43s
Limit brute-force attempts, require admin TOTP, and keep session tokens out of media URLs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6c7c24e887
commit
32b28a93f3
31 files changed
+1146
-101
No files matched your search
@@ -0,0 +1,101 @@
|
||||
import { useState } from 'react'
|
||||
import api from '../utils/api'
|
||||
|
||||
/**
|
||||
* TOTP einrichten: Geheimnis anzeigen, Code bestätigen, Wiederherstellungscodes einmal zeigen.
|
||||
*/
|
||||
export default function TotpSetupCard({ onEnabled }) {
|
||||
const [secret, setSecret] = useState('')
|
||||
const [otpauthUri, setOtpauthUri] = useState('')
|
||||
const [code, setCode] = useState('')
|
||||
const [recoveryCodes, setRecoveryCodes] = useState([])
|
||||
const [error, setError] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
const start = async () => {
|
||||
setError('')
|
||||
setBusy(true)
|
||||
try {
|
||||
const data = await api.setupTotp()
|
||||
setSecret(data.secret || '')
|
||||
setOtpauthUri(data.otpauth_uri || '')
|
||||
setRecoveryCodes([])
|
||||
} catch (err) {
|
||||
setError(err.message || 'Einrichtung fehlgeschlagen')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const confirm = async (e) => {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
setBusy(true)
|
||||
try {
|
||||
const data = await api.confirmTotp(code.trim())
|
||||
if (data?.token) localStorage.setItem('authToken', data.token)
|
||||
setRecoveryCodes(Array.isArray(data?.recovery_codes) ? data.recovery_codes : [])
|
||||
setSecret('')
|
||||
setCode('')
|
||||
if (onEnabled) await onEnabled(data)
|
||||
} catch (err) {
|
||||
setError(err.message || 'Code nicht akzeptiert')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ margin: '0 0 0.75rem', fontSize: '1.1rem' }}>Zwei-Faktor-Anmeldung</h2>
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.875rem', lineHeight: 1.5 }}>
|
||||
Authenticator-App (zum Beispiel Aegis, 1Password oder Microsoft Authenticator) öffnen und das
|
||||
Geheimnis manuell eintragen. Den otpauth-Link nicht an Dritte geben.
|
||||
</p>
|
||||
{error ? (
|
||||
<p style={{ color: 'var(--danger)', fontSize: '0.875rem' }}>{error}</p>
|
||||
) : null}
|
||||
{!secret && recoveryCodes.length === 0 ? (
|
||||
<button type="button" className="btn btn-primary" onClick={start} disabled={busy}>
|
||||
{busy ? 'Wird erzeugt…' : 'Geheimnis erzeugen'}
|
||||
</button>
|
||||
) : null}
|
||||
{secret ? (
|
||||
<form onSubmit={confirm}>
|
||||
<p style={{ fontFamily: 'ui-monospace, monospace', letterSpacing: '0.04em' }}>{secret}</p>
|
||||
{otpauthUri ? (
|
||||
<p style={{ fontSize: '0.75rem', wordBreak: 'break-all', color: 'var(--text3)' }}>{otpauthUri}</p>
|
||||
) : null}
|
||||
<label className="form-label" htmlFor="totp-confirm-code">
|
||||
Code aus der App
|
||||
</label>
|
||||
<input
|
||||
id="totp-confirm-code"
|
||||
className="form-input"
|
||||
inputMode="numeric"
|
||||
autoComplete="one-time-code"
|
||||
value={code}
|
||||
onChange={(e) => setCode(e.target.value)}
|
||||
/>
|
||||
<button type="submit" className="btn btn-primary" disabled={busy} style={{ marginTop: '0.75rem' }}>
|
||||
{busy ? 'Prüft…' : 'Aktivieren'}
|
||||
</button>
|
||||
</form>
|
||||
) : null}
|
||||
{recoveryCodes.length > 0 ? (
|
||||
<div>
|
||||
<p style={{ fontSize: '0.875rem' }}>
|
||||
Diese Wiederherstellungscodes jetzt sichern. Sie werden nur dieses eine Mal angezeigt.
|
||||
</p>
|
||||
<ul>
|
||||
{recoveryCodes.map((item) => (
|
||||
<li key={item} style={{ fontFamily: 'ui-monospace, monospace' }}>
|
||||
{item}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user