Files
NightSpire/web-next/lib/forum-sanitize.ts
T
Inna 239392b876 Foro (escritura): crear tema y responder, con saneado HTML
- lib/forum-sanitize.ts: cleanPostHtml con sanitize-html (misma allowlist que
  forum/sanitize.py de nh3: formato básico + a/img/tablas, rel nofollow, esquemas
  http/https/mailto). Verificado XSS-safe (script/onclick/javascript: eliminados).
- lib/forum-write.ts: createTopic (tema + primer post), createPost (respuesta +
  updated_at), forumIsPostable / topicIsReplyable.
- Routes /api/forum/topic y /api/forum/reply (guard de sesión; identidad = cuenta de
  juego: poster=username, poster_id=accountId). Componentes NewTopicForm y ReplyForm
  (clientes). Se muestran solo si hay sesión; el tema cerrado no admite respuesta.

Verificado: escritura 401 sin sesión, saneado correcto. Pendiente: editar/borrar,
moderación (fijar/cerrar/mover), búsqueda, editor enriquecido.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 23:49:53 +00:00

29 lines
927 B
TypeScript

import sanitizeHtml from 'sanitize-html'
// Misma allowlist que forum/sanitize.py (nh3) para el HTML de los mensajes.
export function cleanPostHtml(html: string): string {
if (!html) return ''
return sanitizeHtml(html, {
allowedTags: [
'p', 'br', 'hr', 'span', 'div',
'strong', 'b', 'em', 'i', 'u', 's', 'strike', 'sub', 'sup',
'ul', 'ol', 'li', 'blockquote', 'code', 'pre',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'a', 'img',
'table', 'thead', 'tbody', 'tr', 'th', 'td',
],
allowedAttributes: {
a: ['href', 'title', 'target'],
img: ['src', 'alt', 'title', 'width', 'height'],
span: ['style'],
div: ['style'],
td: ['colspan', 'rowspan'],
th: ['colspan', 'rowspan'],
},
allowedSchemes: ['http', 'https', 'mailto'],
transformTags: {
a: sanitizeHtml.simpleTransform('a', { rel: 'noopener noreferrer nofollow' }),
},
})
}