Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Html Sanitizer Laravel Package

typo3/html-sanitizer

Standalone PHP HTML sanitizer from TYPO3. Define sanitization rules via Behavior, apply with Visitors, and get a ready-to-use Sanitizer via Builders/presets. Control allowed tags, attributes, and values; encode or remove invalid nodes and comments.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • XSS Protection for User-Generated Content (UGC): Enables secure rendering of HTML from untrusted sources (e.g., comments, forum posts, CMS content) by whitelisting only safe tags/attributes. Critical for platforms handling dynamic content (e.g., social media, Q&A, wikis).

  • Compliance with Security Standards: Aligns with OWASP guidelines for input validation/sanitization, reducing legal/regulatory risks (e.g., GDPR, PCI-DSS). Justifies investment in security-focused infrastructure.

  • Customizable Sanitization Policies: Supports build vs. buy by allowing granular control over allowed HTML (e.g., strict vs. permissive rules for different content types). Avoids reinventing wheel for complex use cases (e.g., rich-text editors with custom tags like <typo3>).

  • Roadmap for Scalable Content Moderation: Integrates with moderation workflows by enabling safe preview/editing of user-submitted HTML before publication. Example: Sanitize previews in a CMS while preserving formatting for admins.

  • Multi-Tenant or Role-Based HTML Rules: Use Builder presets to create tenant-specific or role-based sanitization rules (e.g., "Editors can use <strong>; Guests cannot").


When to Consider This Package

  • Avoid if:

    • Your app doesn’t process HTML input (e.g., pure API backend with no frontend rendering).
    • You need real-time sanitization (e.g., chat apps) and prefer a lower-latency solution like DOMPurify (JavaScript).
    • Your stack is non-PHP (e.g., Node.js, Python). Use native alternatives like bleach (Python) or sanitize-html (Node.js).
    • You require schema-aware sanitization (e.g., MathML, SVG with complex security rules). Consider specialized libraries like SVG Sanitizer.
  • Consider if:

    • You handle user-generated HTML (e.g., CMS, forums, wikis) and need XSS protection.
    • Your team lacks security expertise to manually audit sanitization logic.
    • You need fine-grained control over allowed tags/attributes (e.g., disallowing <script> but allowing <iframe> with src restrictions).
    • Your app uses PHP and requires a server-side solution (not client-side JS).

How to Pitch It (Stakeholders)

For Executives:

"This package is a turnkey XSS protection layer for user-generated HTML, reducing our attack surface without sacrificing functionality. It’s like a ‘whitelist firewall’ for HTML—only safe tags/attributes pass through. For example:

  • Prevents malicious scripts in forum posts while preserving bold/italic formatting.
  • Complies with security standards, reducing audit findings and potential breaches.
  • Saves dev time by avoiding custom sanitization code (which often has bugs). Used by TYPO3 CMS, it’s battle-tested and MIT-licensed. The cost? Minimal—just a Composer install and config. The risk? Zero if we use it correctly."

For Engineers:

"This is a declarative HTML sanitizer with three key advantages:

  1. Flexibility: Define allowed tags/attributes via code (e.g., ->withTags(new Behavior\Tag('a')->addAttrs(new Behavior\Attr('href')))). Need custom rules? Extend it with Visitor classes.
  2. Security: Actively maintained (last release: 2026), with fixes for XSS in CDATA, comments, and raw text. Flags like ENCODE_INVALID_TAG ensure even malformed HTML is safe.
  3. Performance: Lightweight (~100KB) and optimized for PHP (supports 8.2+). Benchmark it against alternatives like HTMLPurifier—it’s faster for simple use cases. Tradeoff: Slight learning curve for custom builders, but docs/examples cover 90% of needs. Start with CommonBuilder for quick wins."*

For Security Teams:

"This mitigates XSS risks by:

  • Whitelisting only safe HTML (no blacklisting, which is error-prone).
  • Encoding invalid content (e.g., <script> becomes &lt;script&gt;) instead of silently dropping it.
  • Blocking high-risk features by default (e.g., javascript: URLs, custom elements). Integration tip: Use it in two layers:
  1. User-facing: Sanitize all UGC before rendering.
  2. Admin-facing: Loosen rules for trusted editors (e.g., allow <iframe> with src validation). Prove its effectiveness by testing with XSS Payloads and the demo server."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi