twig/markdown-extra
Twig extension adding Markdown support: convert Markdown to HTML with the markdown_to_html filter, and convert HTML back to Markdown with html_to_markdown. Ideal for rendering user content and round-tripping between formats in Twig templates.
Secure Content Moderation Systems:
Build vs. Buy Tradeoffs:
parsedown/parsedown, michelf/php-markdown) with a maintained, Symfony-backed solution. Avoids technical debt from forks or abandoned packages.markdown_to_html to support MathJax via a wrapper filter.Use Cases by Laravel Domain:
markdown_to_html in Blade.GET /posts/{id}/rendered) with XSS-proof HTML.Developer Productivity Gains:
{{ $comment|e }}) for Markdown content. Example: A support ticket system can render user comments directly without sanitization steps.Adopt when:
Look elsewhere if:
markdown-extra’s scope. Consider:
markdown-extra) to your vendor directory, though the impact is negligible for most Laravel apps.*"This update closes a critical security gap in how our platform handles user-generated Markdown—directly impacting customer trust, compliance, and operational risk. Here’s why it’s a top priority:
- Risk Elimination: Blocks XSS attacks in high-impact areas (e.g., public forums, API documentation, support tickets), reducing liability and support costs.
- Compliance Alignment: Meets OWASP Top 10, PCI DSS, and GDPR requirements for untrusted input handling, critical for industries like finance, healthcare, or SaaS.
- Cost Savings: Avoids custom security patches or third-party tools (e.g., HTML Purifier), saving $X/year in engineering overhead.
- Competitive Differentiation: Enables secure Markdown workflows (e.g., Git-based docs, collaborative editing) without sacrificing safety—a gap many competitors overlook.
Ask: Should we prioritize this update for [specific high-risk areas, e.g., our public forum or API docs] in the next sprint? The fix is non-breaking, requires minimal effort, and has high ROI in security and scalability.
Business Impact:
- Forums/Support: Reduces moderation overhead and security incidents from malicious scripts in user posts.
- APIs/Docs: Safeguards technical documentation, critical for enterprise adoption and developer trust.
- Multi-Tenant SaaS: Prevents cross-tenant XSS attacks, protecting SLA compliance and customer data."*
*"This release patches CVE-2026-46637 in
twig/markdown-extra, addressing an XSS vulnerability in Markdown-to-HTML rendering. Here’s how it impacts our Laravel stack:
- Critical Fix: The package now auto-escapes untrusted input by default, preventing XSS in user-generated Markdown (e.g., forum posts, comments). This is enabled for all
markdown_to_htmlcalls without configuration changes.- Non-Breaking: Existing Twig filters (
markdown_to_html,html_to_markdown) work as before but are now safer. No API changes required.- Performance: Negligible overhead. Escaping happens during parsing, not at runtime.
- Caching: Safe for cached outputs (e.g., blog posts), as the package handles escaping internally.
Action Items:
- Update immediately to
twig/markdown-extra:^3.26.0in all environments.- Audit high-risk areas:
- User-generated Markdown (forums, wikis, comments).
- Bidirectional pipelines (HTML ↔ Markdown migrations).
- Test edge cases:
- Verify custom Twig filters or extensions using raw Markdown input.
- Check if legacy content (e.g., migrated HTML) renders correctly.
- Document the change: Note that input is now pre-escaped, so manual escaping in templates is redundant and may break formatting.
Key Considerations:
- Custom Filters: If you’ve created filters that bypass escaping (e.g., for trusted content
How can I help you explore Laravel packages today?