The Real Fullstack

The Markdown XSS

We remove <script> tags. How did a comment still steal session cookies?

Engenheiro8 minDesafio de códigoSimulador de fluxo
angularreactmarkdowndompurify

Este desafio ainda não foi traduzido para Português (Brasil). Você está lendo a versão em inglês.

Missão:Choose protections that keep legitimate formatting and links working while making injected HTML and scripts harmless.Contexto · Objetivos de aprendizagem ▾

Fernpost lets users write comments in Markdown. The frontend converts it to HTML, strips <script> tags with a regular expression and assigns the result to innerHTML. Security found comments with onerror handlers, javascript: links and a fake login form.

Missão: Choose protections that keep legitimate formatting and links working while making injected HTML and scripts harmless.

Objetivos de aprendizagem

  • Understand stored cross-site scripting (XSS).
  • Sanitize with an allow-list instead of deny-listing tags.
  • Restrict link schemes and add a Content Security Policy as defence in depth.
SimulaçãoSimulado
comment authorcomments APIcomments DBother readers' browsers
Executar simulação
// comment preview (current)const html = marked.parse(comment.body).replace(/<script.*?<\/script>/gi, '');   // deny-listelement.innerHTML = html;                                                         // executes event handlers

Simplificação

Seven comments with fixed properties. Real sanitizers handle many more vectors (mutation XSS, CSS, SVG). Modelo educacional — os números ilustram comportamento, não são benchmarks.

Conceitos

Desafios relacionados

Referências