The Real Fullstack

The Markdown XSS

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

Ingénieur8 minDéfi de codeSimulateur de flux
angularreactmarkdowndompurify

Ce défi n'est pas encore traduit en Français. Vous lisez la version anglaise.

Mission:Choose protections that keep legitimate formatting and links working while making injected HTML and scripts harmless.Contexte · Objectifs d'apprentissage ▾

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.

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

Objectifs d'apprentissage

  • 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.
SimulationSimulé
comment authorcomments APIcomments DBother readers' browsers
Lancer la simulation
// comment preview (current)const html = marked.parse(comment.body).replace(/<script.*?<\/script>/gi, '');   // deny-listelement.innerHTML = html;                                                         // executes event handlers