joomla/filter
Joomla Filter provides input sanitization and filtering utilities for PHP apps. Use InputFilter to allow/block specific HTML tags and attributes, and OutputFilter for safe output helpers like URL-safe strings. Composer installable, lightweight, framework-ready.
Install the package via Composer: composer require joomla/filter "~3.0" (or ~4.0 for PHP 8.3+). Start with the Joomla\Filter\InputFilter class for sanitizing user input—especially HTML content—before storage or output. The primary use case is preventing XSS attacks by filtering HTML strings, e.g., InputFilter::clean($html, 'html'). For simple scalar values (strings, integers), use InputFilter::clean($value, 'cmd') or 'int'. Check the InputFilter::TAGS_WHITELIST → ONLY_ALLOW_DEFINED_TAGS and ATTR_BLACKLIST → ONLY_BLOCK_DEFINED_ATTRIBUTES constant renamings if upgrading from v1.
InputFilter::clean($input, 'html') with default tag/attribute filtering; customize via blockedTags, blockedAttributes, allowedTags, allowedAttributes arrays in the constructor or via static setters.Joomla\Filter\InputFilter to create domain-specific filters (e.g., PostFilter extends InputFilter) and override filter() or implement preFilter()/postFilter() hooks.$filter = new InputFilter([], [], InputFilter::ONLY_ALLOW_DEFINED_TAGS, InputFilter::ONLY_BLOCK_DEFINED_ATTRIBUTES, true); // $xssAuto = true
InputFilter in a service provider or helper (e.g., filter_html($html)) and register it for injection. For request validation, call InputFilter::clean() in custom validation rules.OutputFilter::stringURLSafe($string) for generating SEO-friendly slugs (requires joomla/language optionally, for multibyte support).javascript:, ', j). Always upgrade to patch releases—critical vulnerabilities were found in earlier versions (CVE-2022-23800).stripImages/stripIframes (v3.0.2+) handle <img style="..."/> and nested tags correctly. Use grep to verify your version if filtering HTML5 media.OutputFilter::stringURLSafe() is used with joomla/language installed.InputFilter class maintains global state; avoid it in long-running processes (e.g., Swoole). Instantiate per-request instead: (new InputFilter($blockedTags, $blockedAttrs, ...)).getClean() to add custom filter types (e.g., 'markdown', 'bbcode') by registering them in your child class’s filter() method.<img src=x onerror=alert(1)>) using PHPUnit—preferably in integration tests to catch regressions after version bumps.How can I help you explore Laravel packages today?