← PHP / Laravel · Contents

PHP-071 / Advanced

Stored XSS in Markdown or HTML input (missing sanitization)

A03:2021 Injection · CWE-79 Cross-site Scripting

Why is this a problem?

If a Markdown converter passes raw HTML through, an element such as <img onerror=...> can be stored and executed.

How to fix it

php
return Str::markdown($post->body, ['html_input' => 'escape', 'allow_unsafe_links' => false]);
// Alternatively allowlist tags using HTMLPurifier or similar

Further reading