twig/markdown-extra
Twig extension adding Markdown support to templates. Provides markdown_to_html and html_to_markdown filters to convert Markdown blocks to HTML and turn HTML back into Markdown, making it easy to render or edit rich content in Twig views.
markdown_to_html). This aligns with Laravel’s security-first philosophy and reduces risk for user-generated content workflows (e.g., wikis, CMS, or comment systems).
// Custom filter (must handle escaping manually if needed)
$twig->addFilter('unsafe_markdown', function($content) {
$markdown = new \Michelf\MarkdownExtra();
return $markdown->transform($content); // No auto-escaping
});
markdown_to_html with user-generated content to ensure escaping works as expected.twig/markdown-extra to v3.26.0 to patch CVE-2026-46637.symfony/markdown is also updated (v6.4+ recommended).<script>alert(1)</script> in Markdown) should render as text.{{ $var|e }} escaping filter.config/twig.php.| Risk Area | Updated Assessment | Mitigation Strategy |
|---|---|---|
| Security | High Priority: CVE-2026-46637 affects all apps using markdown_to_html with untrusted input. |
Immediate: Update to v3.26.0. Test user-generated content workflows. |
| Breaking Changes | Low: Non-breaking, but custom filters may need updates if they rely on unescaped output. | Audit custom Twig filters for manual escaping logic. Use `{{ $var |
| Performance | Low: Pre-escaping adds negligible overhead. | Monitor in high-traffic templates; cache as before. |
| Twig Version Lock | Low: Twig 3.x (Laravel 10+) is unaffected. | No action required. |
| Customization Limits | Medium: Custom filters must now handle escaping manually. | Provide a whitelist mechanism for trusted content (e.g., admin-only Markdown). |
| PHP Version Requirements | Medium: PHP 8.1+ required (no change). | Upgrade if using PHP 8.0; test compatibility if stuck on 8.0. |
<code> blocks) be handled? Options:
html <div>...</div> ).safe_markdown filter for trusted content.symfony/markdown v6.x, which may affect long-term compatibility.twig/markdown-extra (now v3.26.0).symfony/markdown (v6.4+ recommended).composer require twig/markdown-extra:^3.26.0 symfony/markdown:^6.4.0
// app/Providers/AppServiceProvider.php
use Twig\Extra\Markdown\MarkdownExtension;
public function boot()
{
$this->app->make('twig')->addExtension(new MarkdownExtension());
}
<script>alert(1)</script>) render as text:
{{ "<script>alert(1)</script>"|markdown_to_html }} <!-- Should output: <script>alert(1)</script> -->
$twig->addFilter('admin_markdown', function($content) {
$markdown = new \Michelf\MarkdownExtra();
return $markdown->transform($content); // No auto-escaping
});
Str::of(html)->allowedTags() for granular control:
{{ $userMarkdown|markdown_to_html|e('html')|Str::of()->allowedTags('<p><a><strong>') }}
How can I help you explore Laravel packages today?