Close medium exposure on reports, registration, uploads, and exercise HTML.
Deploy Development / deploy (push) Successful in 59s
Test Suite / pytest-backend (push) Failing after 47s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 17s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Failing after 7m48s
Deploy Development / deploy (push) Successful in 59s
Test Suite / pytest-backend (push) Failing after 47s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 17s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Failing after 7m48s
A superadmin can also turn off another account''s two-factor when the authenticator is lost. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
5ea225ec6b
commit
f10c28e5cd
20 files changed
+480
-247
No files matched your search
@@ -156,6 +156,24 @@ export default function AdminUsersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const clearUserTotp = async (row) => {
|
||||
const label = row.name || row.email || `#${row.id}`
|
||||
if (
|
||||
!confirm(
|
||||
`Zwei-Faktor für ${label} aufheben? Danach genügt das Passwort. Authenticator und Wiederherstellungscodes gelten nicht mehr. Offene Sitzungen werden beendet.`
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await api.resetUserTotp(row.id)
|
||||
await loadPlatform()
|
||||
alert('Zwei-Faktor ist aus. Die Person meldet sich mit dem Passwort an und kann ihn neu einrichten.')
|
||||
} catch (e) {
|
||||
alert(e.message || String(e))
|
||||
}
|
||||
}
|
||||
|
||||
const submitPasswordDirect = async () => {
|
||||
if (!pwdModal) return
|
||||
if (pwdNew.length < 8) {
|
||||
@@ -240,6 +258,8 @@ export default function AdminUsersPage() {
|
||||
<div style={{ fontSize: '0.875rem', color: 'var(--text2)' }}>{row.email || '—'}</div>
|
||||
<div style={{ fontSize: '0.78rem', color: 'var(--text3)', marginTop: '0.35rem' }}>
|
||||
Verifiziert: {row.email_verified ? 'ja' : 'nein'}
|
||||
{' · '}
|
||||
Zwei-Faktor: {row.totp_enabled ? 'aktiv' : 'aus'}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.5rem', alignItems: 'flex-end' }}>
|
||||
@@ -279,6 +299,17 @@ export default function AdminUsersPage() {
|
||||
>
|
||||
Passwort / Link
|
||||
</button>
|
||||
{row.totp_enabled ? (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={row.id === user?.id}
|
||||
title={row.id === user?.id ? 'Eigenen Zwei-Faktor unter Einstellungen ändern' : undefined}
|
||||
onClick={() => clearUserTotp(row)}
|
||||
>
|
||||
Zwei-Faktor aufheben
|
||||
</button>
|
||||
) : null}
|
||||
<button type="button" className="btn btn-secondary" onClick={() => savePortal(row.id)}>
|
||||
Portal speichern
|
||||
</button>
|
||||
@@ -573,7 +604,7 @@ export default function AdminUsersPage() {
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem' }}>{pwdModal.label}</p>
|
||||
<p className="muted" style={{ fontSize: '0.82rem', marginBottom: '0.75rem' }}>
|
||||
Standard: Es wird ein sicherer Link per E-Mail verschickt (wie „Passwort vergessen“). Das bisherige Passwort
|
||||
bleibt gültig, bis die Person den Link nutzt und ein neues Passwort wählt.
|
||||
bleibt gültig, bis die Person den Link nutzt und ein neues Passwort wählt. Zwei-Faktor bleibt dabei aktiv.
|
||||
</p>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
|
||||
<button type="button" className="btn btn-primary" onClick={submitPasswordEmail}>
|
||||
|
||||
@@ -1571,7 +1571,7 @@ function ClubsPage() {
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem' }}>{pwdModal.label}</p>
|
||||
<p className="muted" style={{ fontSize: '0.82rem', marginBottom: '0.75rem' }}>
|
||||
Standard: Es wird ein sicherer Link per E-Mail verschickt (wie „Passwort vergessen“). Das bisherige Passwort
|
||||
bleibt gültig, bis die Person den Link nutzt und ein neues Passwort wählt.
|
||||
bleibt gültig, bis die Person den Link nutzt und ein neues Passwort wählt. Zwei-Faktor bleibt dabei aktiv.
|
||||
</p>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
|
||||
<button type="button" className="btn btn-primary" onClick={submitMembersPasswordEmail}>
|
||||
|
||||
@@ -151,6 +151,11 @@ export async function updateProfile(profileId, data) {
|
||||
})
|
||||
}
|
||||
|
||||
/** Superadmin: Zwei-Faktor eines anderen Kontos abschalten. */
|
||||
export async function resetUserTotp(profileId) {
|
||||
return request(`/api/profiles/${profileId}/totp-reset`, { method: 'POST', body: '{}' })
|
||||
}
|
||||
|
||||
/**
|
||||
* Passwort anderer Konten: Standard leerer Body → E-Mail mit Reset-Link (wie Passwort vergessen).
|
||||
* Nur Super-Admins dürfen `newPassword` setzen (direktes Überschreiben des Passwort-Hashes).
|
||||
@@ -1055,6 +1060,7 @@ export const api = {
|
||||
deleteAdminUserContentItem,
|
||||
updateProfile,
|
||||
managementPasswordReset,
|
||||
resetUserTotp,
|
||||
changePassword,
|
||||
verifyEmail,
|
||||
resendVerification,
|
||||
|
||||
@@ -1,111 +1,79 @@
|
||||
/**
|
||||
* Sanitizer für Übungs-Rich-HTML inkl. §11 Platzhalter (span data-shinkan-exercise-media).
|
||||
* Restriktiver als sanitizeTrainerHtml: Allowlist für XSS-Minimierung.
|
||||
* DOMPurify mit fester Allowlist.
|
||||
*/
|
||||
|
||||
import DOMPurify from 'dompurify'
|
||||
import { sanitizeInlineMediaCaption } from './inlineMediaCaption'
|
||||
|
||||
const ALLOWED_BLOCK = new Set(['p', 'div', 'br', 'ul', 'ol', 'li', 'h3'])
|
||||
const ALLOWED_INLINE = new Set(['b', 'strong', 'i', 'em', 'u', 'span', 'a'])
|
||||
const ALLOWED_TAGS = ['p', 'div', 'br', 'ul', 'ol', 'li', 'h3', 'b', 'strong', 'i', 'em', 'u', 'span', 'a']
|
||||
const ALLOWED_ATTR = [
|
||||
'href',
|
||||
'class',
|
||||
'data-shinkan-exercise-media',
|
||||
'data-shinkan-exercise-media-size',
|
||||
'data-shinkan-exercise-media-caption',
|
||||
]
|
||||
const SIZE_OK = new Set(['small', 'medium', 'full'])
|
||||
|
||||
function isHttpsUrl(val) {
|
||||
if (!val || typeof val !== 'string') return false
|
||||
const s = val.trim()
|
||||
return s.startsWith('http://') || s.startsWith('https://')
|
||||
function hookAttribute(_node, data) {
|
||||
const name = data.attrName
|
||||
if (name === 'href') {
|
||||
const href = String(data.attrValue || '').trim()
|
||||
if (!/^https?:\/\//i.test(href)) data.keepAttr = false
|
||||
else data.attrValue = href
|
||||
return
|
||||
}
|
||||
if (name === 'class') {
|
||||
const keep = String(data.attrValue || '')
|
||||
.split(/\s+/)
|
||||
.filter((c) => c === 'shinkan-inline-media')
|
||||
if (!keep.length) data.keepAttr = false
|
||||
else data.attrValue = keep.join(' ')
|
||||
return
|
||||
}
|
||||
if (name === 'data-shinkan-exercise-media') {
|
||||
if (!/^\d+$/.test(String(data.attrValue || '').trim())) data.keepAttr = false
|
||||
return
|
||||
}
|
||||
if (name === 'data-shinkan-exercise-media-size') {
|
||||
const size = String(data.attrValue || '').trim().toLowerCase()
|
||||
if (!SIZE_OK.has(size)) data.keepAttr = false
|
||||
else data.attrValue = size
|
||||
return
|
||||
}
|
||||
if (name === 'data-shinkan-exercise-media-caption') {
|
||||
const caption = sanitizeInlineMediaCaption(String(data.attrValue || ''))
|
||||
if (!caption) data.keepAttr = false
|
||||
else data.attrValue = caption
|
||||
}
|
||||
}
|
||||
|
||||
/** Nur für unsere Embed-Markierung: erlaubt data-attribut und optionale Marker-Klasse + Größe. */
|
||||
const _SIZE_OK = new Set(['small', 'medium', 'full'])
|
||||
function isInlineExerciseMediaPlaceholderSpan(el) {
|
||||
if (!el?.getAttribute || el.tagName.toLowerCase() !== 'span') return false
|
||||
const raw = el.getAttribute('data-shinkan-exercise-media')
|
||||
if (!raw || !String(raw).trim().match(/^\d+$/)) return false
|
||||
return true
|
||||
}
|
||||
const instances = new WeakMap()
|
||||
|
||||
function sanitizeAttributes(el, tagLower) {
|
||||
if (tagLower === 'a') {
|
||||
const href = el.getAttribute('href')
|
||||
if (href && isHttpsUrl(href)) {
|
||||
const out = document.createElement('a')
|
||||
out.setAttribute('href', href.trim())
|
||||
return out.attributes
|
||||
}
|
||||
return []
|
||||
}
|
||||
if (tagLower === 'span' && isInlineExerciseMediaPlaceholderSpan(el)) {
|
||||
const out = document.createElement('span')
|
||||
out.setAttribute('data-shinkan-exercise-media', el.getAttribute('data-shinkan-exercise-media').trim())
|
||||
const sz = (el.getAttribute('data-shinkan-exercise-media-size') || '').trim().toLowerCase()
|
||||
if (sz && _SIZE_OK.has(sz)) {
|
||||
out.setAttribute('data-shinkan-exercise-media-size', sz)
|
||||
}
|
||||
const capRaw = el.getAttribute('data-shinkan-exercise-media-caption')
|
||||
if (capRaw != null && String(capRaw).trim()) {
|
||||
const cap = sanitizeInlineMediaCaption(String(capRaw))
|
||||
if (cap) out.setAttribute('data-shinkan-exercise-media-caption', cap)
|
||||
}
|
||||
const cls = (el.getAttribute('class') || '').trim().split(/\s+/).filter(Boolean)
|
||||
const keep = cls.filter((c) => c === 'shinkan-inline-media')
|
||||
if (keep.length) out.setAttribute('class', keep.join(' '))
|
||||
return out.attributes
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
function cloneAsAllowed(tagLower, el) {
|
||||
const fresh = document.createElement(tagLower)
|
||||
const attrs = sanitizeAttributes(el, tagLower)
|
||||
for (const a of attrs) {
|
||||
fresh.setAttribute(a.name, a.value)
|
||||
}
|
||||
return fresh
|
||||
}
|
||||
|
||||
function cleanTree(parent) {
|
||||
const nodes = Array.from(parent.childNodes)
|
||||
for (const node of nodes) {
|
||||
if (node.nodeType === Node.TEXT_NODE) continue
|
||||
if (node.nodeType === Node.COMMENT_NODE) {
|
||||
parent.removeChild(node)
|
||||
continue
|
||||
}
|
||||
if (node.nodeType !== Node.ELEMENT_NODE) {
|
||||
parent.removeChild(node)
|
||||
continue
|
||||
}
|
||||
const tag = node.tagName.toLowerCase()
|
||||
if (tag === 'script' || tag === 'iframe' || tag === 'object' || tag === 'embed') {
|
||||
parent.removeChild(node)
|
||||
continue
|
||||
}
|
||||
if (ALLOWED_BLOCK.has(tag) || ALLOWED_INLINE.has(tag)) {
|
||||
const repl = cloneAsAllowed(tag, node)
|
||||
while (node.firstChild) {
|
||||
repl.appendChild(node.firstChild)
|
||||
}
|
||||
cleanTree(repl)
|
||||
parent.replaceChild(repl, node)
|
||||
continue
|
||||
}
|
||||
while (node.firstChild) {
|
||||
parent.insertBefore(node.firstChild, node)
|
||||
}
|
||||
parent.removeChild(node)
|
||||
}
|
||||
function purifyFor(win) {
|
||||
const existing = instances.get(win)
|
||||
if (existing) return existing
|
||||
const purify = DOMPurify(win)
|
||||
purify.addHook('uponSanitizeAttribute', hookAttribute)
|
||||
instances.set(win, purify)
|
||||
return purify
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|null|undefined} html
|
||||
* @param {Window=} win
|
||||
* @returns {string}
|
||||
*/
|
||||
export function sanitizeExerciseRichDisplayHtml(html) {
|
||||
export function sanitizeExerciseRichDisplayHtml(html, win) {
|
||||
if (html == null || typeof html !== 'string') return ''
|
||||
const trimmed = html.trim()
|
||||
if (!trimmed) return ''
|
||||
|
||||
const tpl = document.createElement('template')
|
||||
tpl.innerHTML = trimmed
|
||||
cleanTree(tpl.content)
|
||||
return tpl.innerHTML
|
||||
const target = win || (typeof window !== 'undefined' ? window : null)
|
||||
if (!target) return ''
|
||||
return purifyFor(target).sanitize(trimmed, {
|
||||
ALLOWED_TAGS,
|
||||
ALLOWED_ATTR,
|
||||
ALLOW_DATA_ATTR: false,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { JSDOM } from 'jsdom'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { sanitizeExerciseRichDisplayHtml } from './exerciseRichTextSanitize'
|
||||
|
||||
const { window } = new JSDOM('<!doctype html><html><body></body></html>')
|
||||
|
||||
describe('sanitizeExerciseRichDisplayHtml', () => {
|
||||
it('entfernt Skripte und Handler und behält den Medien-Platzhalter', () => {
|
||||
const dirty =
|
||||
'<p onclick="alert(1)">Hallo <script>alert(1)</script></p>' +
|
||||
'<a href="javascript:alert(1)">Link</a>' +
|
||||
'<span class="shinkan-inline-media evil" data-shinkan-exercise-media="7" data-shinkan-exercise-media-size="full"></span>'
|
||||
const clean = sanitizeExerciseRichDisplayHtml(dirty, window)
|
||||
expect(clean.toLowerCase()).not.toContain('script')
|
||||
expect(clean.toLowerCase()).not.toContain('onclick')
|
||||
expect(clean.toLowerCase()).not.toContain('javascript:')
|
||||
expect(clean).toContain('Hallo')
|
||||
expect(clean).toContain('data-shinkan-exercise-media="7"')
|
||||
expect(clean).not.toContain('evil')
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,7 @@
|
||||
/** Einfache HTML-Hilfen für Rich-Text (Trainer-Content, kein öffentliches CMS). */
|
||||
|
||||
import { sanitizeExerciseRichDisplayHtml } from './exerciseRichTextSanitize'
|
||||
|
||||
export function stripHtmlToText(html) {
|
||||
if (!html || typeof html !== 'string') return ''
|
||||
const d = document.createElement('div')
|
||||
@@ -7,17 +9,7 @@ export function stripHtmlToText(html) {
|
||||
return (d.textContent || '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
/** Entfernt script/iframes und Event-Handler-Attribute grob. */
|
||||
/** Entfernt alles außerhalb der Übungs-Allowlist. */
|
||||
export function sanitizeTrainerHtml(html) {
|
||||
if (!html || typeof html !== 'string') return ''
|
||||
const d = document.createElement('div')
|
||||
d.innerHTML = html
|
||||
d.querySelectorAll('script, iframe, object, embed').forEach((n) => n.remove())
|
||||
d.querySelectorAll('*').forEach((el) => {
|
||||
for (const attr of [...el.attributes]) {
|
||||
const n = attr.name.toLowerCase()
|
||||
if (n.startsWith('on') || n === 'srcdoc') el.removeAttribute(attr.name)
|
||||
}
|
||||
})
|
||||
return d.innerHTML
|
||||
return sanitizeExerciseRichDisplayHtml(html)
|
||||
}
|
||||
@@ -1,41 +1,11 @@
|
||||
/**
|
||||
* Reduziert HTML aus Übungs-Kurztexten auf eine kleine erlaubte Menge von Tags (ohne Attribute).
|
||||
* Für Anzeige mit dangerouslySetInnerHTML.
|
||||
* Reduziert HTML aus Übungs-Kurztexten auf die Allowlist von sanitizeExerciseRichDisplayHtml.
|
||||
*/
|
||||
const ALLOWED_TAGS = new Set(['b', 'strong', 'i', 'em', 'br', 'p', 'span', 'ul', 'ol', 'li'])
|
||||
|
||||
function cleanTree(parent) {
|
||||
const nodes = Array.from(parent.childNodes)
|
||||
for (const node of nodes) {
|
||||
if (node.nodeType === Node.TEXT_NODE) continue
|
||||
if (node.nodeType !== Node.ELEMENT_NODE) {
|
||||
parent.removeChild(node)
|
||||
continue
|
||||
}
|
||||
const tag = node.tagName.toLowerCase()
|
||||
if (!ALLOWED_TAGS.has(tag)) {
|
||||
while (node.firstChild) {
|
||||
parent.insertBefore(node.firstChild, node)
|
||||
}
|
||||
parent.removeChild(node)
|
||||
continue
|
||||
}
|
||||
while (node.attributes.length > 0) {
|
||||
node.removeAttribute(node.attributes[0].name)
|
||||
}
|
||||
cleanTree(node)
|
||||
}
|
||||
}
|
||||
import { sanitizeExerciseRichDisplayHtml } from './exerciseRichTextSanitize'
|
||||
|
||||
export function sanitizeExerciseRichText(html) {
|
||||
if (html == null || typeof html !== 'string') return ''
|
||||
const trimmed = html.trim()
|
||||
if (!trimmed) return ''
|
||||
|
||||
const tpl = document.createElement('template')
|
||||
tpl.innerHTML = trimmed
|
||||
cleanTree(tpl.content)
|
||||
return tpl.innerHTML
|
||||
return sanitizeExerciseRichDisplayHtml(html)
|
||||
}
|
||||
|
||||
export function coerceApiNameList(value) {
|
||||
|
||||
Reference in new issue
Block a user